0

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

  • 1
    Can you just clarify the following: How to you come to the conclusion that A = 1 and B = 5, or is this just an example? Are both A and B functions of x? And by 'target', do you mean where f(x) converges to the target value? – ChaddRobertson Nov 08 '20 at 04:39
  • 1
    What are "best" parameters? This is an underdetermined system of equations, so infinitely many solutions exist. – a_guest Nov 08 '20 at 10:48
  • @ChaddRobertson That was a misprint, A and B should be ones. They are integer variables, not functions and target means that f(x) converges to the target value. – Пажилая Скумбрия Nov 08 '20 at 10:49
  • @a_guest best parameters means any set of parameters for which the function converges to the target value – Пажилая Скумбрия Nov 08 '20 at 10:51

1 Answers1

0

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}]
Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39