根据描述,我们用线性规划带约束来求解问题
# coding=utf-8 from scipy.optimize import linprog import numpy as np def maxGain(args): xg,yg,naifenx,naifeny,kaofeix,kaofeiy,sukx,suky,naifenmax,kaofeimax,sukmax = args # c = np.array([0.7, 1.2]) # A = np.array([[9, 4], [4, 5], [3, 10]]) # b = np.array([3600, 2000, 3000]) c = np.array([xg, yg]) A = np.array([[naifenx, naifeny], [kaofeix, kaofeiy], [sukx, suky]]) b = np.array([naifenmax, kaofeimax, sukmax]) x0_bounds = (0, None) x1_bounds = (0, None) res = linprog(-c, A_ub=A,b_ub=b,\ bounds=(x0_bounds,x1_bounds),\ options={"disp": True} ) return res if __name__ == "__main__": args = (0.7,1.2,9,4,4,5,3,10,3600,2000,3000) #11个参数,,,,,,,,, res = maxGain(args) print(res.x) #print(res) print(-res.fun)可看注释掉的代码,根据图片显示的位置,进行阅读。
转载于:https://www.cnblogs.com/shizhenqiang/p/8184460.html
相关资源:python单纯形法解线性规划问题