title: How to Model a Multi OD-pair Grid Network Using Nonlinear Complementarity Program in GAMS
body: <p>I have coded a transport assignment problem using Non-liner complementary modeling in GAMS. The code runs perfect for single OD (Origin-Destination), and multi-O Single-D cases. However, when I switch to solve a Grid network with Multiple OD pairs, something goes wrong. </p>
  
  <p>I have tried fixing some of the variables, but still it asks for fixing more of them. </p>
  
  <pre><code>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;
  </code></pre>