I use this code in the cplex and don't know why some decision variables don't get value, I attach my code below. I don't know my model is wrong or my code? I haven't error in the code but have some conflicts.

range D=1..3;   {int} DD=asSet(D);    //Distribution centers.
int c=0;        {int} cc={0};         //center.
range I=4..10;  {int} II={4,5,6};     //Local clinics.
range DI=1..10; //D+I
range cD=0..3; //c+D
//range cDI=0..10; //c+D+I
range J=0..10;  {int} JJ= cc union DD union II;       //Vertices.
{int} L={0,1,2} ;                      //Levels which central 0, DC 1, local clinic 2.
range T=0..2;   {int} TT=asSet(T);     //Transportation vehicles which cold truck ( = 0), 4 × 4 truck ( = 1), motorbike ( = 2).
range R=0..3;   {int} RR= {0,1,2,3};   //Storage devices which cold room ( = 0), regional device ( = 1), district device ( = 2), local clinic device ( = 3).
range F=0..1;   {int} FF={0,1};        //Replenishment frequency: {quarterly ( = 0), monthly ( = 1)}.
//Define Arcs---------------------------------------------------------------------------------------------------------------------------------------------------------------
tuple Arc{
key int origin;
key int destination;
{Arc} A1={<0,1>,<0,2>,<0,3>};          //Arcs between center and Distribution centers. 
{Arc} A2={<1,4>,<1,5>,<1,6>,<2,4>,<2,5>,<2,6>,<3,4>,<3,5>,<3,6>,<1,2>,<2,3>,<3,7>,<2,8>,<1,9>,<2,10>};  //Arcs between Distribution centers and locla clinics.
{Arc} A3={<1,2>,<2,3>};               //Arcs between Distribution centers.
{Arc} A={<0,1>,<0,2>,<0,3>,<1,4>,<1,5>,<1,6>,<2,4>,<2,5>,<2,6>,<3,4>,<3,5>,<3,6>,<1,2>,<2,3>,<3,7>,<2,8>,<1,9>,<2,10>}; //total Arcs.
///suppose1:motorbike ( = 2) works by electricity///
{int} chargestation={1,2,3};          //chargestation in route.
range chargestationcopy=1..6;   {int} chargestationcopyy={1,2,3,4,5,6}; //we have three shargestation but it may each chargestation visited more than one.

float C[A][t in T]=rand(10);          //Transportation cost per kilometer of vehicle type t from location i to location j.
float CS[R]=[8116,1582,600,596];      //Annual storage cost per storage device r.
float C0=40000;                       //Annual level 0 facility (central store) operating cost.
float C1[j in D]=4500;                //Annual level 1 facility (DC) operating cost at location j.
float C2[j in I]=800;                 //Annual level 2 facility (clinic) operating cost at location j.
float P[T]= [9293, 172,5];            //Transportation capacity per trip of vehicle t.
float PS[R]=[18000,1843,76,35];       //Storage capacity of device r.
float G[f in F]=(f==0)?4:12;          //Annual number of replenishments f  ( = 4 if f = 0 and = 12 if f = 1).
float S=0.25;                         //Buffer stock factor for vaccines stored at a location (typically = 0.25).
float H[A]= [2,3,2,2,5,6,7,5,8,9,12,13,12,6,5,7,5,6]; //Distance (kilometer) between location i and location j.
float M=100000000;                    //Big M.
///suppose1:motorbike ( = 2) works by electricity///-------------------------------------------------
int Beta=1;                           //(1+ beta) shows the number of copy of shargstations.
int Q =200;                           //motorbike battery capacity.
float e[i in cD][j in DI]=rand(10);   //charge consumption of motorbike from i to j.
int Tmax=200;                         //maximum time that motorbike should drive in two nodes.
float time[i in cD][j in DI]=rand(10);
///suppose2:define cost of green house gas in objective function/////--------------------------------
float costco2=20;                     //average cost of co2 on the ration of weight.
float wco2=10;                        //weight of generate co2 by burning fuel per liter.
float fuel[T]=[10,5,0];               //volume of burning fuel per weight of vehicle and distance.
float w[T]=[100,200,0];               //weight of vehicle.
float wload[T]=[50,40,0];             //weight of load.
float wcurb[T]=[150,240,0];           //weights of vehicle and its load.
int RVC[T]=[3,2,1];                   //ratio of volume of vehicle on weight (without load).
///suppose3:consume fuel for refrigerator///----------
float Emisionfueltoco2[t in T]=0.4;
float Emisionco2torefrigerator[t in T]=0.2;

dvar float+ x[A];                     //Annual flow (volume) of vaccines from location i to location j
dvar float+ Y[J][R][F];               //Number of storage devices of type r at location j with replenishment frequency f 
dvar float+ Z[A][T][F];                   //Number of vehicle trips per replenishment from location i to location j using vehicle type t with replenishment
dvar boolean W[J];                    //1 if a location j is open, 0 otherwise
dvar boolean U[A];                    //1 if vaccines flow from location i to location j, 0 otherwise
dvar boolean V[J];                    //1 if a location j has monthly replenishment frequency, 0 otherwise
///suppose1:motorbike ( = 2) works by electricity///
dvar float+ y[J][T];                      //charge level of motorbike in each node.
dvar float+ q[chargestationcopy][T];   //charge level of motorbike in each chargestation.
dvar float+ O[chargestationcopy][T];   //charge of motorbike when depart from chargestation.
dvar float+ delta[chargestationcopy][T];//period of time being in chargestation.
dvar float+ timeexitchargestationcopy[chargestationcopy][T];//exit time from chargestation.
dvar float+ timeenterchargestationcopy[chargestationcopy][T];//enter time to chargstation.
dvar float+ recievetime[J][T];        //recieve time to a nod
dvar float+ servicetime[J][T];        //service time for costomer or clinic
//dvar float time[cD][DI];            //time period of motorbike when drive from obe node to other.
dvar boolean K[cD][DI][F];                //if motorebike visit i an j be one and else zero.

dexpr float objective= sum(i in A,t in T,f in F)2* C[i][t]*G[f]*H[i]*Z[i][t][f]+
sum(j in J,f in F,r in R)CS[r]*Y[j][r][f]+ C0*W[0]+ sum(j in D)C1[j]*W[j]+sum(j in I)C2[j]*W[j]+sum(i in chargestationcopy, t in T:t==2)delta[i][t]+
sum(i in cD,j in DI,t in T: t==2, f in F)time[i][j]*K[i][j][f]+sum(i in A,t in T:t!=2)H[i]*costco2*wco2*fuel[t]*w[t]*wload[t]+sum(i in A,t in T:t!=2)x[i]*H[i]*wco2*fuel[t]*wcurb[t]/RVC[t]+
sum(t in T:t!=2)fuel[t]*Emisionfueltoco2[t]*Emisionco2torefrigerator[t] ;

minimize objective;
subject to{
cos1:sum(i in A)x[i]-sum(j in A)x[j]==0;
forall(i,j in A)cos2:sum(t in T,f in F)P[t]*G[f]*Z[i][t][f]>=x[i];
cos3:sum(t in T,r in R, f in F,j in J)P[t]*G[f]*Y[j][r][f]>=(1+S)*sum(i in A)x[i];
forall(j in DD)cos4:M*W[j]>=sum(i in A)x[i]+sum(j in A)x[j];
forall(i in A)cos5:x[i]<=M*U[i];
cos6:sum(i in A)U[i]<=1;
forall(j in D)cos7:sum(r in R,f in F)Y[j][r][f]<=M*W[j];
forall(j in J)cos8:sum(r in R)Y[j][r][1]<=M*V[j];
forall(j in J)cos9:sum(r in R)Y[j][r][0]<=M*(1-V[j]);
forall (i in A3,j in J)cos10:x[i]<=M*V[j];
forall (i in A1,k in D)cos11:V[k]<=2-U[i]-(sum(j in A3)U[j]/abs(3));
forall (i in cc union II)cos12:W[i]==1;
forall (i in I)cos13:V[i]==1;
forall (i in A)cos15:x[i]>=0;
///suppose1:motorbike ( = 2) works by electricity///
forall(i in cD, t in T:t==2, f in F)cb1:sum(j in DI)K[i][j][f]<=1;
forall(i in cD,j in DI,t in T:t==2,f in F)cb2:e[i][j]*K[i][j][f]-(1-K[i][j][f])*Q <=y[i][t]-y[j][t];
forall(i in cD,j in DI,t in T:t==2,f in F)cb3:y[i][t]-y[j][t]<=e[i][j]*K[i][j][f]+(1-K[i][j][f])*Q;
forall(i in cD,j in chargestationcopy,t in T:t==2, f in F)cb4:e[i][j]*K[i][j][f]-(1-K[i][j][f])*Q<= y[i][t]-q[j][t];
forall(i in cD,j in chargestationcopy,t in T:t==2, f in F)cb5:y[i][t]-q[j][t]<=e[i][j]*K[i][j][f]-(1-K[i][j][f])*Q;
forall(i in cc,t in T:t==2)cb6:y[i][t]==Q;
forall(i in chargestationcopy,t in T:t==2)cb7:y[i][t]==O[i][t];
forall(i in chargestationcopy,t in T:t==2)cb8:q[i][t]<=O[i][t];
forall(i in chargestationcopy,t in T:t==2)cb9:delta[i][t]==timeexitchargestationcopy[i][t]-timeenterchargestationcopy[i][t];
forall(i in cD,j in DI,t in T:t==2, f in F)cb10:recievetime[i][t]+(time[i][j]+servicetime[j][t])*K[i][j][f]-Tmax*(1-K[i][j][f])<=recievetime[j][t];
forall(i in cD:i!=0,j in chargestationcopy,t in T:t==2, f in F)cb11:recievetime[i][t]+delta[i][t]+time[i][j]*K[i][j][f]-Tmax*(1-K[i][j][f])<=recievetime[j][t];
forall(i in cD,j in DI,t in T:t==2)cb12:recievetime[j][t]+time[i][j]<=Tmax;
forall(t in T:t==2)cb13:recievetime[0][t]<=Tmax;

enter image description here

enter image description here

enter image description here

  • $\begingroup$ are you sure the model is feasible ? Perhaps include the log in your question. $\endgroup$ – Kuifje Feb 24 at 9:24
  • $\begingroup$ I attached the engine log picture. $\endgroup$ – ramin Feb 24 at 9:58
  • $\begingroup$ I attach the whole log. $\endgroup$ – ramin Feb 24 at 10:15
  • 1
    $\begingroup$ it looks like it is infeasible (there are conflicting constraints). What is in the Conflicts tab ? $\endgroup$ – Kuifje Feb 24 at 10:32

your model is not feasible and that is why you get no solution.

if you comment

//forall(i in cD,j in DI,t in T:t==2, f in F)cb10:recievetime[i][t]+(time[i][j]+servicetime[j][t])*K[i][j][f]-Tmax*(1-K[i][j][f])<=recievetime[j][t];

then you ll get some conflicts and relaxations like

72  [0,Infinity]    [-6,Infinity]   delta[1][2]
72  [0,Infinity]    [-10,Infinity]  delta[2][2]
72  [0,Infinity]    [-5,Infinity]   delta[3][2]

and a relaxed solution in the problem browser

relaxed solution in the problem browser

  • $\begingroup$ thanks, Alex Fleischer. You always help me. $\endgroup$ – ramin Feb 24 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.