public override Cplex.Goal Execute(Cplex cplex) { if (IsIntegerFeasible()) { return(null); } int num = cut.Length; Cplex.Goal goal = this; for (int i = 0; i < num; ++i) { IRange thecut = cut[i]; if (thecut != null) { double val = GetValue(thecut.Expr); if (thecut.LB > val + eps || val - eps > thecut.UB) { goal = cplex.And(cplex.GlobalCutGoal(thecut), goal); cut[i] = null; } } } if (goal == this) { goal = cplex.And(cplex.BranchAsCplex(), goal); } return(goal); }
// Branch on var with largest objective coefficient // among those with largest infeasibility public override Cplex.Goal Execute(Cplex cplex) { double[] x = GetValues (_vars); double[] obj = GetObjCoefs(_vars); Cplex.IntegerFeasibilityStatus[] feas = GetFeasibilities(_vars); double maxinf = 0.0; double maxobj = 0.0; int bestj = -1; int cols = _vars.Length; for (int j = 0; j < cols; ++j) { if ( feas[j].Equals(Cplex.IntegerFeasibilityStatus.Infeasible) ) { double xj_inf = x[j] - System.Math.Floor(x[j]); if ( xj_inf > 0.5 ) xj_inf = 1.0 - xj_inf; if ( xj_inf >= maxinf && (xj_inf > maxinf || System.Math.Abs(obj[j]) >= maxobj) ) { bestj = j; maxinf = xj_inf; maxobj = System.Math.Abs(obj[j]); } } } if ( bestj >= 0 ) { return cplex.And( cplex.Or(cplex.GeGoal(_vars[bestj], System.Math.Floor(x[bestj])+1), cplex.LeGoal(_vars[bestj], System.Math.Floor(x[bestj]))), this); } else return null; }
public override Cplex.Goal Execute(Cplex cplex) { if ( IsIntegerFeasible() ) return null; int num = cut.Length; Cplex.Goal goal = this; for (int i = 0; i < num; ++i) { IRange thecut = cut[i]; if ( thecut != null ) { double val = GetValue(thecut.Expr); if ( thecut.LB > val+eps || val-eps > thecut.UB ) { goal = cplex.And(cplex.GlobalCutGoal(thecut), goal); cut[i] = null; } } } if ( goal == this ) goal = cplex.And(cplex.BranchAsCplex(), goal); return goal; }
public override Cplex.Goal Execute(Cplex cplex) { int besti = -1; double maxObjCoef = System.Double.MinValue; // From among all variables that do not respect their minimum // usage levels, select the one with maximum objective coefficient. for (int i = 0; i < _scVars.Length; i++) { double 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(cplex.And(cplex.Or(cplex.LeGoal(_scVars[besti], 0.0), cplex.GeGoal(_scVars[besti], _scLbs[besti])), this)); } else if (!IsIntegerFeasible()) { return(cplex.And(cplex.BranchAsCplex(), this)); } return(null); }
// Branch on var with largest objective coefficient // among those with largest infeasibility public override Cplex.Goal Execute(Cplex cplex) { double[] x = GetValues(_vars); double[] obj = GetObjCoefs(_vars); Cplex.IntegerFeasibilityStatus[] feas = GetFeasibilities(_vars); double maxinf = 0.0; double maxobj = 0.0; int bestj = -1; int cols = _vars.Length; for (int j = 0; j < cols; ++j) { if (feas[j].Equals(Cplex.IntegerFeasibilityStatus.Infeasible)) { double xj_inf = x[j] - System.Math.Floor(x[j]); if (xj_inf > 0.5) { xj_inf = 1.0 - xj_inf; } if (xj_inf >= maxinf && (xj_inf > maxinf || System.Math.Abs(obj[j]) >= maxobj)) { bestj = j; maxinf = xj_inf; maxobj = System.Math.Abs(obj[j]); } } } if (bestj >= 0) { return(cplex.And( cplex.Or(cplex.GeGoal(_vars[bestj], System.Math.Floor(x[bestj]) + 1), cplex.LeGoal(_vars[bestj], System.Math.Floor(x[bestj]))), this)); } else { return(null); } }
private IConstraint addConfigurationPartToConstraint(IConstraint previous, List <INumVar> toAdd, Cplex plex) { foreach (INumVar var in toAdd) { if (previous == null) { previous = plex.Eq(1, var); } else { previous = plex.And(previous, plex.Eq(1, var)); } } if (previous != null) { previous = plex.Not(previous); } return(previous); }
public override Cplex.Goal Execute(Cplex cplex) { int besti = -1; double maxObjCoef = System.Double.MinValue; // From among all variables that do not respect their minimum // usage levels, select the one with maximum objective coefficient. for (int i = 0; i < _scVars.Length; i++) { double 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 cplex.And(cplex.Or(cplex.LeGoal(_scVars[besti], 0.0), cplex.GeGoal(_scVars[besti], _scLbs[besti])), this ); } else if ( !IsIntegerFeasible() ) { return cplex.And(cplex.BranchAsCplex(), this ); } return null; }