Non linear constraints in Cplex opl

45 views Asked by At

``Can anyone help me check this Cplex code, it has many errors that can not extract the expression for many constraints, especially 15 and 18 . Many others have the same problem but I move the denominator to the left and the errors go away. Is ít ok to do that? Moreover, in the constraint (5) d_zp[z][p] = 1 if (p - 1) * 24 * N / P_val >=T_z_D[z] , otherwise d_zp[z][p] =0. I write the code below for constraints 15 , is it right? ''' `

int Z_val = ...;
int P_val = 18;
int T_val = 54;
int I_val = ...;
int J_val = ...;
int K_val = ...;
int N = ...; // Planning horizon (day);
float alpha = ...; // The average loading rate of delivery trucks;
float gamma = ...; // The maximum of containers waiting in the queue at each block.
int BigM = 1000;
int fact_K_minus_1 = ...;

range Z = 1 .. Z_val; // Number of vessels
range P = 1 .. P_val; // Number of appointment periods
range T = 1 .. T_val; // Number of time intervals
range I = 1 .. I_val; // Number of gate lanes
range J = 1 .. J_val; // Number of yard blocks
range K = 1 .. K_val; // Number of RTGCs

float T_z_A[Z] = ...;
float T_z_D[Z] = ...;
float V_z[Z] = ...;
float beta_zj[Z][J] = ...;

float C_s = ...;
range KSet = 0 .. K_val - 1;
float T_l = ...;
float T_k = ...;

float Y_j[J] = ...;
float c_o = ...;
float c_R = ...;
float factorial[KSet] = ...;

// Define sets
{int} Z_j[J];

// Objective function or constraints go here

execute {
  // Iterate over j and z to update Z sets
  for (var j in J) {
    for (var z in Z) {
      if (beta_zj[z][j] > 0) {
        Z_j[j].add(z); // Add z to the set Z_j[j]
      }
    }
  }

  // Print the result (optional)
  for (var j in J) {
    writeln("Z_j[", j, "] = ", Z_j[j]);
  }
}



// Decision variables
dvar float p_z_S[Z];// Starting appointment period for delivery trucks related to vessel z
dvar float p_z_E[Z] ;// Ending appointment period for delivery trucks related to vessel z

// Derived variables
float d = ceil ( T_val / P_val );// Number of time intervals in one appointment period
int m = ftoi ( d );
execute{
  writeln(m);
}


dvar float  lambda_zp[Z][P];// Appointment quota of export containers related to vessel z at appointment period p

dvar float lambda_zt_g[Z][T];// Number of trucks related to vessel z arriving at terminal gate at interval t
dvar float lambda_it_g[I][T];// Number of trucks arriving at gate lane i at interval t
dvar float+ l_it_g[I][T] ;// Average number of trucks waiting in queue at gate lane i at interval t
dvar float+ d_it_g[I][T];// Actual discharge rate of gate lane i at interval t (truck/min)
dvar float+ p_it_g[I][T];// Capacity utilization rate of gate lane i at interval t
dvar float+ w_p_g[P];// Average waiting time of trucks at terminal gate during appointment period p (min)
dvar float+ w_g;// Average waiting time of trucks at terminal gate during the planning horizon (min)
dvar float+ lambda_t_y[T];// Number of export containers arriving at yard at interval t
dvar float lambda_jt_y[J][T];// Number of export containers arriving at block j at interval t
dvar float l_jt_y[J][T];
dvar float+ d_jkt_y[J][K][T];// Discharge rate of RTGC k deployed to block j at interval t (natural container/min)
dvar float+ p_jkt_y[J][K][T];// Average utilization rate of RTGC k deployed to block j at interval t
dvar float+ w_jp_y[J][P];// Average waiting time of trucks at block j in appointment period p (min)
dvar float+ w_y;// Average waiting time of trucks at yard in the planning horizon (min)
dvar boolean d_zp[Z][P];// Binary variable, 1 if vessel z has departed at appointment period p, 0 otherwise


// Objective function
minimize
   ( sum ( t in T ) sum ( i in I ) l_it_g[i][t] + sum ( t in T ) sum ( j in J )
     l_jt_y[j][t] ) * ( 24 * N * c_o / T_val ) + sum ( j in J ) sum ( k in K )
     sum ( t in T ) ( 1 - p_jkt_y[j][k][t] ) * 24 * N * c_R / T_val;
subject to {
  // Constraints 1


    forall ( z in Z )//(1)
    ( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val >= T_l;

    forall ( z in Z )//(2)
    ( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val <= T_k;

    forall ( z in Z )//(3)
    p_z_E[z] * 24 * N / P_val <= T_z_A[z];

   forall ( z in Z, p in P ) //(4)
    lambda_zp[z][p] *(p_z_E[z] - p_z_S[z] + 1) == V_z[z]  ;  
  
  
    forall (z in Z, p in P) {
  (p - 1) * 24 * N / P_val - T_z_D[z] >= BigM * (d_zp[z][p] - 1);
  (p - 1) * 24 * N / P_val - T_z_D[z] <= BigM * d_zp[z][p];
}

  forall ( j in J, p in P ) //(6)
    sum ( z in Z_j[j] ) (sum ( a in 1 .. p ) 
      ( lambda_zp[z][a] - V_z[z] * d_zp[z][a] )) * beta_zj[z][j] <= Y_j[j];

  // Constraints at gate
    forall ( z in Z, p in P, t in ( ( p - 1 ) * m + 1 ) .. p * m )//(7)
    lambda_zt_g[z][t] == lambda_zp[z][p] / ( m * alpha );

    forall ( i in I, t in T )//(8)
    lambda_it_g[i][t] == sum ( z in Z ) lambda_zt_g[z][t] / I_val;

    forall ( i in I, t in 1 .. T_val - 1 )//(9)
    l_it_g[i][t + 1] == maxl ( l_it_g[i][t] + lambda_it_g[i][t] - 
      ( 24 * 60 * N * d_it_g[i][t] / T_val ), 0 );

    forall ( i in I, t in T )//(10)
    d_it_g[i][t] == ( 19 / 60 ) * p_it_g[i][t];

    forall ( i in I, t in T )//(11)
    l_it_g[i][t] * ( 1 - p_it_g[i][t] ) == p_it_g[i][t];
    forall ( p in P )//(12)
    w_p_g[p] * sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m ) sum ( i in I ) d_it_g[i][t] == sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m ) sum ( i in I )
       l_it_g[i][t] ;

    w_g * sum ( t in T ) sum ( i in I ) d_it_g[i][t]== sum ( t in T ) sum ( i in I ) l_it_g[i][t]  ;//(13)

  // Constraints at yard
    forall ( t in T )//(14)
    lambda_t_y[t] == ( 24 * 60 * N / T_val ) * sum ( i in I ) d_it_g[i][t];

   forall ( j in J, t in T )//(15)
    lambda_jt_y[j][t] == lambda_t_y[t] * alpha * sum ( z in Z_j[j] )(beta_zj[z][j] * lambda_zt_g[z][t] / sum ( i in I ) lambda_it_g[i][t]);
      

    forall ( j in J, t in 1.. T_val-1 )//(16)
    l_jt_y[j][t + 1] == maxl ( l_jt_y[j][t] + lambda_jt_y[j][t] - ( 24 * 60 * N / T_val ) * sum ( k in K ) d_jkt_y[j][k][t], 0 );

      forall ( j in J, t in T, k in K) //(17)
      d_jkt_y[j][k][t] == ( 9 / 60 ) * p_jkt_y[j][k][t];

    forall ( j in J, t in T, k in K) //(18)
    l_jt_y[j][t] == (( p_jkt_y[j][k][t]  * ( 1 + C_s * C_s ))/ ( 2 * ( K_val - p_jkt_y[j][k][t] ) )) * ( 1 + ( fact_K_minus_1 * ( K_val - p_jkt_y[j][k][t] ) ) )* sum ( n in KSet ) (1 / ( factorial[n] *  
       (p_jkt_y[j][k][t]   ^ ( K_val - n )  ))) ^ ( - 1 ) + p_jkt_y[j][k][t];


    forall ( j in J, t in T )//(19)
    l_jt_y[j][t] <= gamma;

    forall ( j in J, p in P )//(20)
    w_jp_y[j][p] == sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m )l_jt_y[j][t] / sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m,k in K ) d_jkt_y[j][k][t];

  w_y == sum ( t in T ) sum ( j in J ) l_jt_y[j][t] / sum ( t in T, j in J,k in K ) d_jkt_y[j][k][t];//(21)
}




```
0

There are 0 answers