CPlex:所有决策变量“无值”以及如何解决冲突

问题描述 投票:0回答:1

我运行代码,结果对于所有决策变量始终“无值”。在冲突选项卡中它显示:“ct20#1#10#4,ct21#1#10#4,ct22#1#10#4)”,但我卡住了,不知道如何纠正并获得结果。谁能帮我?。我在模型中添加了 ct20,因为 p_jkt_y[j][k][t] 是在时间间隔 t 部署到块 j 的 RTGC k 的平均利用率,这是我的 ct21 和 ct22 :

using CP;
int Z_val = ...;
int P_val = 10;
int T_val = 20;

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 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];

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
int scale = 1000;
dvar int+ p_z_S[Z];// Starting appointment period for delivery trucks related to vessel z
dvar int+ p_z_E[Z];//Ending appointment period for delivery trucks related to vessel z

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



dvar int+ a[Z][P];
dvar int+ b[Z][T] ;
dvar int+ c[I][T]  ;
dvar int+ dm[I][T];
dvar int+ e[I][T];
dvar int+ f[I][T];
dvar int+ g[P];
dvar int+ h;
dvar int+ i[T] ;
dvar int+ jm[J][T] ;
dvar int+ k[J][T] ;
dvar int+ l[J][K][T];
dvar int+ ma[J][K][T];
dvar int+ n[J][P];
dvar int+ o;



dexpr float lambda_zp[z in Z][p in P] = a[z][p] / scale;// Appointment quota of export containers related to vessel z at appointment period p
dexpr float lambda_zt_g[z in Z][t in T]= b[z][t]/scale;
dexpr float lambda_it_g[i in I][t in T]= c[i][t]/scale;
dexpr float l_it_g[i in I][t in T] = dm[i][t] / scale;// Average number of trucks waiting in queue at gate lane i at interval t
dexpr float d_it_g[i in I][t in T] = e[i][t] / scale;// Actual discharge rate of gate lane i at interval t (truck/min)
dexpr float p_it_g[i in I][t in T] = f[i][t] / scale;// Capacity utilization rate of gate lane i at interval t
dexpr float w_p_g[p in P] = g[p] / scale;// Average waiting time of trucks at terminal gate during appointment period p (min)
dexpr float w_g = h / scale;// Average waiting time of trucks at terminal gate during the planning horizon (min)
dexpr float lambda_t_y[t in T]=i[t]/ scale;
dexpr float lambda_jt_y[j in J][t in T]=jm[j][t]/ scale;
dexpr float l_jt_y[j in J][t in T]= k[j][t]/ scale;
dexpr float d_jkt_y[j in J][k in K][t in T] = l[j][k][t] / scale;// Discharge rate of RTGC k deployed to block j at interval t (natural container/min)
dexpr float p_jkt_y[j in J][k in K][t in T] = ma[j][k][t] / scale;// Average utilization rate of RTGC k deployed to block j at interval t
dexpr float w_jp_y[j in J][p in P] = n[j][p] / scale;// Average waiting time of trucks at block j in appointment period p (min)
dexpr float w_y = o / scale;// 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

constraint g2[z in Z][t in T];

// 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)
    ct1:( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val >= T_l;
    ct2:p_z_E[z] > p_z_S[z];
  }
    forall ( z in Z ) {//(2)
    ct2a:( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val <= T_k;
    p_z_E[z] > p_z_S[z];
  }
    forall ( z in Z )//(3)
    ct3:p_z_E[z] * 24 * N / P_val <= T_z_A[z];

    forall ( z in Z, p in P ) {//(4)
    ct4:lambda_zp[z][p] * ( p_z_E[z] - p_z_S[z] + 1 ) == V_z[z] ;
    ct5:( p_z_E[z] - p_z_S[z] + 1 ) != 0;
  }
    forall ( z in Z, p in P ) {//(5)
    if ( ( p - 1 ) * 24 * N / P_val >= T_z_D[z] ) {
      d_zp[z][p] == 1;
    }
    else {
      d_zp[z][p] == 0;
    }
  }
    forall ( j in J, p in P )//(6)
    ct6: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)
    g2[z][t]: lambda_zt_g[z][t] ==  lambda_zp[z][p]  / ( m * alpha ) 
    ;

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

