SUBHADARSHINI PANDA
SUBHADARSHINI PANDA

Reputation: 11

What could be the violated constraints or syntax-related issues in the provided CPLEX OPL code when encountering a no solution as an error?

I am trying to solve a mixed-integer type nonlinear optimization model in cplex opl. I am getting no solution while solving the problem in cplex opl. What might be causing this? Could it be a violated constraint or a syntax-related issue within the code?

using CP;

int nm=4;
int r=48;
range num=1..nm;
range hr=1..r;
int scale=100;
float m[hr];
float n[hr];
float S_IN[num]=[0.5783, 0.5883,0.5696,0.59];
float S_D[num]=[0.99294,0.65781,0.91168,0.9408];
float S_R[num]=[0.41468, 0.0695,0.3421,0.3508];
float B_C[num]=[13.8,13.8,13.8,13.8];
int A[num][hr]=[[0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0]];

// Declaration of Decision variables
dvar boolean C[num][hr];
dvar boolean D[num][hr];
dvar int+ scalerc[num][hr];
dvar int+ scalerd[num][hr];
dvar int scaletc[hr];
dvar int scaletd[hr];
dvar int+ scaleB_E[num][hr];


dexpr float rc[i in num][j in hr]=scalerc[i][j]/scale;
dexpr float rd[i in num][j in hr]=scalerd[i][j]/scale;
dexpr float tc[i in hr]=scaletc[i]/scale;
dexpr float td[i in hr]=scaletd[i]/scale;
dexpr float B_E[i in num][j in hr]=scaleB_E[i][j]/scale;
dexpr float b[i in hr]=(((m[i]+tc[i]-td[i])^2)+n[i]^2);
dexpr float nb[i in hr]=sqrt(b[i]);
dexpr float amax=max(i in hr)(nb[i]);
dexpr float nf=1/sum(i in hr)nb[i];


tuple data {
    int slot;
    float mt;
    float nt;
  }
      
data ND[hr] = [
<1, 1025.6,  707.3>,
<2, 1025.6,  707.3>,
<3, 1067.55, 657.2>,
<4, 1067.55, 657.2>,
<5, 1035.1,  641.95>,
<6, 1035.1,  641.95>,
<7, 832.25,  616.45>,
<8, 832.25,  616.45>,
<9, 654.65,  647.2>,
<10, 654.65, 647.2>,
<11, 514.9,  654.95>,
<12, 514.9,  654.95>,
<13, 871.95, 732.85>,
<14, 871.95, 732.85>,
<15, 1587.7, 1347.85>,
<16, 1587.7, 1347.85>,
<17, 1813.35,1586.35>,
<18, 1813.35,1586.35>,
<19, 1839.4, 1802.05>,
<20, 1839.4, 1802.05>,
<21, 2256.2, 2022.25>,
<22, 2256.2, 2022.25>,
<23, 2298.6, 2050>,
<24, 2298.6, 2050>,
<25, 2195.9, 1978.9>,
<26, 2195.9, 1978.9>,
<27, 1776.2, 1830.9>,
<28, 1776.2, 1830.9>,
<29, 1648.8, 1681.15>,
<30, 1648.8, 1681.15>,
<31,  958,   1268.5>,
<32,  958,   1268.5>,
<33, 1070.7, 1242.85>,
<34, 1070.7, 1242.85>,
<35, 1135.95, 1218.85>,
<36, 1135.95,1218.85>,
<37, 1276.2,1256.35>,
<38, 1276.2,1256.35>,
<39, 1338.4,1283.2>,
<40, 1338.4,1283.2>,
<41, 1311.6,1262.3>,
<42, 1311.6,1262.3>,
<43, 1310,1156.75>,
<44, 1310,1156.75>,
<45, 1211.7,1039.1>,
<46, 1211.7,1039.1>,
<47, 1265.75,856.25>,
<48, 1265.75,856.25>
];

