求一个lingo编程中的问题!悬赏20大洋!成功后加10大洋!关于lingo约束条件的编写....
本帖最后由 罗梦 于 2013-4-18 13:25 编辑其中Ni为决策变量,即i类木材的购买的数量,这个模型中有一个约束条件是绝对值(Vi-Vj)<=2 (即购买的不同型号的木材之间的长度差不大于2分米) 在lingo中如何编写这个约束啊 主要是这个约束 小弟弄不来
各位大神 帮帮忙 小弟在此谢了
下面是我的程序 大神看下如何修改啊
sets:
Pvcell/1..13/:power,area,unitprice,count,voc;
links(Pvcell,Pvcell):m;!为了好描述;
endsets
!目标函数;
max=@sum(Pvcell(i):count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(links(i,j):@abs(voc(i)-voc(j))<=2); !小弟这样编写的,导致模型无解,不知原因,该如何编写这个约束条件呢?;
!初始数据的输入;
data:
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End 加一个是非变量a(i)=1 (购买第i号) a(i)=0 不购买
sets:
Pvcell/1..13/:a,power,area,unitprice,count,voc;
links(Pvcell,Pvcell):m;
endsets
max=@sum(Pvcell(i):a(i)*count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(pvcell(i):
@for(pvcell(j)|@abs(voc(j)-voc(i))#gt#2:a(i)+a(j)<=1
)
);
@for(pvcell(i):@bin(a(i))
);
!初始数据的输入;
data:
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End
在lingo/option中勾选全局最优解再运行 如果是非破解版运行结果不一样 我试过了 只买第1,2,8号木材 我也是新手 不过目测你的决策变量应该是count 首先 “@for(links(i,j):@abs(voc(i)-voc(j))<=2); ”中voc我想应该是count 你试试
@FOR(Pvcell(I):
@FOR(Pvcell(J):@ABS(count(J)-count(I))<=2
)); @FOR(Pvcell(I):
@FOR(Pvcell(J) : @ABS(count(J)-count(I))<=2
)); 刚才说错了 估计是要再加一部分是非变量来判断是否买第I号木材 你得把题说全 kf22 发表于 2013-4-18 16:25 static/image/common/back.gif
刚才说错了 估计是要再加一部分是非变量来判断是否买第I号木材 你得把题说全
但是程序怎么编呢?我尝试加入了一个由count决定的变量a,但是我感觉我还是编错了,因为不出结果。我写的程序是@for(Pvcell(i):a(i)=@if(count(i)#ge#1,1,0));
@FOR(Pvcell(I):@FOR(Pvcell(J):@ABS(count(J)-count(I))<=2)); 小弟自己用if和for语句将模型成功求解
sets:
Pvcell/1..13/:power,area,unitprice,count,voc,n;
Pvcell1/1..13/:voc1,m;
links(Pvcell,Pvcell1):k;
endsets
!目标函数;
max=@sum(Pvcell(i):count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(Pvcell(i):n(i)=@if(count(i)#ne#0,voc(i),0));
@for(Pvcell1(j):m(j)=@if(count(j)#ne#0,voc1(j),0));
@for(links(i,j):k(i,j)=@if(m(j)#ne#0#and#n(i)#ne#0,@abs(m(j)-n(i)),0));
@for(links(i,j):k(i,j)<=2);
!初始数据的输入;
data:
voc1=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End
另外我想用matlab优化工具箱解决可以吗???????????? kf22 发表于 2013-4-18 16:10 static/image/common/back.gif
我也是新手 不过目测你的决策变量应该是count 首先 “@for(links(i,j)abs(voc(i)-voc(j))
谢谢 我的问题已解决 可能是我题目没表达清楚 不过还是谢谢
我自己用if和for编的
sets:
Pvcell/1..13/:power,area,unitprice,count,voc,n;
Pvcell1/1..13/:voc1,m;
links(Pvcell,Pvcell1):k;
endsets
!目标函数;
max=@sum(Pvcell(i):count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(Pvcell(i):n(i)=@if(count(i)#ne#0,voc(i),0));
@for(Pvcell1(j):m(j)=@if(count(j)#ne#0,voc1(j),0));
@for(links(i,j):k(i,j)=@if(m(j)#ne#0#and#n(i)#ne#0,@abs(m(j)-n(i)),0));
@for(links(i,j):k(i,j)<=2);
!初始数据的输入;
data:
voc1=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End
问下我可以用matlab优化工具箱解决吗 kf22 发表于 2013-4-18 16:12 static/image/common/back.gif
@FOR(Pvcell(I):
@FOR(Pvcell(J) : @ABS(count(J)-count(I))
不是 可能是我题没表达清楚 不过问题已经自己解决了
程序;
sets:
Pvcell/1..13/:power,area,unitprice,count,voc,n;
Pvcell1/1..13/:voc1,m;
links(Pvcell,Pvcell1):k;
endsets
!目标函数;
max=@sum(Pvcell(i):count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(Pvcell(i):n(i)=@if(count(i)#ne#0,voc(i),0));
@for(Pvcell1(j):m(j)=@if(count(j)#ne#0,voc1(j),0));
@for(links(i,j):k(i,j)=@if(m(j)#ne#0#and#n(i)#ne#0,@abs(m(j)-n(i)),0));
@for(links(i,j):k(i,j)<=2);
!初始数据的输入;
data:
voc1=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End
另外可以用matlab优化工具箱解决吗 kf22 发表于 2013-4-18 00:03 static/image/common/back.gif
加一个是非变量a(i)=1 (购买第i号) a(i)=0 不购买
sets:
多谢 不过我发现你这样编 当我加入另一个约束条件 即不同型号的购买数量相等时 运行需要很久 我这样编的就快很多;
sets:
Pvcell/1..13/:power,area,unitprice,count,voc,n;
Pvcell1/1..13/:voc1,m;
links(Pvcell,Pvcell1):k;
endsets
!目标函数;
max=@sum(Pvcell(i):count(i)*power(i));
!约束条件;
@sum(Pvcell(i):(power(i)*unitprice(i))*count(i))<=65000;
@sum(Pvcell(i):area(i)*count(i))<=30000000;
@for(Pvcell(i):@gin(count(i)));
@for(Pvcell(i):n(i)=@if(count(i)#ne#0,voc(i),0));
@for(Pvcell1(j):m(j)=@if(count(j)#ne#0,voc1(j),0));
@for(links(i,j):k(i,j)=@if(m(j)#ne#0#and#n(i)#ne#0,@abs(m(j)-n(i)),0));
@for(links(i,j):k(i,j)<=2);
!初始数据的输入;
data:
voc1=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
voc=46.1 46.91 46.1 38.1 37.73 45.92 37.91 45.98 33.6 36.9 44.8 45.1 37.83;
power=215 325 200 270 245 295 265 320 210 240 280 295 250;
area=1276640 1938396 1276640 1637792 1635150 1938396 1635150 1938396 1470144 1626880 1940352 1940352 1668000;
unitprice=14.9 14.9 14.9 14.9 14.9 14.9 12.5 12.5 12.5 12.5 12.5 12.5 12.5;
enddata
End
另外可以用matlab优化工具箱解决这种问题不啊啊
页:
[1]