我已经在GAMS中使用非线性互补建模对运输分配问题进行了编码。该代码非常适合单个OD(原始目标)和多O Single-D情况。但是,当我切换到具有多个OD对的Grid网络时,出现了问题。
我尝试修复某些变量,但仍然要求修复更多变量。
SET N NODES /1*9/;
ALIAS (I,N), (J,N), (K,N), (L,N);
SET DEST(J) IDENTIFICATION OF DESTINATION NODES,
ACTIVE(I,J,K) IDENTIFIES THE SET OF ACTIVE ARCS,
A(N,N) ARCS;
SET PARAM /A, B, K/
TABLE ARC_COST(I,J,PARAM) Arc cost data
A B K
1.5 4 0.6 28
5.2 2 0.3 33
2.3 5 0.75 22
3.9 5 0.75 24
1.6 2 0.3 29
6.7 4 0.6 33
7.8 3 0.45 27
8.9 5 0.75 26
5.4 3 0.45 22
4.8 4 0.6 22
6.4 3 0.45 25
4.3 5 0.75 25;
Parameter COEF_A(I,J), COEF_B(I,J), COEF_K(I,J);
COEF_A(I,J) = ARC_COST(I,J,"A");
COEF_B(I,J) = ARC_COST(I,J,"B");
COEF_K(I,J) = ARC_COST(I,J,"K");
TABLE DMD(I,J) Trip matrix
1 2 3 4 5 6 7 8 9
1 0 0 0 0 0 0 0 0 40
2 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0
5 0 0 20 0 0 0 0 0 0
6 0 0 0 0 0 0 0 25 0
7 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 0 0 0 0
9 0 0 0 0 0 0 0 0 0;
* Identify arcs using flow cost parameter:
A(I,J) = YES$COEF_A(I,J);
* Identify destination nodes using the trip table:
DEST(J) = YES$SUM(I, DMD(I,J));
ACTIVE(A,K) = YES$DEST(K);
ACTIVE(I,J,I) = NO;
ACTIVE(I,I,J) = NO;
Display ACTIVE, COEF_A, COEF_B, COEF_K ;
VARIABLES T(I,J) TIME TO GET FROM NODE I TO NODE J,
X(I,J,K) FLOW TO K ALONG ARC I-J,
F(I,J) AGGREGATE FLOW ON ARC I-J;
EQUATION RATIONAL(I,J,K) COST MINIMIZATION
BALANCE(I,J) MATERIAL BALANCE
FDEF(I,J) AGGREGATE FLOW DEFINITION;
* The time to reach node K from node I is no greater than
* the time required to travel from node I to node J and then
* from node J to node K.
RATIONAL(I,J,K)$ACTIVE(I,J,K).. COEF_A(I,J) + COEF_B(I,J) * POWER(F(I,J)/COEF_K(I,J),4) + T(J,K)=G= T(I,K);
* The flow into a node equals demand plus flow out:
BALANCE(I,K)$T.UP(I,K)..SUM(A(I,J)$ACTIVE(A,K),X(A,K)) =G=SUM(A(J,I)$ACTIVE(A,K),X(A,K)) + DMD(I,K);
* Flow on a given arc constitutes flows to all destinations K:
FDEF(A)..F(A) =E= SUM(K$ACTIVE(A,K), X(A,K));
* Here is the MCP model:
MODEL TRAFFIC /RATIONAL.X, BALANCE.T, FDEF.F/;
* Initial levels for arc flows are needed so that we can
* properly evaluate the nonlinear functions:
F.L(A) = COEF_K(A);
X.L(A,K) = 0.0;
T.L(I,J) = COEF_A(I,J)$A(I,J) + SMIN(K$A(I,K),COEF_A(I,K))$(NOT A(I,J));
* Lower bounds are zero for flows, positive for times:
X.LO(A,K) = 0.0;
T.LO(I,J) = 0.0;
* Fixing values causes corresponding equilibrium conditions
* to be dropped:
T.FX(I,I) = 0;
T.FX(I,J)$(NOT A(I,J)) = 0;
F.FX(I,J)$(NOT A(I,J)) = 0;
option mcp=miles;
SOLVE TRAFFIC USING MCP;
答案 0 :(得分:0)
此模型有点混乱。但是这里有些编辑至少可以为您提供解决方案。
消息非常好:
**** MCP pair BALANCE.T has empty equation but associated variable is NOT fixed
T(1,5)
这是因为当DEST(K)不存在时BALANCE(I,K)为空。解决方法并不困难:
代替
T.FX(I,J)$(NOT A(I,J)) = 0;
写
T.FX(I,K)$(not DEST(K)) = 0;
T还有另一个问题:某些T.LO(I,J).LO和T.L(I,J)值是INF:
T.L(I,J) = COEF_A(I,J)$A(I,J) + SMIN(K$A(I,K),COEF_A(I,K))$(NOT A(I,J));
display T.L;
显示:
---- 98 VARIABLE T.L TIME TO GET FROM NODE I TO NODE J
1 2 3 4 5 6 7 8 9
1 2.000 2.000 2.000 2.000 4.000 2.000 2.000 2.000 2.000
2 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000
3 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000
4 4.000 4.000 5.000 4.000 4.000 4.000 4.000 4.000 4.000
5 2.000 2.000 2.000 3.000 2.000 2.000 2.000 2.000 2.000
6 3.000 3.000 3.000 3.000 3.000 3.000 4.000 3.000 3.000
7 3.000 3.000 3.000 3.000 3.000 3.000 3.000 3.000 3.000
8 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000 5.000
9 +INF +INF +INF +INF +INF +INF +INF +INF +INF
(课程:始终,请检查并再次检查每个步骤的结果是否符合您的预期。)将模型传递给求解器时,不允许使用这些+ INF值(正确地如此) 。我们可以按如下方法使用创可贴:
T.L(i,j)$(T.L(i,j)=INF) = 1e6;
T.LO(i,j)$(T.LO(i,j)=INF) = 1e6;
(我在solve语句之前添加了它)。更好的是:将分配固定为T.L(I,J)。提示:空集上的SMIN是多少?您可能需要考虑一下如何以更结构化的方式来解决这个问题。