python - python root finding in integers
问题描述
Is there tools for optimization in python, where I can choose target value for function and get best parameters, that will be integers?
Example, my function is:
f(x) = 4*A + B
So If choose 5 as a target value it will return me A=1 and B=1
解决方案
Maybe a constraint solver:
# https://pypi.org/project/python-constraint/
from constraint import *
problem = Problem()
problem.addVariables(["a","b"],range(1,100000))
problem.addConstraint(ExactSumConstraint(5,[4,1]))
problem.getSolutions()
This gives:
[{'a': 1, 'b': 1}]
推荐阅读
- javascript - FCC 锻炼追踪器添加锻炼
- sql - 获取多个日期范围之间的值总和
- wordpress - Wordpress 下拉菜单(引导程序)
- php - 如何使用 PHP 打印这个数字序列?
- python - 如何保存连体模型的基础网络?
- php - 将产品简短描述添加到 WooCommerce 电子邮件通知
- python - Heroku 计划的 Python 脚本每隔几天就会崩溃一次
- react-native - React 检测到 StackNavigator 调用的 Hook 顺序发生了变化
- python - 如何创建 0 维 tf.Variable?
- php - 如何在 SQL 中自动填充多对多表