linear-programmingcplex

Reduced Costs in IBM ILOG CPLEX Optimization Studio


In this Stack Overflow post, they give the code to find the solution duals (shadow prices).

execute { writeln(ctMaxTotal.dual); writeln(ctMaxTotal2.dual); writeln(ctMaxChloride.dual); }

What is the command to find the reduced costs of a linear programming problem?

All of the help I found assumes that I am running CPLEX inside java or inside python. However, I am running the IBM ILOG CPLEX Optimization Studio.


Solution

  • In oil.mod in OPL CPLEX examples you may see

    enter image description here

    execute DISPLAY_REDUCED_COSTS{
      for( var g in Gasolines ) {
        writeln("a[",g,"].reducedCost = ",a[g].reducedCost);
      }
    }
    

    or even a simpler example I wrote

    int nbKids=300;
    float costBus40=500;
    float costBus30=400;
     
    dvar int+ nbBus40;
    dvar int+ nbBus30;
     
    minimize
     costBus40*nbBus40  +nbBus30*costBus30;
     
    subject to
    {
     ctKids:40*nbBus40+nbBus30*30>=nbKids;
    
    }
    
    main {
      var status = 0;
      thisOplModel.generate();
      if (cplex.solve()) {
        writeln("Integer Model");   
        writeln("OBJECTIVE: ",cplex.getObjValue());   
        
      }
    
      // relax integrity constraint
      thisOplModel.convertAllIntVars();
     
      if (cplex.solve()) {
        writeln("Relaxed Model");   
        writeln("OBJECTIVE: ",cplex.getObjValue());  
        
        writeln("dual of the kids constraint = ",thisOplModel.ctKids.dual);
        writeln("reduced costs for nbbus40 : ",thisOplModel.nbBus40.reducedCost);
        writeln("reduced costs for nbbus30 : ",thisOplModel.nbBus30.reducedCost);
      }
       
     
    }