execute {
      for(var i in hr){
         var mt = ND[i].mt;
         var nt = ND[i].nt;
         m[i]=mt;
         n[i]=nt;
       } 
     }               
            
// Objective
minimize  amax*48*nf;
subject to {
 forall(i in hr){
   tc[i]==sum(k in num)rc[k][i];
   td[i]==sum(k in num)rd[k][i];
 } 
 forall(i in num){
  forall(j in hr){      
     0.2*B_C[i]<=B_E[i][j]<=B_C[i];
 (C[i][j]==0)=>rc[i][j]==0;
 (D[i][j]==0)=>rd[i][j]==0;
  rc[i][j]==0 => (C[i][j]==0);
  rd[i][j]==0 => (D[i][j]==0);
 (C[i][j]+D[i][j]==0)=> rc[i][j]==0 && rd[i][j]==0 ;
 if(A[i][j]==0){
   C[i][j]==0;
   D[i][j]==0;
    }  
  }
}         
forall (i in num){  
    forall (j in hr){
      0<=rc[i][j]<=1;
      0<=rd[i][j]<=1;
     B_E[i][45]>=S_D[i]*B_C[i];
    if (A[i][j]==0){
          if(j==1){
        B_E[i][j]==S_IN[i]*B_C[i];
        }else{
       B_E[i][j]==B_E[i][j-1];
        }
    }
    else{
      C[i][j]+D[i][j]<=1;                
   B_E[i][j]==B_E[i][j-1]+((rc[i][j]*0.95-rd[i][j]/0.95));    
  }
  }
  }
}

Particularly the addition of the constraints

if (A[i][j]==0){
              if(j==1){
            B_E[i][j]==S_IN[i]*B_C[i];
            }else{
           B_E[i][j]==B_E[i][j-1];
            }
        }
        else{
          C[i][j]+D[i][j]<=1;                
       B_E[i][j]==B_E[i][j-1]+((rc[i][j]*0.95-rd[i][j]/0.95));    
      }  lead to no solution.

Upvotes: 0

Views: 29

Answers (1)

Alex Fleischer
Alex Fleischer

Reputation: 10059

What about relaxing the equality into something a bit more flexible ?

 if (A[i][j]==0){
          if(j==1){ 0==0;
        abs(B_E[i][j]-S_IN[i]*B_C[i])<=0.01;
        }else{
       B_E[i][j]==B_E[i][j-1];
        }
    }
    else{
      C[i][j]+D[i][j]<=1;                
   abs(B_E[i][j]-B_E[i][j-1]-((rc[i][j]*0.95-rd[i][j]/0.95)))<=0.01;    
  }

The following model gives a solution in 30 s

execute
{
  cp.param.timelimit=30;
}


using CP;

