lingo學習篇

一、整數規劃-gin都變成整數,要放在end後

clipboard.png

max 5x1+8x2
st
x1+x2<6
5x1+9x2<45
end
gin 2!變量變整數

使都變成0-1變量,int
@bin,0-1變量限制函數

二、非線性規劃

clipboard.png

clipboard.png
@bnd(取值範圍)spa

三、複雜問題求解

clipboard.png

Model:
Sets:       !定義集合;
CK/1..10/:d,y;   !10個倉庫,y和d都是10維的變量,其中y是01變量,d由下面數據給定;

KH/1..20/;        !20個客戶;
SS(CK,KH):x,c;   !x和c都是10*20的變量,x表示供應百分數,c表示所有供應的費用;
EndSets
Min=@Sum(SS(i,j):c(i,j)*x(i,j))+@Sum(CK(i):d(i)*y(i));
@For(CK(i):@Sum(KH(j):x(i,j))<20*y(i));  !若不建某倉庫,是沒有物資的;
@For(KH(j):@Sum(CK(i):x(i,j))=1);  !每一個客戶須要供應的百分數之和都爲1;
@For(CK(i):@Bin(y(i)));    !y是0、1變量限制;
Data:   !數據部分;
d=2    3    4    2    3    4    2    3    4    5
;
c=
9    14    6    15    6    19    11    19    4    5    3    6    4    10    12    19    8    7    10    4
10    16    9    12    8    14    4    20    9    13    2    17    18    19    15    18    16    9    8    8
2    10    2    18    4    19    8    13    15    9    4    8    16    2    15    11    8    8    3    14
6    4    1    9    3    3    5    15    6    10    9    13    6    4    8    5    2    9    13    8
7    10    20    17    7    9    13    16    9    15    13    10    12    12    4    16    6    16    6    17
15    18    14    18    11    4    20    20    13    1    10    19    6    4    12    20    20    1    20    7
15    14    20    12    6    15    20    3    1    16    6    6    6    20    3    17    6    11    17    12
1    1    5    2    2    5    16    8    7    7    12    9    5    12    6    4    17    11    11    20
18    16    20    18    5    20    8    6    17    20    9    19    1    10    9    5    8    9    17    15
6    7    17    4    12    4    19    4    13    16    7    6    1    14    11    5    7    9    11    13
;
EndData
End

注意:集合定義
如定義di,yicode

sets:
CK/1..3/:d,y;

end sets
data:       
d=1 3 4;
y=5 7 8;
end data

定義di,yi,ci,xi

sets:
a/1..3/:d,y;
b/1..2/;
SS(a,b):c,x;
end sets

data: 
d=1 3 4;
y=3 5 7;
c=1 3 4 5 7 8;
x=1 3 3 4 7 8;
end data

構造關係式:求和(cij 乘以xij)+求和(di乘以yi)ip

clipboard.png

max=z;
z=@sum(SS(i,j):c(i,j)*x(i,j))+@sum(a(i):d(i)*y(i));

clipboard.png

@For(a(i):@Sum(b(j):x(i,j))<20*y(i));
@For(b(j):@Sum(a(i):x(i,j))=1);

本身建的模型求解

clipboard.png

lingoci

model:
p1=17;
p2=2.67;
k1=0.3;
k2=8;
p3=1700;
N1=550/(1+1.2*@exp(-0.8*x1));
N2=25/(1+1.1*@exp(-0.4*x2));
Max=Z;
Z=k1*p1*N1+k1*p3*N2+(k2-x1-x2)*N1*p2;
0<=x1+x2;x1+x1<=8;
N1>=N2;
0<=x1;x1<=20;
0<=x2;x2<=10;
@gin(x1); @gin(x2);
end

matlab版解非線性規劃
構建函數:it

function f= con_fun1(x)
p1=17; 
p2=2.67;  
k1=0.3;
k2=8;
p3=1700;
N1=550/(1+1.2*exp(-0.8*x(1)));
N2=25/(1+1.1*exp(-0.4*x(2)));
f=-1*(k1*p1*N1+k1*p3*N2+(k2-x(1)-x(2))*N1*p2);
end
OPTIONS=optimset('display','iter','LargeScale','off');
lb=[0 0];
hb=[20 10];
A=[1 1;-1 -1];
k2=30;
b=[k2;0];
[x,fval,exitflag,output]=fmincon(@con_fun1,[1,1],A,b,[],[],lb,hb,[],OPTIONS);
相關文章
相關標籤/搜索