Decision Optimization

 View Only
Expand all | Collapse all

CPLEX(default) cannot extract expression

  • 1.  CPLEX(default) cannot extract expression

    Posted Sun January 21, 2018 06:48 AM

    Originally posted by: skyskyhuanghuang


    Hi all,

    I am a newbie in using OPL,i have written like this:

    int M=...;
    float P2=...;
    float H1[1..M][1..M]=...;
    float B0=...;
    float n0=...;
    dvar float+ Yji1[1..M][1..M]in 0..1 ;
    //dvar int Yji1[1..M][1..M] in 0..1 ;
     
    maximize
    B0*sum(i in 1..M)(
         log(1+sum(j in 1..M)(
                 P2*H1[j][i]*Yji1[j][i]/ 
                   (n0+sum(n,q in 1..M)P2*H1[n][i]*Yji1[n][q]
                     -P2*H1[j][i]*sum(k in 1..M)Yji1[j][k])
               )
             )/log(2)
       );
    When I run the code i get errors like:

    CPLEX(default) cannot extract expression: maximize (sum(i in 1..3) (ln(sum(j in 1..3) ((H1[j][i]*0.126)*Yji1[j][i]) / (sum(n in 1..3, q in 1..3) (H1[n][i]*0.126)*Yji1[n][q]+((H1[j][i]*0.126)*(sum(k in 1..3) Yji1[j][k]))*(-1)+6.3e-13)+1) / 2.30258509299405) / (ln(2) / 2.30258509299405))*20000000. 20180120.mod /Solve 20:1-30:5 /home/sky/opl/Solve/20180120.mod OPL Problem Marker

    When I remove the sum of noise power behind, the procedure is right, and this is why

    maximize
    B0*sum(i in 1..M)(
         log(1+sum(j in 1..M)(
                 P2*H1[j][i]*Yji1[j][i]/n0 
                   //(n0+sum(n,q in 1..M)P2*H1[n][i]*Yji1[n][q]
                     //-P2*H1[j][i]*sum(k in 1..M)Yji1[j][k])
               )
             )/log(2)
       );

     I dont know how to fix this or other problems in the code.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: CPLEX(default) cannot extract expression

    Posted Sun January 21, 2018 08:11 AM

    Hi,

    you get that error because log is not linear.

    what you could do is use CPO.

    See for example

    using CP;
     
     int scale=10000;
     
     
     int M=2;
    float P2=1.2;
    float H1[i in 1..M][j in 1..M]=2;
    float B0=1;
    float n0=2;

    //dvar int Yji1[1..M][1..M] in 0..1 ;

    dvar int scaleYji1[1..M][1..M] in 0..scale ;
    dexpr float Yji1[i in 1..M][j in 1..M]=scaleYji1[i][j]/scale;
     
    maximize
    B0*sum(i in 1..M)(
         log(1+sum(j in 1..M)(
                 P2*H1[j][i]*Yji1[j][i]/
                   (n0+sum(n,q in 1..M)P2*H1[n][i]*Yji1[n][q]
                     -P2*H1[j][i]*sum(k in 1..M)Yji1[j][k])
               )
             )/log(2)
       );
       
       subject to
       {
          
       }

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: CPLEX(default) cannot extract expression

    Posted Mon January 22, 2018 01:52 AM

    Originally posted by: skyskyhuanghuang


    thank you very much.But after changing the calculation, time becomes longer, how to solve it?and the decision variable becomes scaleYji1,i just want decision variable to be Yji1.How can i sovle it ?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: CPLEX(default) cannot extract expression

    Posted Mon January 22, 2018 02:50 AM

    Hi,

    you may set a time limit

    execute
    {

    cp.param.timelimit=60;
    }

    You may also stay with CPLEX but then you would have to linearize the log

    See https://www.ibm.com/developerworks/community/forums/html/threadTopic?id=dd4fa84b-4bcb-4be4-8887-0b55e8c8f7f2&ps=25

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: CPLEX(default) cannot extract expression

    Posted Mon January 22, 2018 09:51 PM

    Originally posted by: skyskyhuanghuang


    Thanks for the code.

    execute
    {

    cp.param.timelimit=60;
    }

    but for cplex,It does not seem to work.I don now why.Also, How to set the emphasismip parameter in the mod file to 1?

    Thank you,

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: CPLEX(default) cannot extract expression

    Posted Tue January 23, 2018 01:40 AM

    Hi

    with linear programming:

    cplex.tilim=60;

    cplex.mimpemphasis=1;

    in an execute block

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: CPLEX(default) cannot extract expression

    Posted Tue January 23, 2018 03:52 AM

    Originally posted by: skyskyhuanghuang


    Thank you.


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  RE: Re: CPLEX(default) cannot extract expression

    Posted Mon March 21, 2022 03:43 PM
    Hi,

    I am getting similar error in my code, could you please help me out in solving
    thanks in advance

    int max_k=...;
    int max_t=...;
    range K=1..max_k;
    range T=1..max_t;
    int d[K][T]=...;
    int p[K][T]=...;
    int q[K][T]=...;
    int h[K][T]=...;
    int a[K]=...;
    int M[K][T];
    int C=...;
    float e[K]=...;
    dvar int x[K][T];
    dvar int s[K][T];
    dvar boolean y[K][T];
    minimize sum(k in K,t in T)p[k][t]*x[k][t]+sum(k in K,t in T)q[k][t]*y[k][t]+sum(k in K,t in T)h[k][t]*s[k][t];
    subject to {
    forall(t in T, k in K){
    s[k][t-1]+x[k][t]==d[k][t]+s[k][t];
    }
    forall(k in K){
    s[k][0]==0;
    }
    forall(t in T, k in K){
    x[k][t]<=M[k][t]*y[k][t];
    }
    forall(k in K, t in T){
    M[k][t]==9999999999;
    }
    forall(t in T){
    sum(k in K)e[k]*s[k][t]<=C;
    }
    }

    ------------------------------
    Vaidik Miyani
    ------------------------------



  • 9.  RE: Re: CPLEX(default) cannot extract expression

    IBM Champion
    Posted Mon March 21, 2022 05:36 PM
    In your first constraint, when t = 1 you refer to s[k][0], which does not exist.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 10.  Re: CPLEX(default) cannot extract expression

    Posted Wed May 30, 2018 09:26 AM

    Originally posted by: MaxImal14582906


    Hey,

     

    I get the same error and i have a similar problem. My Optimization Problem looks like this:

    My code looks like this:

    //parameters

     

    int m=...; //number of machines

     

    int n=...; //number of time steps in overall simulation

     

    int p=...; // number of time steps in power cycle

     

    float Pmin=...; //minimum of production

     

    float Pmax=...; //maximum of production

     

     

     

    range machines = 1..m;

     

    range time = 1..n;

     

    range ptime = 1..p;

     

     

    float power [machines][ptime]=...;

    // float msteps [machines];

     

     

    // variables

     

    dvar int+ x[machines][time];

     

    /*dvar int+ i in 1..n;

    dexpr int+ y=i-inew+1;

    dexpr int+ inew=i-y+1;

    dexpr int+ inewp=i-msteps[machines];*/

     

     

    minimize

     

    sum (i in time, j in machines, inew in ptime) x[j][i-inew+1]*power[j][inew]

    ;

     

     

    subject to {

     

    forall (j in machines, i in time)

     

    Start_m:

     

    sum (inew in (i-p+1)..i) x[j][inew] <= 1;

     

     

    Powerrange:

     

    Pmin <= sum (i in time, j in machines, inew in ptime) x[j][i-inew+1]*power[j][inew] <= Pmax;

     

     

    forall (j in machines, i in time)

     

    Range_binaryVariable:

     

    0 <= x[j][i] <= 1;

    }

     

    I think the problem is that my binary variable has changing index. But I do not know how to solve, so I would be happy if you could help me.

     

    Best Regards


    #DecisionOptimization


  • 11.  Re: CPLEX(default) cannot extract expression

    Posted Wed May 30, 2018 02:42 PM

    Hi,

    you got out of range.

    Let me fix the objective in order to show you the way.

    You should change

    minimize

     

    sum (i in time, j in machines, inew in ptime) x[j][i-inew+1]*power[j][inew]

    into

    minimize

     

    sum (i in time, j in machines, inew in ptime: (i-inew+1) in time) x[j][i-inew+1]*power[j][inew]

    ;

    regards

     

    https://www.linkedin.com/pulse/ist-mathematische-optimierung-und-wie-kann-sie-helfen-alex-fleischer/

    ;


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 12.  Re: CPLEX(default) cannot extract expression

    Posted Fri August 09, 2019 07:14 AM

    Originally posted by: reru90


    hi,

    I have the same issue "CPLEX(default) cannot extract expression". can someone halp me, please?

     

    Best Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 13.  Re: CPLEX(default) cannot extract expression

    Posted Mon September 02, 2019 02:06 AM

    Hi,

    you multiply a decision variable int by a decision variable boolean.

    In https://www.linkedin.com/pulse/how-opl-alex-fleischer/

    you could have a look at

    How to multiply a decision variable by a boolean decision variable in CPLEX ?

    if you add

    using CP;

    the error will go away.

    regards

     

     

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 14.  RE: Re: CPLEX(default) cannot extract expression

    Posted Wed April 28, 2021 11:33 AM

    hi,

    I have a lot of error messages that read: "CPLEX(default) cannot extract expression". Can someone maybe help me with this?
    If I add using CP; than the number of errors goes from 30 to 20. I want to optimize a single vehicle IRP ((Bertazzi & Speranza, 2013)

    Best Regards



    ------------------------------
    Bastiaan Devilee
    ------------------------------



  • 15.  RE: Re: CPLEX(default) cannot extract expression

    IBM Champion
    Posted Mon May 03, 2021 04:45 PM
    For future reference, starting a question is preferable to jumping on an old thread.

    Your last constraint is definitely incorrect. You are using the same symbol (i) as an index variable in both the forall qualifier and the summations. This makes no mathematical sense. You need to use a different symbol for one or the other.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 16.  RE: Re: CPLEX(default) cannot extract expression

    Posted Thu July 15, 2021 09:15 AM
    Hello I got errors in my latency constraint section where it says "CPLEX cannot extract expression" below i attached the file, can anyone help me , Thankss !!

    ------------------------------
    Brandon Wymer Pramana
    ------------------------------



  • 17.  RE: Re: CPLEX(default) cannot extract expression

    Posted Thu July 15, 2021 09:32 AM
    Hi,

    your constraints should be linear and 1/x is not.

    Let me fix the first one that gives some errors:

    forall(i in cloud)
    //1/(capacityCloud[i]-(arrivalCloud[i]+sum(k in fog) OffCloudFog[i][k]-sum(j in fog)OffFogCloud[j][i]))<=latencyMax;
    
    capacityCloud[i]-(arrivalCloud[i]+sum(k in fog) OffCloudFog[i][k]-sum(j in fog)OffFogCloud[j][i])>=1/latencyMax;
    ​


    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 18.  RE: Re: CPLEX(default) cannot extract expression

    Posted Thu July 15, 2021 10:31 AM
    Thanks I just get it fixed !!

    ------------------------------
    Brandon Wymer Pramana
    ------------------------------



  • 19.  RE: Re: CPLEX(default) cannot extract expression

    Posted Thu February 17, 2022 03:54 PM
    Hi,

    I have the same error (cannot extract expression)...
    tuple Operation{
      key int id;
      string name;
      int duration;
    }
    
    tuple resourceTypes{ 
      key int id;
      string name;
    }
    
    tuple NeededResources{
      key int opId;
      key int resourceType;
      int neededNumber;
    }
    
    tuple Resource{ 
      key int id;
      int resourceType;
    }
    
    {Operation} operations = ...;
    {resourceTypes} resTypes = ...; 
    {NeededResources} neededRes = ...; 
    {Resource} resources = ...; 
    ​

    ... then in my constraints:

             forall(op in operations){
                forall(rt in resTypes){
                  item(neededRes,ord(neededRes,<op.id,rt.id>)).neededNumber == sum(rc in resources: rc.resourceType==rt.id) p[op][rc];
                  //sum(rc in resources: rc.resourceType==rt.id) p[op][rc] <= 10;
                  //item(neededRes,ord(neededRes,<op.id,rt.id>)).neededNumber <= 10;
                }
              }

    After testing separately each part it seems like the issue is with "item(neededRes,ord(neededRes,<op.id,rt.id>)).neededNumber", but I have no idea why.

    Thanks in advance!



    ------------------------------
    Mehdi El Krari
    ------------------------------



  • 20.  RE: Re: CPLEX(default) cannot extract expression

    Posted Fri February 18, 2022 02:16 AM
    Are you sure
    ord(neededRes,<op.id,rt.id>)​

    always return a valid value?
    You should try to create array comprehensions outside of the subject to to decompose the content of the forall and see where the error comes from.
    You might get a clearer error message than the CPLEX one.

    ------------------------------
    Vincent Beraudier
    ------------------------------



  • 21.  RE: Re: CPLEX(default) cannot extract expression

    Posted Fri February 18, 2022 10:40 AM
    Thanks Vincent!

    You were right :)

    ------------------------------
    Mehdi El Krari
    ------------------------------



  • 22.  RE: Re: CPLEX(default) cannot extract expression

    Posted Fri February 18, 2022 02:17 AM
    Hi,

    have you thought about sharing .mod and .dat so that other users could try ?

    regards

    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------



  • 23.  RE: Re: CPLEX(default) cannot extract expression

    Posted Fri February 18, 2022 10:42 AM
    Thanks for the reply, Alex :)

    Vincent's reply was helpful to my issue.

    ------------------------------
    Mehdi El Krari
    ------------------------------



  • 24.  RE: Re: CPLEX(default) cannot extract expression

    Posted Wed May 25, 2022 03:55 PM
    Hello,
    I have two non-linear constraints (integer decision variable / boolean decision variable) which I cant solve. Constraints are in the section "Fairness constraints"

    How can I solve them? Thanks for your support.

    Gonzalo

    ------------------------------
    Gonzalo Arturo Garcia Moreno
    ------------------------------



  • 25.  RE: CPLEX(default) cannot extract expression

    Posted Tue December 12, 2023 02:45 PM

    I have the same error , could anyone help me with it . The code 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)
    }
    
    
    


    ------------------------------
    Nguyen Diem
    ------------------------------



  • 26.  RE: CPLEX(default) cannot extract expression

    Posted Tue December 12, 2023 02:45 PM

    I have the same errors,can anyone help me with it. The code 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)
    }



    ------------------------------
    Nguyen Diem
    ------------------------------