Commit fbbccb71 authored by David Bommes's avatar David Bommes

CBC return value

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@293 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 5c449cfe
......@@ -38,6 +38,7 @@
// Heuristics
#include "CbcHeuristic.hpp"
#include "CbcCompareDepth.hpp"
#include <stdexcept>
......@@ -128,7 +129,7 @@ void model_tweak(CbcModel& model)
#define P(X) ((X).data())
void solve_impl(
bool solve_impl(
NProblemInterface* _problem,
const std::vector<NConstraintInterface*>& _constraints,
const std::vector<PairIndexVtype>& _discrete_constraints,
......@@ -249,6 +250,10 @@ void solve_impl(
// TRACE_CBT("CbcModel::getMaximumSeconds()", model.getMaximumSeconds());
model_tweak(model);
CbcCompareDepth compare_depth;
model.setNodeComparison(&compare_depth);
model.branchAndBound();
const double* solution = model.bestSolution();
......@@ -256,27 +261,34 @@ void solve_impl(
// store if solution available
if(solution != 0)
{
_problem->store_result(solution);
return true;
}
else
return false;
}
#undef P
void CBCSolver::solve(
bool CBCSolver::solve(
NProblemInterface* _problem,
const std::vector<NConstraintInterface*>& _constraints,
const std::vector<PairIndexVtype>& _discrete_constraints,
const double _time_limit
)
{
bool valid_solution = false;
try
{
solve_impl(_problem, _constraints, _discrete_constraints, _time_limit);
valid_solution = solve_impl(_problem, _constraints, _discrete_constraints, _time_limit);
}
catch (CoinError& ce)
{
std::cerr << "CoinError code = " << ce.message() << std::endl;
// THROW_OUTCOME(UNSPECIFIED_CBC_EXCEPTION);
}
return valid_solution;
}
......
......@@ -45,14 +45,14 @@ public:
// ********** SOLVE **************** //
//! \throws Outcome
void solve(
bool solve(
NProblemInterface* _problem, // problem instance
const std::vector<NConstraintInterface*>& _constraints, // linear constraints
const std::vector<PairIndexVtype>& _discrete_constraints, // discrete constraints
const double _time_limit = 60); // time limit in seconds
//! \throws Outcome
void solve(
bool solve(
NProblemInterface* _problem, // problem instance
const std::vector<NConstraintInterface*>& _constraints, // linear constraints
const double _time_limit = 60) // time limit in seconds
......@@ -60,6 +60,20 @@ public:
std::vector<PairIndexVtype> dc;
return solve(_problem, _constraints, dc, _time_limit);
}
// // same as previous but more control over stopping criteria
// // the optimizer runs in two phases
// // phase 1) stops if solution with a MIP gap lower than _gap0 is found or _time_limit0 is reached
// // phase 2) starts only if in phase 1 no solution with a MIP gap lower than _gap1 was found and
// // uses _gap1 and _time_limit2 as parameters
// inline bool solve_two_phase(NProblemInterface* _problem, // problem instance
// std::vector<NConstraintInterface*>& _constraints, // linear constraints
// std::vector<PairIndexVtype>& _discrete_constraints, // discrete constraints
// const double _time_limit0 = 60, // time limit phase 1 in seconds
// const double _gap0 = 0.001, // MIP gap phase 1
// const double _time_limit1 = 120, // time limit phase 2 in seconds
// const double _gap1 = 0.2, // MIP gap phase 2
// const bool _silent = false);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment