Search code examples
integercplexopl

CPLEX OPL: Constraint that ensures demand due dates are met


I have a CPLEX OPL model that minimizes the total transport costs of cargo between cities. x is my main (integer) decision variable. All other variables mentioned below are integers. I want to add due dates to this model. This means that the demand at time t (e.g. 3) has to be transported in the period 1 to t (e.g. 1 to 3). However, I can't sum over the period 1 to t.

subject to {
  // Satisfy demands before due date
  forall(i,j in City, t in Times)
      ctDueDate:  
        sum(m in Mode, v in Vehicle, s in 1..t) x[m][i][j][v][s] == sum(s in 1..t) Demand[s][i][j];
}

What is the proper way to code this?


Solution

  • This works fine:

    range City=1..4;
    
    range Times=1..3;
    
    range Mode=1..2;
    
    range Vehicle=1..2;
    
    
    
    int Demand[Times][City][City];
    
    
    
    dvar int x[Mode][City][City][Vehicle][Times] in 0..10;
    
     
    
    
    subject to {
    
      // Satisfy demands before due date
    
      forall(i,j in City, t in Times)
    
          ctDueDate:  
    
            sum(m in Mode, v in Vehicle, s in 1..t) x[m][i][j][v][s] 
    
          == sum(s in >  1..t) Demand[s][i][j];
    
    }