它已經有一段時間,因爲我已經做到了這一點,所以我有點生疏,但公式是:的Python linprog最大化目標函數
max t(C)*x
s.t. Ax <=b
我有我的一個矩陣約束條件是( 1448x1359):
[[ 1. 1. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 1. 1. 1.]]
然後,我有我的結合b(1448x1):
[ 1. 1. 7. ..., 2. 1. 2.]
而我的目標函數被最大化,這是一個向量(1359,1)。
現在,在其他包我的最大目標函數是841,但是使用linprog:
res = linprog(c=OBJ_N, A_ub=A, b_ub=b, options={"disp": True})
它成功地優化-0.0所以我不知道如果我使用Python中正確的命令,並有我的約束正確的方式?
編輯:確定這是有道理的,它試圖最小化。我現在已經改寫(交換c和b,並將A轉爲最小)。
# (max t(C)*x s.t. Ax <=b) = min t(b)*x s.t. ATy = c, y ≥ 0
# (i): minimise number of shops no bounds
ID = np.ones(len(w[0]))
print(ID)
print(ID.shape) #1359
At = A.transpose()
need_divest = (A.dot(ID)) - 1
print(need_divest)
print(need_divest.shape) #1448
res = linprog(c=need_divest, A_eq=At, b_eq=ID, options={"disp": True})
print(res)
不過,我得到「消息:‘Optimzation失敗無法找到一個可行的起點。’」
linprog:'最小化的線性目標函數受線性等式和不等式constraints.' - 這是否幫助? – cel
你走錯了路......在這裏你試圖解決你最初的「最小化」問題的「雙重」問題。 您可以考慮下面的答案,正確說明您的原始問題。 – Mathiou