Ejemplo n.º 1
0
ILOMIPINFOCALLBACK5(loggingCallback,
                    IloNumVarArray, vars,
                    IloNum,         lastLog, 
                    IloNum,         lastIncumbent,
                    IloNum,         startTime,
                    IloNum,         startDetTime)
{
   int newIncumbent = 0;
   int nodes = getNnodes();

   if ( hasIncumbent()                                  && 
        fabs(lastIncumbent - getIncumbentObjValue())
              > 1e-5*(1.0 + fabs(getIncumbentObjValue())) ) {
      lastIncumbent = getIncumbentObjValue();
      newIncumbent = 1;
   }
     
   if ( nodes >= lastLog + 100  ||  newIncumbent ) {  

      if ( !newIncumbent )  lastLog = nodes;
      getEnv().out() << "Time = " << getCplexTime() - startTime
                     << "  Dettime = " << getDetTime() - startDetTime
                     << "  Nodes = " << nodes
                     << '(' << getNremainingNodes() << ')'
                     << "  Best objective = " << getBestObjValue();

      if ( hasIncumbent() ) {
         getEnv().out() << "  Incumbent objective = " << getIncumbentObjValue()
                        << endl;
      }
      else {
         getEnv().out() << endl;
      }

   }
   if ( newIncumbent ) {
      IloNumArray val(vars.getEnv());
      getIncumbentValues(val, vars);
      val[0] = getIncumbentValue(vars[0]);
      getEnv().out() << "New incumbent variable values: " << endl
                     << val << endl;
      val.end();
   }
}
Ejemplo n.º 2
0
// a cplex callback to print the current best found solution
ILOMIPINFOCALLBACK3(MIPInfoCallback, bool, isMinimization, IloCplex, cplex, IloNum, startTime) {
  if (!hasIncumbent())
    return;
  static double prevBest = (isMinimization ? 1e+100 : -1e+100);
  const IloNum currentBest = getIncumbentObjValue();
  if ((isMinimization && currentBest < prevBest) || (!isMinimization && currentBest > prevBest)) {
    prevBest = currentBest;
    cout << "New incumbent found at " << (cplex.getCplexTime() - startTime) << " sec : " << currentBest << endl;
  }
}
Ejemplo n.º 3
0
ILOMIPINFOCALLBACK5(loggingCallback,
                    IloNumVarArray, vars,
                    IloNum,         lastDettime, 
                    IloNum,         lastIncumbent,
                    IloNum,         startTime,
                    IloNum,         startDetTime)
{
   int newIncumbent = 0;
   double dettime = getDetTime();

   if ( hasIncumbent()                                  && 
        fabs(lastIncumbent - getIncumbentObjValue())
              > 1e-5*(1.0 + fabs(getIncumbentObjValue())) ) {
      lastIncumbent = getIncumbentObjValue();
      newIncumbent = 1;
   }
     
   if ( dettime >= lastDettime + 1000.0  ||  newIncumbent ) {  

      if ( !newIncumbent )  lastDettime = dettime;
      getEnv().out() << "Time = " << getCplexTime() - startTime
                     << "  Dettime = " << dettime - startDetTime
                     << "  Best objective = " << getBestObjValue();

      if ( hasIncumbent() ) {
         getEnv().out() << "  Incumbent objective = " << getIncumbentObjValue()
                        << endl;
      }
      else {
         getEnv().out() << endl;
      }

   }
   if ( newIncumbent ) {
      IloNumArray val(vars.getEnv());
      getIncumbentValues(val, vars);
      val[0] = getIncumbentValue(vars[0]);
      getEnv().out() << "New incumbent variable values: " << endl
                     << val << endl;
      val.end();
   }
}
Ejemplo n.º 4
0
ILOMIPINFOCALLBACK3(BestObjectiveReachedCallback,
                    IloNum, relGap,
					IloBool, aborted,
					IloNum, bestObjective)
{
	if (!aborted  &&  hasIncumbent())
	{
		IloNum objective = getIncumbentObjValue();
		if (fabs(objective - bestObjective) <= fabs(bestObjective) * relGap)
			abort();
	}
};
Ejemplo n.º 5
0
ILOMIPINFOCALLBACK5(timeLimitCallback,
                    IloCplex, cplex,
                    IloBool,  aborted,
                    IloNum,   timeStart,
                    IloNum,   timeLimit,
                    IloNum,   acceptableGap)
{
   if ( !aborted  &&  hasIncumbent() ) {
      IloNum gap = 100.0 * getMIPRelativeGap();
      IloNum timeUsed = cplex.getCplexTime() - timeStart;
      if ( timeUsed > 1 )
         getEnv().out() << timeUsed << endl;
      if ( timeUsed > timeLimit && gap < acceptableGap ) {
         getEnv().out() << endl
                        << "Good enough solution at "
                        << timeUsed << " sec., gap = "
                        << gap << "%, quitting." << endl;
         aborted = IloTrue;
         abort();
      }
   }
}