将这段代码改为求min{max{qixi}}这种目标函数 from scipy.optimize import linprog import matplotlib.pyplot as plt k = 0 c_values = [] Q_values = [] while k < 0.1: c = [-0.05, -0.27, -0.19, -0.185, -0.185] Aeq = [[1, 1.01, 1.02, 1.045, 1.065]] beq = [1] A = [[0.05, 0.27, 0.19, 0.185, 0.185]] b = [k] vlb = [0, 0, 0, 0, 0] vub = [] res = linprog(c=c, A_ub=A, b_ub=b, A_eq=Aeq, b_eq=beq, bounds=list(zip(vlb, vub))) x = res.x k += 0.001 print(k) print(x) Q = -res.fun c_values.append(a) Q_values.append(Q) plt.plot(c_values, Q_values, '.') plt.xlabel('a') plt.ylabel('Q') plt.axis([0,0.5, 0, 0.5]) plt.show()
时间: 2024-04-14 15:27:58 浏览: 198
以下是修改后的代码,用于求解目标函数min{max{qixi}}:
```python
from scipy.optimize import linprog
import matplotlib.pyplot as plt
a = 0
c_values = []
Q_values = []
while a < 0.1:
c = [0, 0, 0, 0, -1]
Aeq = [[1, 1.01, 1.02, 1.045, 1.065]]
beq = [1]
A = [[-1, 0, 0, 0, 0], [0, -1, 0, 0, 0], [0, 0, -1, 0, 0], [0, 0, 0, -1, 0], [0, 0, 0, 0, -1]]
b = [-a, -a, -a, -a, 0]
vlb = [0, 0, 0, 0, 0]
vub = []
res = linprog(c=c, A_ub=A, b_ub=b, A_eq=Aeq, b_eq=beq, bounds=list(zip(vlb, vub)))
x = res.x[:5]
a += 0.001
print(a)
print(x)
Q = max([q * x[i] for i, q in enumerate(c)])
c_values.append(a)
Q_values.append(Q)
plt.plot(c_values, Q_values, '.')
plt.xlabel('a')
plt.ylabel('Q')
plt.axis([0, 0.1, 0, 0.5])
plt.show()
```
请尝试运行修改后的代码,看看是否满足您的需求。它将计算目标函数min{max{qixi}}的最小值,并将结果绘制在图表上。x轴表示变量a的取值,y轴表示目标函数的值Q。图表的x轴范围是从0到0.1,y轴范围是从0到0.5。
阅读全文