Lingo中的多商品

时间:2019-05-02 09:02:01

标签: lingo

我正在做一个多商品优化模型。一切正常,但是当我想在代码中添加更多约束时,我得到了错误。我想添加最后一个,其中X是发送的产品数量,D是需求。其中X应该等于或大于从i到j的需求。我该怎么解决?

我试图用不同的方式编写代码。

 MODEL:
! Multi-commodity network flow problem;
SETS:
! The nodes in the network;
 NODES/1..6/:;
! The set of nodes that are origins;
 COMMO(NODES)/1, 2, 3, 4, 5, 6/:;
 EDGES(NODES, NODES): D, C, U, V;
 NET(EDGES, COMMO): X;
ENDSETS
DATA:
! Demand: amount to be shipped from
 origin(row) to destination(col);
D = 0 2 4 3 0 2
 0 0 2 0 1 0
 0 0 0 0 0 0
 0 0 0 0 0 0
 0 2 0 1 0 4
 0 0 0 0 0 0;
! Cost per unit shipped over a arc/link;
C = 0 2 3 4 4 4
 2 0 2 1 2 3
 2 1 0 1 2 2
 3 2 2 0 2 2
 4 2 1 3 0 1
 4 3 2 3 3 0;
! Upper limit on amount shipped on each link;
U = 3 2 2 1 1 10
 0 5 1 4 2 4
 2 0 0 1 2 4
 3 3 5 2 4 3
 1 0 1 7 3 2
 2 2 3 1 2 6;
! Whether an arc/link exists or not;
! V = 0 if U = 0;
! V = 1 otherwise;
V =  0 1 1 1 1 1
 0 0 1 1 1 1
 1 0 0 1 1 1
 1 1 1 0 1 1
 1 0 1 1 0 1
 1 1 1 1 1 0; 
ENDDATA
! Minimize ;
MIN = @SUM( NET(I, J, K): C(I, J) * X(I, J, K));
@FOR(COMMO(K): @FOR(NODES(J)|J #NE# K:
 @SUM(NODES(I): V(I, J) * X(I, J, K) - V(J, I) * X(J, I, K))
 = D(K, J);
 );
 @FOR(NODES(J)|J #EQ# K:
 @SUM(NODES(I): V(I, J) * X(I, J, K) - V(J, I) * X(J, I, K))
 = -@SUM( NODES(L): D(K, L)));); 
! Constraint;
!The amount of resources shipped over 
link i to j have to be equal to or lower than the capacity; 
 @FOR(EDGES(I, J)|I #NE# J:
 @SUM(COMMO(K): X(I, J, K)) <= U(I, J);

 ); 

@FOR(EDGES(I, J)|I #NE# J:
 @SUM(COMMO(K): X(I, J, K)) => D(I, J);

 ); 


END

预期结果是获得优化模型。

0 个答案:

没有答案