3

I have a linear function for two input value according the following (params has been computed already):

def objective(x):
    return x[0] * params[0] + x[1] * params[1] + params[2]

Now I want to calculate the optimum (minimum) of the function with scipy.optimize.minimize with restrictions on the input value ranges: the sum of the inputs are not allowed to be greater than 1000. I can restrict the respective two input to ranges:

bounds = ((0.0, 1000.0), (0, 1000.0))
scipy.optimize.minimize(objective, (0, 0), method="TNC", bounds=bounds)

and it gives 1000, 1000 as candidates for the input values for the optimum, as expected. However, as I stated, I need the input value pair for optimum in the range where the sum of the values is restricted, not only the separate input values independently. How should I modify my code in order to do that?

Fredrik
  • 411
  • 1
  • 3
  • 14
  • just a guess - and certainly not a good solution - but perhaps you could add a term to the output of the function that increases dramatically as the input moves away from the condition of the sum of the values. By making it smooth it should still play nice with methods that rely on estimating the gradient. assert that the final solution meets the sum criteria. – fishstix44 Feb 07 '21 at 12:45

0 Answers0