예제 #1
0
ILOCPLEXGOAL2(SemiContGoal,
              IloNumVarArray, scVars,
              IloNumArray,    scLbs) {
   IloInt besti = -1;
   IloNum maxObjCoef = -IloInfinity;
   IloInt i;

   // From among all variables that do not respect their minimum 
   // usage levels, select the one with maximum objective coefficient.

   for (i = 0; i < scVars.getSize(); i++) {
      IloNum val = getValue(scVars[i]);
      if ( val >= 1e-5           &&
           val <= scLbs[i] - 1e-5  ) {
         if ( getObjCoef(scVars[i]) >= maxObjCoef ) {
            besti = i;
            maxObjCoef = getObjCoef(scVars[i]);
         }
      }
   }

   //  If any are found, branch to enforce the condition that
   //  the variable must either be 0.0 or greater than
   //  the minimum usage level.
   if ( besti != -1 ) {
      return AndGoal ( OrGoal ( scVars[besti] <= 0.0,
                                scVars[besti] >= scLbs[besti] ),
                       this );
   }
   else if ( !isIntegerFeasible() ) {
      return AndGoal( BranchAsCplexGoal(getEnv()), this );
   }

   return 0;
}
ILOCPLEXGOAL1(MyBranchGoal, IloNumVarArray, vars) {
   IloNumArray x;
   IloNumArray obj;
   IntegerFeasibilityArray feas;

   x    = IloNumArray(getEnv());
   obj  = IloNumArray(getEnv());
   feas = IntegerFeasibilityArray(getEnv());
   getValues(x, vars);
   getObjCoefs(obj, vars);
   getFeasibilities(feas, vars);

   IloInt bestj  = -1;
   IloNum maxinf = 0.0;
   IloNum maxobj = 0.0;
   IloInt cols = vars.getSize();
   for (IloInt j = 0; j < cols; j++) {
      if ( feas[j] == Infeasible ) {
         IloNum xj_inf = x[j] - IloFloor (x[j]);
         if ( xj_inf > 0.5 )
            xj_inf = 1.0 - xj_inf;
         if ( xj_inf >= maxinf                             &&
             (xj_inf > maxinf || IloAbs (obj[j]) >= maxobj)  ) {
            bestj  = j;
            maxinf = xj_inf;
            maxobj = IloAbs (obj[j]);
         }
      }
   }

   IloCplex::Goal res;
   if ( bestj >= 0 ) {
      res = AndGoal(OrGoal(vars[bestj] >= IloFloor(x[bestj])+1,
                           vars[bestj] <= IloFloor(x[bestj])),
                    this);
   }

   x.end();
   obj.end();
   feas.end();

   return res;
}