//forall ( i in I, t in T  )
    //ct9:l_it_g[i][t]>=0.00001; 
    
    forall ( i in I, t in 1 .. T_val - 1 )//(9)
    ct10: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)
    ct11:d_it_g[i][t] == ( 19 / 60 ) * p_it_g[i][t] ;

    forall ( i in I, t in T ) {//(11)
    
    ct12:l_it_g[i][t] == p_it_g[i][t]/( 1 - p_it_g[i][t] ) ;
    ct13:p_it_g[i][t]!=1;
  }
    forall ( p in P )//(12)
    ct14: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] )<= 0.01 ;

  ct15: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)
    ct16: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)
    ct17: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 T  )
    //ct18:l_jt_y[j][t]>=0.000001;
    
    forall ( j in J, t in 1 .. T_val - 1 )//(16)
    ct19: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)
  ct20:p_jkt_y[j][k][t] <=1;

  forall ( j in J,t in T,k in K //(17)
  ) {
    ct21:d_jkt_y[j][k][t] == ( 19 / 60 ) * p_jkt_y[j][k][t] ;
    
  }
  forall ( j in J,t in T,k in K //(18)
  )
    ct22: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)
    ct23:l_jt_y[j][t] <= gamma;

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

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



}

dat.文件:

SheetConnection my_sheet("eee.xlsx");
Z_val = 8;
I_val = 4;
J_val = 5;
N = 2;
alpha = 1.5;
gamma = 8;
C_s = 0.42687;
T_l= 6;
T_k= 48;
c_o = 5.728;
c_R = 15.48;

K_val from SheetRead (my_sheet,"Sheet1!B4");
fact_K_minus_1 from SheetRead (my_sheet,"Sheet1!D4");

T_z_A from SheetRead (my_sheet,"Sheet1!B7:B14");
T_z_D from SheetRead (my_sheet,"Sheet1!C7:C14");
V_z from SheetRead (my_sheet,"Sheet1!D7:D14");
Y_j from SheetRead (my_sheet,"Sheet1!L7:L11");
factorial from SheetRead(my_sheet,"Sheet1!I7:I11");

beta_zj from SheetRead (my_sheet,"Sheet1!:B22:I26");

我的Excel文件 https://docs.google.com/spreadsheets/d/1j4R45RKG53Gaz68DnBP36OLT3vitgcAd/edit#gid=1448362513

optimization error-handling cplex constraint-programming check-constraints
1个回答
0
投票

如果将等式 a==b 转换为 abs(a-b),你可以走得更远<=0.01

执行 { cp.param.timelimit=300; }

using CP;

int Z_val = ...;
int P_val = 10;
int T_val = 20;

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 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];

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
int scale = 1000;
dvar int+ p_z_S[Z];// Starting appointment period for delivery trucks related to vessel z
dvar int+ p_z_E[Z];//Ending appointment period for delivery trucks related to vessel z

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



dvar int+ a[Z][P];
dvar int+ b[Z][T] ;
dvar int+ c[I][T]  ;
dvar int+ dm[I][T];
dvar int+ e[I][T];
dvar int+ f[I][T];
dvar int+ g[P];
dvar int+ h;
dvar int+ i[T] ;
dvar int+ jm[J][T] ;
dvar int+ k[J][T] ;
dvar int+ l[J][K][T];
dvar int+ ma[J][K][T];
dvar int+ n[J][P];
dvar int+ o;



dexpr float lambda_zp[z in Z][p in P] = a[z][p] / scale;// Appointment quota of export containers related to vessel z at appointment period p
dexpr float lambda_zt_g[z in Z][t in T]= b[z][t]/scale;
dexpr float lambda_it_g[i in I][t in T]= c[i][t]/scale;
dexpr float l_it_g[i in I][t in T] = dm[i][t] / scale;// Average number of trucks waiting in queue at gate lane i at interval t
dexpr float d_it_g[i in I][t in T] = e[i][t] / scale;// Actual discharge rate of gate lane i at interval t (truck/min)
dexpr float p_it_g[i in I][t in T] = f[i][t] / scale;// Capacity utilization rate of gate lane i at interval t
dexpr float w_p_g[p in P] = g[p] / scale;// Average waiting time of trucks at terminal gate during appointment period p (min)
dexpr float w_g = h / scale;// Average waiting time of trucks at terminal gate during the planning horizon (min)
dexpr float lambda_t_y[t in T]=i[t]/ scale;
dexpr float lambda_jt_y[j in J][t in T]=jm[j][t]/ scale;
dexpr float l_jt_y[j in J][t in T]= k[j][t]/ scale;
dexpr float d_jkt_y[j in J][k in K][t in T] = l[j][k][t] / scale;// Discharge rate of RTGC k deployed to block j at interval t (natural container/min)
dexpr float p_jkt_y[j in J][k in K][t in T] = ma[j][k][t] / scale;// Average utilization rate of RTGC k deployed to block j at interval t
dexpr float w_jp_y[j in J][p in P] = n[j][p] / scale;// Average waiting time of trucks at block j in appointment period p (min)
dexpr float w_y = o / scale;// 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

