I am trying to run simulated annealing to solve the following problem:
Minimize: Z = 5x + 4y
4x + y ≥ 40,
2x + 3y ≥ 90,
x, y ≥ 0
However I faced two problems:
- adding constriants
- setting the bounds
Scipy's dual_annealing() doesn't support any constraints as parameters (unlike functions such as minimize()). While setting the bounds to [0, inf). I get some errors. My code and the errors are shown below.
def obj(v):
x, y = v
return 5*x + 4*y
# define range for input
r_min, r_max = 0, np.inf
result = dual_annealing(objective, bounds)
If I use bounds as bounds = [[r_min, r_max], [r_min, r_max]] I get this error:
640 np.isnan(lower)) or np.any(np.isnan(upper))):
--> 641 raise ValueError('Some bounds values are inf values or nan values')
642 # Checking that bounds are consistent
643 if not np.all(lower < upper):
ValueError: Some bounds values are inf values or nan values
And if I use bounds = Bounds(lb=r_min), I get this error:
--> 639 if (np.any(np.isinf(lower)) or np.any(np.isinf(upper)) or np.any(
640 np.isnan(lower)) or np.any(np.isnan(upper))):
641 raise ValueError('Some bounds values are inf values or nan values')
642 # Checking that bounds are consistent
TypeError: ufunc 'isinf' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
2
Most of the examples online use fixed bounds and unconstrained problems. How can I add infinity bounds and constraints?