2017-04-17 6 views
2

私はMatlabの研究論文で発見した線形最適化を再現しようとしています。 W1W2優先重みであり、MatLabの集計を使用した線形プログラミング

objective function

C1C2C3C4C5:私は、次の線形最適化問題を解決するために必要。

jは、1から12(12ヶ月)です。

次の制約が適用されます。

constraint functions

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 

問題があります。最終的には、今年のグローバルな最適化ではなく、毎月の最適化を見つけることに気付きました。私は1年を通して最適化を見つける方法(つまり、総和関数を最適化する方法)をオンラインで検索していましたが、何も見つかりませんでした。誰かが私を正しい方向に向けることができますか?

+0

Matlabのlinprogの合計はありません。それは完全に行列ベースです。いくつかの問題についてはこれは問題ではありません。他の人にとっては悪夢です([here](http://yetanothermathprogrammingconsultant.blogspot.com/2016/10/matlab-vs-gams-integer-programming.html参照))。あなたの場合、各列が変数に対応し、各行が制約に対応する1つの大きな行列を構築する必要があります。 –

+0

@ErwinKalvelagenご返信ありがとうございます。私はあなたの問題を解決するために例を使用しました。 –

答えて

0

@ErwinKalvelagenのおかげで、私は自分の問題を解決することができました。将来的に他人のための私のソリューションです:

%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;]; 
I = I*1; %allows the inflow to be scaled to test the model for a dry or wet year 
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 priority weightings 
w1 = 2; 
w2= 50; 
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 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5 (C1*w1) C2 (C3*w2) (C4*w2) C5]; 

%set up spare matrix for Aeq 
Aeq = zeros(12,60); 

% Populate Aeq 
% first the positive portions of the monthly data 
row = 1; 
coloumn = 1; 
for counter = 1:12 
    for counter = 1:5 
     Aeq(coloumn,row)=1; 
     row = row + 1; 
    end 
    coloumn = coloumn+1; 
end 
% then the -S0 for each month 
Aeq(1, 56)=-1; 
coloumn = 1; 
for row = 2:12 
    Aeq(row,coloumn)=-1; 
    coloumn = coloumn+5; 
end 

%populate Beq 
Beq = I-L; 

%populate the lower and upper bounds 
Smin = 70; 
Smax_1_9 = 731.2; 
Smax_10_12 = 673.2 
QDmin = 0 
QDmax = 54.14 
Rmin = 0; 
Rmax = 13.4; 
RRmin = 0; 
RRmax = 41.8; 
SPILLmin = 0; 
SPILLmax = 17345; 
%first the lower bound 
lbmonthly = [Smin; QDmin; Rmin; RRmin; SPILLmin;]; 
lb = vertcat(lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly,lbmonthly); 
%second the upper bound 
ubmonthly_1_9 = [Smax_1_9; QDmax; Rmax; RRmax; SPILLmax;]; 
ubmonthly_10_12 = [Smax_10_12; QDmax; Rmax; RRmax; SPILLmax;]; 
ub = vertcat(ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_1_9, ubmonthly_10_12, ubmonthly_10_12, ubmonthly_10_12); 

%find the optimal 
opt = linprog(-A,[],[],Aeq,Beq,lb,ub); 

%output the result as a matrix 
opt = reshape(opt,5,12)' 
関連する問題