diff --git a/schedulers/tetrisched/include/tetrisched/GurobiSolver.hpp b/schedulers/tetrisched/include/tetrisched/GurobiSolver.hpp index c3b1b8a2..2754b8e7 100644 --- a/schedulers/tetrisched/include/tetrisched/GurobiSolver.hpp +++ b/schedulers/tetrisched/include/tetrisched/GurobiSolver.hpp @@ -17,6 +17,9 @@ class GurobiSolver : public Solver { /// variables. std::unordered_map gurobiVariables; + /// Set the defaults for parameters on the model. + void setDefaultParameters(GRBModel& gurobiModel); + /// Translate the variable to a Gurobi variable. GRBVar translateVariable(GRBModel& gurobiModel, const VariablePtr& variable) const; @@ -25,7 +28,7 @@ class GurobiSolver : public Solver { GRBConstr translateConstraint(GRBModel& gurobiModel, const ConstraintPtr& constraint) const; - /// Translate teh ObjectiveFunction into a Gurobi expression. + /// Translate the ObjectiveFunction into a Gurobi expression. GRBLinExpr translateObjectiveFunction( GRBModel& gurobiModel, const ObjectiveFunctionPtr& objectiveFunction) const; diff --git a/schedulers/tetrisched/src/GurobiSolver.cpp b/schedulers/tetrisched/src/GurobiSolver.cpp index 9d92a400..2962a550 100644 --- a/schedulers/tetrisched/src/GurobiSolver.cpp +++ b/schedulers/tetrisched/src/GurobiSolver.cpp @@ -1,10 +1,13 @@ #include "tetrisched/GurobiSolver.hpp" #include +#include namespace tetrisched { GurobiSolver::GurobiSolver() - : gurobiEnv(new GRBEnv()), gurobiModel(new GRBModel(*gurobiEnv)) {} + : gurobiEnv(new GRBEnv()), gurobiModel(new GRBModel(*gurobiEnv)) { + setDefaultParameters(*gurobiModel); +} SolverModelPtr GurobiSolver::getModel() { if (!solverModel) { @@ -17,6 +20,18 @@ void GurobiSolver::setModel(SolverModelPtr solverModelPtr) { solverModel = solverModelPtr; } +void GurobiSolver::setDefaultParameters(GRBModel& gurobiModel) { + // Set the maximum numer of threads. + const auto thread_count = std::thread::hardware_concurrency(); + gurobiModel.set(GRB_IntParam_Threads, thread_count); + + // Ask Gurobi to aggressively cut the search space. + gurobiModel.set(GRB_IntParam_Cuts, 3); + + // Ask Gurobi to find new incumbent solutions rather than prove bounds. + gurobiModel.set(GRB_IntParam_MIPFocus, 1); +} + GRBVar GurobiSolver::translateVariable(GRBModel& gurobiModel, const VariablePtr& variable) const { // Note (Sukrit): Do not use value_or here since the type coercion renders @@ -129,6 +144,7 @@ void GurobiSolver::translateModel() { } gurobiModel = std::make_unique(*gurobiEnv); + setDefaultParameters(*gurobiModel); // Generate all the variables and keep a cache of the variable indices // to the Gurobi variables.