Skip to content

Commit

Permalink
Merge pull request #74 from Echtzeitsysteme/hotfix/tolerance-adaptions
Browse files Browse the repository at this point in the history
Extends ILP solver tolerance setups + adjusts transformation epsilon
  • Loading branch information
maxkratz committed Nov 24, 2022
2 parents a20f71b + 5b28fa3 commit 5b08180
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.emoflon.gips.intermediate.GipsIntermediate.VariableType;

public final class GipsConstraintUtils {
final public static double EPSILON = 0.00001d;
final public static double EPSILON = 0.0001d;
final public static double INF = 10_000;

static protected VariableTuple insertSlackVariables(final GipsTransformationData data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import ilog.concert.IloNumVar;
import ilog.concert.IloObjective;
import ilog.cplex.IloCplex;
import ilog.cplex.IloCplex.Status;

public class CplexSolver extends ILPSolver {

Expand Down Expand Up @@ -59,7 +60,12 @@ public CplexSolver(final GipsEngine engine, final ILPSolverConfig config) {
cplex.setParam(IloCplex.Param.RandomSeed, config.randomSeed());
}
cplex.setParam(IloCplex.Param.Preprocessing.Presolve, config.enablePresolve());
// TODO: Tolerance
// TODO: Check specific tolerances later on
if (config.enableTolerance()) {
cplex.setParam(IloCplex.Param.MIP.Tolerances.Integrality, config.tolerance());
cplex.setParam(IloCplex.Param.MIP.Tolerances.AbsMIPGap, config.tolerance());
}

if (!config.enableOutput()) {
cplex.setOut(null);
}
Expand Down Expand Up @@ -87,16 +93,19 @@ public ILPSolverOutput solve() {

// Determine status
ILPSolverStatus status = null;
if (cplex.getStatus() == IloCplex.Status.Unbounded) {
final Status cplexStatus = cplex.getStatus();
if (cplexStatus == IloCplex.Status.Unbounded) {
status = ILPSolverStatus.UNBOUNDED;
} else if (cplex.getStatus() == IloCplex.Status.InfeasibleOrUnbounded) {
} else if (cplexStatus == IloCplex.Status.InfeasibleOrUnbounded) {
status = ILPSolverStatus.INF_OR_UNBD;
} else if (cplex.getStatus() == IloCplex.Status.Infeasible) {
} else if (cplexStatus == IloCplex.Status.Infeasible) {
status = ILPSolverStatus.INFEASIBLE;
} else if (cplex.getStatus() == IloCplex.Status.Optimal) {
} else if (cplexStatus == IloCplex.Status.Optimal) {
status = ILPSolverStatus.OPTIMAL;
} else if (cplex.getStatus() == IloCplex.Status.Unknown) {
} else if (cplexStatus == IloCplex.Status.Unknown) {
status = ILPSolverStatus.TIME_OUT;
} else if (cplexStatus == IloCplex.Status.Feasible) {
status = ILPSolverStatus.FEASIBLE;
} else {
throw new RuntimeException("Unknown solver status.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ public GlpkSolver(final GipsEngine engine, final ILPSolverConfig config) {
if (config.timeLimitEnabled()) {
iocp.setTm_lim((int) config.timeLimit() * 1000); // seconds to milliseconds
}
// TODO: Check specific tolerances later on
if (config.enableTolerance()) {
iocp.setTol_obj(config.tolerance());
iocp.setTol_int(config.tolerance());
iocp.setMip_gap(config.tolerance());
}
// Random seed not supported by the GLPK Java interface
// TODO: Set output flag
Expand All @@ -95,8 +98,6 @@ public ILPSolverOutput solve() {
setUpCnstrs();
setUpObj();

// GLPK.glp_write_lp(model, null, "glpk.lp");

// Solving
final int ret = GLPK.glp_intopt(model, iocp);
final int modelStatus = GLPK.glp_get_status(model);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public GurobiSolver(final GipsEngine engine, final ILPSolverConfig config) throw
if (!config.enableOutput()) {
env.set(IntParam.OutputFlag, 0);
}
// TODO: Check specific tolerances later on
if (config.enableTolerance()) {
env.set(DoubleParam.OptimalityTol, config.tolerance());
env.set(DoubleParam.IntFeasTol, config.tolerance());
}
if (config.timeLimitEnabled()) {
env.set(DoubleParam.TimeLimit, config.timeLimit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public enum ILPSolverStatus {
UNBOUNDED("Unbounded"), INF_OR_UNBD("Infeasible or Unbounded"), INFEASIBLE("Infeasible"),
OPTIMAL("Solved and Optimal"), TIME_OUT("Time out");
OPTIMAL("Solved and Optimal"), TIME_OUT("Time out"), FEASIBLE("Feasible");

public final String name;

Expand Down

0 comments on commit 5b08180

Please sign in to comment.