Skip to content

Commit c11c754

Browse files
Do not recreate convex bounding MIP problem every iteration
1 parent 0eb5086 commit c11c754

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

src/Tasks/TaskPerformConvexBounding.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,35 @@ TaskPerformConvexBounding::TaskPerformConvexBounding(EnvironmentPtr envPtr, bool
6666
taskSelectHPPtsByObjectiveRootsearch = std::make_shared<TaskSelectHyperplanePointsObjectiveFunction>(env);
6767
}
6868

69+
#ifdef HAS_CPLEX
70+
if(env->results->usedMIPSolver == ES_MIPSolver::Cplex)
71+
{
72+
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverCplex>(env));
73+
}
74+
#endif
75+
76+
#ifdef HAS_GUROBI
77+
if(env->results->usedMIPSolver == ES_MIPSolver::Gurobi)
78+
{
79+
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverGurobi>(env));
80+
}
81+
#endif
82+
83+
#ifdef HAS_CBC
84+
if(env->results->usedMIPSolver == ES_MIPSolver::Cbc)
85+
{
86+
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverCbc>(env));
87+
}
88+
#endif
89+
90+
assert(MIPSolver);
91+
92+
if(!MIPSolver->initializeProblem())
93+
throw Exception(" Cannot initialize selected MIP solver.");
94+
95+
taskCreateMIPProblem = std::make_shared<TaskCreateMIPProblem>(env, MIPSolver, env->reformulatedProblem);
96+
taskCreateMIPProblem->run();
97+
6998
env->timing->stopTimer("ConvexBounding");
7099
}
71100

@@ -108,48 +137,19 @@ void TaskPerformConvexBounding::run()
108137
else
109138
env->output->outputInfo(" Convex bounding started");
110139

111-
MIPSolverPtr MIPSolver;
112-
113-
#ifdef HAS_CPLEX
114-
if(env->results->usedMIPSolver == ES_MIPSolver::Cplex)
115-
{
116-
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverCplex>(env));
117-
}
118-
#endif
119-
120-
#ifdef HAS_GUROBI
121-
if(env->results->usedMIPSolver == ES_MIPSolver::Gurobi)
122-
{
123-
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverGurobi>(env));
124-
}
125-
#endif
126-
127-
#ifdef HAS_CBC
128-
if(env->results->usedMIPSolver == ES_MIPSolver::Cbc)
129-
{
130-
MIPSolver = MIPSolverPtr(std::make_shared<MIPSolverCbc>(env));
131-
}
132-
#endif
133-
134-
assert(MIPSolver);
135-
136-
if(!MIPSolver->initializeProblem())
137-
throw Exception(" Cannot initialize selected MIP solver.");
138-
139-
taskCreateMIPProblem = std::make_shared<TaskCreateMIPProblem>(env, MIPSolver, env->reformulatedProblem);
140-
taskCreateMIPProblem->run();
141-
142140
int numberHyperplanesAdded = 0;
143141

144-
for(auto HP : env->dualSolver->generatedHyperplanes)
142+
for(int i = lastAddedHyperplane; i < env->dualSolver->generatedHyperplanes.size(); ++i)
145143
{
146-
if(HP.isSourceConvex)
144+
if(env->dualSolver->generatedHyperplanes[i].isSourceConvex)
147145
{
148-
if(MIPSolver->createHyperplane((Hyperplane)HP))
146+
if(MIPSolver->createHyperplane((Hyperplane)env->dualSolver->generatedHyperplanes[i]))
149147
numberHyperplanesAdded++;
150148
}
151149
}
152150

151+
int lastAddedHyperplane = env->dualSolver->generatedHyperplanes.size();
152+
153153
double currDual = env->results->getGlobalDualBound();
154154

155155
int iterationNumber = env->results->getCurrentIteration()->iterationNumber;
@@ -302,15 +302,15 @@ void TaskPerformConvexBounding::run()
302302
{
303303
env->output->outputInfo(fmt::format("x Convex bounding finished with new global dual bound {}. Old bound "
304304
"was {}. Absolute improvement: {}",
305-
env->results->getGlobalDualBound(), currDual, std::abs(currDual - env->results->getGlobalDualBound())));
305+
objectiveBound, currDual, std::abs(currDual - env->results->getGlobalDualBound())));
306306

307307
env->solutionStatistics.numberOfDualImprovementsAfterConvexBounding++;
308308
}
309309
else
310310
{
311311
env->output->outputInfo(
312312
fmt::format(" Convex bounding finished with dual bound {}. No improvement over old bound {}",
313-
currDual, env->results->getGlobalDualBound()));
313+
objectiveBound, env->results->getGlobalDualBound()));
314314
}
315315

316316
lastNumberOfHyperplanesWithConvexSource = env->solutionStatistics.numberOfHyperplanesWithConvexSource;

src/Tasks/TaskPerformConvexBounding.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ class TaskPerformConvexBounding : public TaskBase
3939
int lastNumberOfHyperplanesWithNonconvexSource = 0;
4040
int idleIterations = 0;
4141
bool ignoreIdleIterations = false;
42+
int lastAddedHyperplane = 0;
4243

4344
std::shared_ptr<TaskBase> taskSelectHPPts;
4445
std::shared_ptr<TaskSelectHyperplanePointsObjectiveFunction> taskSelectHPPtsByObjectiveRootsearch;
4546
std::shared_ptr<TaskUpdateInteriorPoint> tUpdateInteriorPoint;
47+
48+
MIPSolverPtr MIPSolver;
4649
};
4750
} // namespace SHOT

0 commit comments

Comments
 (0)