int nm=4;
int r=48;
range num=1..nm;
range hr=1..r;
int scale=100;
float m[hr];
float n[hr];
float S_IN[num]=[0.5783, 0.5883,0.5696,0.59];
float S_D[num]=[0.99294,0.65781,0.91168,0.9408];
float S_R[num]=[0.41468, 0.0695,0.3421,0.3508];
float B_C[num]=[13.8,13.8,13.8,13.8];
int A[num][hr]=[[0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
                [0, 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0]];

// Declaration of Decision variables
dvar boolean C[num][hr];
dvar boolean D[num][hr];
dvar int+ scalerc[num][hr];
dvar int+ scalerd[num][hr];
dvar int scaletc[hr];
dvar int scaletd[hr];
dvar int+ scaleB_E[num][hr];


dexpr float rc[i in num][j in hr]=scalerc[i][j]/scale;
dexpr float rd[i in num][j in hr]=scalerd[i][j]/scale;
dexpr float tc[i in hr]=scaletc[i]/scale;
dexpr float td[i in hr]=scaletd[i]/scale;
dexpr float B_E[i in num][j in hr]=scaleB_E[i][j]/scale;
dexpr float b[i in hr]=(((m[i]+tc[i]-td[i])^2)+n[i]^2);
dexpr float nb[i in hr]=sqrt(b[i]);
dexpr float amax=max(i in hr)(nb[i]);
dexpr float nf=1/sum(i in hr)nb[i];


tuple data {
    int slot;
    float mt;
    float nt;
  }
      
data ND[hr] = [
<1, 1025.6,  707.3>,
<2, 1025.6,  707.3>,
<3, 1067.55, 657.2>,
<4, 1067.55, 657.2>,
<5, 1035.1,  641.95>,
<6, 1035.1,  641.95>,
<7, 832.25,  616.45>,
<8, 832.25,  616.45>,
<9, 654.65,  647.2>,
<10, 654.65, 647.2>,
<11, 514.9,  654.95>,
<12, 514.9,  654.95>,
<13, 871.95, 732.85>,
<14, 871.95, 732.85>,
<15, 1587.7, 1347.85>,
<16, 1587.7, 1347.85>,
<17, 1813.35,1586.35>,
<18, 1813.35,1586.35>,
<19, 1839.4, 1802.05>,
<20, 1839.4, 1802.05>,
<21, 2256.2, 2022.25>,
<22, 2256.2, 2022.25>,
<23, 2298.6, 2050>,
<24, 2298.6, 2050>,
<25, 2195.9, 1978.9>,
<26, 2195.9, 1978.9>,
<27, 1776.2, 1830.9>,
<28, 1776.2, 1830.9>,
<29, 1648.8, 1681.15>,
<30, 1648.8, 1681.15>,
<31,  958,   1268.5>,
<32,  958,   1268.5>,
<33, 1070.7, 1242.85>,
<34, 1070.7, 1242.85>,
<35, 1135.95, 1218.85>,
<36, 1135.95,1218.85>,
<37, 1276.2,1256.35>,
<38, 1276.2,1256.35>,
<39, 1338.4,1283.2>,
<40, 1338.4,1283.2>,
<41, 1311.6,1262.3>,
<42, 1311.6,1262.3>,
<43, 1310,1156.75>,
<44, 1310,1156.75>,
<45, 1211.7,1039.1>,
<46, 1211.7,1039.1>,
<47, 1265.75,856.25>,
<48, 1265.75,856.25>
];

execute {
      for(var i in hr){
         var mt = ND[i].mt;
         var nt = ND[i].nt;
         m[i]=mt;
         n[i]=nt;
       } 
     }               
            
// Objective
minimize  amax*48*nf;
subject to {
 forall(i in hr){
   tc[i]==sum(k in num)rc[k][i];
   td[i]==sum(k in num)rd[k][i];
 } 
 forall(i in num){
  forall(j in hr){      
     0.2*B_C[i]<=B_E[i][j]<=B_C[i];
 (C[i][j]==0)=>rc[i][j]==0;
 (D[i][j]==0)=>rd[i][j]==0;
  rc[i][j]==0 => (C[i][j]==0);
  rd[i][j]==0 => (D[i][j]==0);
 (C[i][j]+D[i][j]==0)=> rc[i][j]==0 && rd[i][j]==0 ;
 if(A[i][j]==0){
   C[i][j]==0;
   D[i][j]==0;
    }  
  }
}         
forall (i in num){  
    forall (j in hr){
      0<=rc[i][j]<=1;
      0<=rd[i][j]<=1;
     B_E[i][45]>=S_D[i]*B_C[i];
    if (A[i][j]==0){
          if(j==1){ 0==0;
        abs(B_E[i][j]-S_IN[i]*B_C[i])<=0.01;
        }else{
       B_E[i][j]==B_E[i][j-1];
        }
    }
    else{
      C[i][j]+D[i][j]<=1;                
   abs(B_E[i][j]-B_E[i][j-1]-((rc[i][j]*0.95-rd[i][j]/0.95)))<=0.01;    
  }
  }
  }
}

Upvotes: 0

Related Questions