简体   繁体   中英

LP relaxation in CPLEX

Can I get a relaxed value when I write the following code under my model? I do not have any decision variable results when I do it. Do I need to change anything?

main {
  var status = 0;
  thisOplModel.generate();
  if (cplex.solve()) {
    writeln("Integer Model");   
    writeln("OBJECTIVE: ",cplex.getObjValue());   
    if (cplex.getObjValue() != 1) {
      status = -1;
    }
  } 

  thisOplModel.convertAllIntVars();
  if (cplex.solve()) {
    writeln("Relaxed Model");   
    writeln("OBJECTIVE: ",cplex.getObjValue());  
    if (cplex.getObjValue() != 0.5) {
      status = -1;
    }
  } 
   
(status);
}

sure.

Full example from Relax integrity constraints and dual value in Making Optimization Simple

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);
  }
   
 
}

which gives

Integer Model
OBJECTIVE: 3800
Relaxed Model
OBJECTIVE: 3750
dual of the kids constraint = 12.5

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