Search code examples
cplexweighted-average

how to solve weighetd average constraints in Cplex OPL?


I am using Cplex to solve supply chain optimization model, Objective function is linear, some constraints include the weighted average moisture content is nonlinear constraints, and errors happen.

forall(j in S)

  minMC<=(sum (i in H) X[i][j] *MC[i][j])/sum (i in H) X[i][j];

  forall(j in S)
  (sum (i in H) X[i][j]*MC[i][j])/sum (i in H) X[i][j]>= maxMC; 

Errors:

Description Resource Path   Location Type CPLEX(default) cannot extract expression:
 forall(j in 1..12) 0.45 <= (sum(i in 1..24) X[i][j]*MC[i][j]) / (sum(i in 1..24) X[i][j]).

Solution

  • you should not divide by a decision variable if you use linear programming but you could manage by multiplying both side of the inequality.

    Let me give you a tiny example out of the zoo tiny example:

    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
    
    dvar int+ nbBus40;
    dvar int+ nbBus30;
    
    minimize 
     costBus40*nbBus40  +nbBus30*costBus30;
    
    subject to
    {
     40*nbBus40+nbBus30*30>=nbKids;
    
     //  (nbBus40*0.5+nbBus30*0.7)/(nbBus30+nbBus40)<=10;  //KO
    
     (nbBus40*0.5+nbBus30*0.7)<=10*(nbBus30+nbBus40);
    
    }