5.5py

2839663913發表於2024-10-15

from scipy.optimize import linprog

c = [2, 3, 3, 2]
A = [
[-1, -1, 0, 0],
[0, 0, -1, -1],
[1, 2, 1, 0],
[0, 1, 0, 2],
[10, 9, 8, 7]
]
b = [
[-20],
[-25],
[80],
[35],
[1000]
]

LB = [0] * len(c)
UB = [None] * len(c)
bound = tuple(zip(LB, UB))

res = linprog(c, A_ub=A, b_ub=b, bounds=bound, method='highs')

if res.success:
print("目標函式的最小解:", res.fun)
print("最優解為:", res.x)
else:
print("最佳化問題沒有成功解決。")
#2023310143007