简体   繁体   中英

IBM CPLEX Optimization Studio OPL doesn't respect constraints?

I'm working on a project in which I have a matrix of distances between nodes that I import to cplex. I do it like this:

tuple arc{
 float x;
 float y;
 float d;
 float Ttime;       //Time to travell the arc
 }

 tuple vehicle{
 key int id;
 int STdepot;   //Starting Depot (1 or 2)
 int MaxCars;       //Maximum number of cars in a vehicle
 float AvSpeed;     //Average Speed of a vehicle
 }

tuple cavities{
key int id;
float x;
float y;
float rate;         //Consumption Rate
float iniStock;     //Initial Stock to be consumed at cavitie x
float deadline;     //Deadline to arrive at cavitie x
int ProdCons;       //Production Consumed at cavitie x

}

tuple CAVtype{
key int id;
int CarsCons;       //Consuming cars of 12 or 20
}

tuple nodes{
key int id;
float x;        //Coordinates in X
float y;        //Coordinates in Y
string type;
}       
 setof(arc)         OD = ...;   //DistanceMatrix
 setof(vehicle)     K=...;      //Vehicles
 setof(cavities)    C=...;      //Cavities
 setof(CAVtype)     T=...;      // Cavities Type
 setof(nodes)       N=...;      //Nodes

  float d[N][N];
  float t[N][N];    

execute preProcess{

  cplex.tilim=300;
  for(var i in N){
    for(var j in N){
        d[i][j] = 9999;
        t[i][j] = 9999;
    }
  }

  for(var arc in OD){
  var origin = N.get(arc.x);      
  var destination = N.get(arc.y);

      d[origin][destination] = arc.d;
      t[origin][destination] = arc.Ttime;
  }  
 }

It imports everything, but when I add the restrictions, the distance matrix is not respected and the variables show connections between nodes that don't have connections. Also, the last restrictions changes the value of q, why does this happen? How can I solve this?

Thanks in advance.

The objective function and the restrictions are the following:

    dexpr float MachineStoppage = sum(k in K,i in N,j in N) d[i][j] * x[i][j][k] + 
 sum(g in C,k in K) penalize *phi[g] + sum(i in N,g in C) u[i][g];              //(1)

minimize MachineStoppage;

//*******************************|Restrictions|***********************************************************
subject to{

forall (i in C, k in K)                                         //(2)
  FlowConservation:
 sum(j in N: i.id!=j.id) x[<i.id>][j][k] == z[<i.id>][k];

forall (i in C, k in K)                                         //(3)
  FlowConservation2:
 sum(j in N: i.id!=j.id) x[j][<i.id>][k] == z[<i.id>][k];


 forall(i in N, k in K: i.type == "d" && k.STdepot!= i.id)                                          //(5)
   DepartingFromAnyDepot:
  sum(j in N: i.id!=j.id) x[i][j][k] == 0;


 forall(i in N)                      
   sum(k in K) z[i][k]==1; 

 forall(i in N,j in N,k in K: i!=j && j.id!=0)                          //(8)
   ArrivalTimeTracking1:
  w[k][i] + t[i][j] <= w[k][j] + M*(1-x[i][j][k]);


 forall(i in N,j in N,k in K: i!=j && j.id!=0)                          //(9)
   ArrivalTimeTracking2:
  w[k][i] + t[i][j] >= w[k][j]- M*(1-x[i][j][k]);

 forall(k in K, g in C, i in N)                                         //(10)
   ReplenishmentDelay:
 //w[k][<g.id>] <= g.deadline + phi[g];
  w[k][<g.id>] <= g.deadline + phi[g];

 forall(i in N, g in C, k in K)                                        //(11)
   QuantitiesToBeDeliveredToTheCavities:                            
  q[k][g] == ((g.rate*w[k][<g.id>]) + u[i][g] + (g.ProdCons-g.iniStock));

 forall(i in N,g in C,k in K)                                          //(12)
   LimitofQuantitiesToBeDelivered:
   q[k][g] >= z[i][k] * g.ProdCons;
  //q[k][g] >= z[<i.id>][k] * g.ProdCons;

 forall(h in T, k in K)                                                //(13)
   NumberOfCarsOfEachTypeinEachVehicle:
  sum(i in N,g in C) q[k][g] <= h.CarsCons*y[k][h];

/*
 forall(k in K, g in C)                                                //(14)
   MaximumOfCarsinaVehicle:
  sum(h in T) y[k][h] <=b;
*/

Are you sure you do not get a relaxed solution ? In documentation

IDE and OPL > CPLEX Studio IDE > IDE Tutorials

You could have a look at the section "Relaxing infeasible models".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM