0

I want to retrieve the reduced cost of a decision variable in CPLEX OPL. However, the dvar indices are tuples, and cplex cannot iterate over a tuple to print the reduced costs. Is it impossible with tuples, or is there a way for it? For example there is a decision variable as below:

dvar float+ Production[ProductionLocations][TimePeriods];

tuple timeperiod {
  string TimePeriodID;
  string TimePeriodName;
  float CurrencyRate;
  float Rank;
  string ActivePeriod;
}
{timeperiod} TimePeriods = ...;
tuple productionlocation { 
  string ProductID;
  string ProductName;
  string LocationID;
  string LocationName;
}
{productionlocation} ProductionLocations = ...;

Thanks in advance.

osygl
  • 13
  • 2

2 Answers2

0

you may iterate on tuple set.

In oil.mod in OPL CPLEX examples you may see

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

Gasolines is a string set but could be a tuple set, this would work too

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • Thank you @Alex Fleischer. I tried what you suggested but received this error:Description IBM ILOG CPLEX: CPLEX Error 1017: Not available for mixed-integer problems The decision variable is a float, however the problem is MILP. Isn't it possible to retrieve the reduce costs? – osygl Feb 17 '20 at 08:30
  • Hi, that works for LP but you could relax integrity. See https://www.ibm.com/developerworks/community/forums/html/topic?id=f6bca8db-242d-445d-854c-a3c75975bc88&ps=25 – Alex Fleischer Feb 17 '20 at 10:08
0

Let me expand on Alex's answer: it seems you attempt to query dual values for a MIP. Dual values are however not defined for MIPs. You have two options here:

  1. You can relax all the variables and solve the relaxed problem. That is an LP and will thus provide duals. However, this may not be too helpful.
  2. You can compute the optimal solution to the MIP, fix all integer variables and then solve the remaining problem. This is again an LP and will thus provide dual values. These dual values may be more meaningful than the values you get from relaxing everything.

In order to do the second thing, you can still use scripting:

main {
  thisOplModel.generate();
  cplex.solve(); // Compute integer optimal solution
  cplex.solveFixed(); // Fix integer variables to optimal values, solve LP
  // query your dual values:
  for (var g in Gasolines) {
    writeln("a[",g,"].reducedCost = ",a[g].reducedCost);
  }
}
Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22