from scipy.optimize import linprog # set up cost list with cost function coefficient values c = [-2,-3] # set up constraint coefficient matrix A A_ub = [[1,1],[2,1]] # constraint list for upper bounds (less than or equal constraints) b_ub =[10,15] # in addition, i need to prepare a bounds tuple for each # optimization variable and summarize them a list x1_bounds = (0,None) x2_bounds = (0,None) # now I use SciPy.optimize.linprog to model and solve the problem at hand model_linear = linprog(c=c,A_ub=A_ub,b_ub=b_ub,bounds=[x1_bounds,x2_bounds]) # output model solution print(str(model_linear)) #Results: # message: Optimization terminated successfully. (HiGHS Status 7: Optimal) # success: True # status: 0 # fun: -30.0 # x: [ 0.000e+00 1.000e+01]
Last Updated on 2023-06-28 by gantovnik
Recent Comments