constraint g2[z in Z][t in T];

// 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)
    ct1:( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val >= T_l;
    ct2:p_z_E[z] > p_z_S[z];
  }
    forall ( z in Z ) {//(2)
    ct2a:( p_z_E[z] - p_z_S[z] + 1 ) * 24 * N / P_val <= T_k;
    p_z_E[z] > p_z_S[z];
  }
    forall ( z in Z )//(3)
    ct3:p_z_E[z] * 24 * N / P_val <= T_z_A[z];

    forall ( z in Z, p in P ) {//(4)
    ct4:abs(lambda_zp[z][p] * ( p_z_E[z] - p_z_S[z] + 1 ) - V_z[z] )<=0.01;
    ct5:( p_z_E[z] - p_z_S[z] + 1 ) != 0;
  }
    forall ( z in Z, p in P ) {//(5)
    if ( ( p - 1 ) * 24 * N / P_val >= T_z_D[z] ) {
      d_zp[z][p] == 1;
    }
    else {
      d_zp[z][p] == 0;
    }
  }
  
  
    forall ( j in J, p in P )//(6)
    ct6: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)
    g2[z][t]: abs(lambda_zt_g[z][t] -  lambda_zp[z][p]  / ( m * alpha ))<=0.01; 
    ;

    forall ( i in I, t in T )//(8)
    ct8:abs(lambda_it_g[i][t] - ( sum ( z in Z ) lambda_zt_g[z][t] / I_val ))<=0.01 ;

//forall ( i in I, t in T  )
    //ct9:l_it_g[i][t]>=0.00001; 
    
    forall ( i in I, t in 1 .. T_val - 1 )//(9)
    ct10:abs(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 ))<=0.01 ;

    
    
    forall ( i in I, t in T )//(10)
    ct11:abs(d_it_g[i][t] - ( 19 / 60 ) * p_it_g[i][t] )<=0.01;

    forall ( i in I, t in T ) {//(11)
    
    ct12:abs(l_it_g[i][t] - p_it_g[i][t]/( 1 - p_it_g[i][t] ) )<=0.01;
    ct13:p_it_g[i][t]!=1;
  }
    forall ( p in P )//(12)
    ct14: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] )<= 0.01 ;

  //ct15:abs(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] ))<=0.01 ;//(13)



  // Constraints at yard
    forall ( t in T )//(14)
    ct16: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)
    ct17:abs(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] )
       ))<=0.01 ;
 //forall ( j in J, t in T  )
    //ct18:l_jt_y[j][t]>=0.000001;
    
   forall ( j in J, t in 1 .. T_val - 1 )//(16)
    ct19:abs(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 ) ))<=100 ;
// 
 forall ( j in J,t in T,k in K) //(17)
  ct20:p_jkt_y[j][k][t] <=1;

  forall ( j in J,t in T,k in K //(17)
  ) {
    ct21:abs(d_jkt_y[j][k][t] - ( 19 / 60 ) * p_jkt_y[j][k][t])<=0.01 ;
    
  }
  forall ( j in J,t in T,k in K //(18)
  )
    ct22:abs(-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] ))<=0.01 ;
//
    forall ( j in J, t in T )//(19)
    ct23:l_jt_y[j][t] <= gamma;
//
    forall ( j in J, p in P )//(20)
    ct24:abs(w_jp_y[j][p] * sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m, k in K )
       d_jkt_y[j][k][t] - ( sum ( t in ( ( p - 1 ) * m + 1 ) .. p * m )
       l_jt_y[j][t] ))<=0.01 ;

  ct25:abs(w_y * sum ( t in T, j in J, k in K ) d_jkt_y[j][k][t] - ( sum ( t in T ) sum 
  ( j in J ) l_jt_y[j][t] ))<=0.01 ;//(21)



}

给出了解决方案

© www.soinside.com 2019 - 2024. All rights reserved.