2
我想複製我在Matlab中的研究論文中找到的線性優化。我需要解決以下線性優化問題:MatLab中求和的線性規劃
其中C1,C2,C3,C4,C5,W1和W2是優先權重。
j取自1至12(一年的12個月)。
以下限制適用:
I(j)的和L(j)是按月記錄。
我使用MatLab來編寫解決方案。這裏是我的代碼(我很新的這一點,所以請原諒任何不好的編碼!):
%set up the data for the year:
I = [72.6 26.0 23.2 20.4 15.2 22.0 40.9 45.2 38.7 41.4 142.2 116.8]
L = [1.6 1.3 0.8 0.6 0.6 0.6 1 1.5 1.8 1.8 1.8 2.0];
%set up the initial level:
S0 = 683
%set up the priority weightings
w2= 1;
w1 = 1.5;
C1 = 3;
C2 = 2;
C3 = 5;
C4 = 4;
C5 = -5;
%set up the constraint equation, lower bond and upper bound
A = [(C1*w1) C2 (C3*w2) (C4*w2) C5];
Aeq = [1 1 1 1 1];
lb = [70 0 0 0 0];
ub = [815 54.14 13.4 41.8 17345];
%set up a blank matrix to store the results
x=zeros(12,5);
%for each month calculate the optimum and store in the matrix
for j = 1:12
Beq = [(I(j)+S0-L(j))];
x(j,:) = linprog(-A,[],[],Aeq,Beq,lb,ub);
S0 = x(j,1);
end
%output the result
opt = x
問題是,當我比較我的結果的研究論文中,我發現,我得到不同的結果。最終我意識到我正在爲每個月找到最佳狀態,而不是全年的全球最佳狀態。我一直在網上搜索如何找到全年的最佳值(即優化求和函數),但我找不到任何東西。任何人都可以將我指向正確的方向嗎?
有一個在Matlab的linprog沒有總和。它完全基於矩陣。對於某些問題,這是沒有問題的,對於其他問題,這是噩夢(參見[這裏](http://yetanothermathprogrammingconsultant.blogspot.com/2016/10/matlab-vs-gams-integer-programming.html))。在你的情況下,你需要建立一個大矩陣,每一列對應一個變量,每一行對應一個約束。 –
@ErwinKalvelagen非常感謝您的回覆。我用你的例子來解決我的問題。 –