Commit 9865aa75 authored by Marcel Campen's avatar Marcel Campen

return final gap from Gurobi

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@296 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 99396cd6
...@@ -217,7 +217,6 @@ solve(NProblemInterface* _problem, ...@@ -217,7 +217,6 @@ solve(NProblemInterface* _problem,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool bool
GUROBISolver:: GUROBISolver::
solve_two_phase(NProblemInterface* _problem, // problem instance solve_two_phase(NProblemInterface* _problem, // problem instance
...@@ -227,6 +226,22 @@ solve_two_phase(NProblemInterface* _problem, // ...@@ -227,6 +226,22 @@ solve_two_phase(NProblemInterface* _problem, //
const double _gap0, // MIP gap phase 1 const double _gap0, // MIP gap phase 1
const double _time_limit1, // time limit phase 2 in seconds const double _time_limit1, // time limit phase 2 in seconds
const double _gap1) // MIP gap phase 2 const double _gap1) // MIP gap phase 2
{
double dummy;
return solve_two_phase(_problem, _constraints, _discrete_constraints, _time_limit0, _gap0, _time_limit1, _gap1, dummy);
}
bool
GUROBISolver::
solve_two_phase(NProblemInterface* _problem, // problem instance
std::vector<NConstraintInterface*>& _constraints, // linear constraints
std::vector<PairIndexVtype>& _discrete_constraints, // discrete constraints
const double _time_limit0, // time limit phase 1 in seconds
const double _gap0, // MIP gap phase 1
const double _time_limit1, // time limit phase 2 in seconds
const double _gap1, // MIP gap phase 2
double& _final_gap) //return final gap
{ {
try try
{ {
...@@ -352,13 +367,15 @@ solve_two_phase(NProblemInterface* _problem, // ...@@ -352,13 +367,15 @@ solve_two_phase(NProblemInterface* _problem, //
model.getEnv().set(GRB_DoubleParam_TimeLimit, _time_limit0); model.getEnv().set(GRB_DoubleParam_TimeLimit, _time_limit0);
model.getEnv().set(GRB_DoubleParam_MIPGap, _gap0); model.getEnv().set(GRB_DoubleParam_MIPGap, _gap0);
model.optimize(); model.optimize();
_final_gap = model.get(GRB_DoubleAttr_MIPGap);
// jump into phase 2? // jump into phase 2?
if(model.get(GRB_DoubleAttr_MIPGap) > _gap1) if(model.get(GRB_DoubleAttr_MIPGap) > _gap1 && _time_limit1 > 0)
{ {
model.getEnv().set(GRB_DoubleParam_TimeLimit, _time_limit1); model.getEnv().set(GRB_DoubleParam_TimeLimit, _time_limit1);
model.getEnv().set(GRB_DoubleParam_MIPGap, _gap1); model.getEnv().set(GRB_DoubleParam_MIPGap, _gap1);
model.optimize(); model.optimize();
_final_gap = model.get(GRB_DoubleAttr_MIPGap);
} }
} }
else else
......
...@@ -77,6 +77,15 @@ public: ...@@ -77,6 +77,15 @@ public:
const double _time_limit1 = 120, // time limit phase 2 in seconds const double _time_limit1 = 120, // time limit phase 2 in seconds
const double _gap1 = 0.2 ); // MIP gap phase 2 const double _gap1 = 0.2 ); // MIP gap phase 2
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, // time limit phase 1 in seconds
const double _gap0 , // MIP gap phase 1
const double _time_limit1, // time limit phase 2 in seconds
const double _gap1, // MIP gap phase 2
double& _final_gap); //return final gap
// optimization with additional lazy constraints that are only added iteratively to the problem if not satisfied // optimization with additional lazy constraints that are only added iteratively to the problem if not satisfied
bool solve(NProblemInterface* _problem, bool solve(NProblemInterface* _problem,
......
...@@ -191,6 +191,7 @@ solve(NProblemInterface* _problem, ...@@ -191,6 +191,7 @@ solve(NProblemInterface* _problem,
while(!feasible_point_found && cur_pass <(_max_passes-1)) while(!feasible_point_found && cur_pass <(_max_passes-1))
{ {
++cur_pass; ++cur_pass;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// 1. Create an instance of current IPOPT NLP // 1. Create an instance of current IPOPT NLP
...@@ -237,9 +238,7 @@ solve(NProblemInterface* _problem, ...@@ -237,9 +238,7 @@ solve(NProblemInterface* _problem,
if(!lazy_added[i]) if(!lazy_added[i])
{ {
NConstraintInterface* lc = _lazy_constraints[i]; NConstraintInterface* lc = _lazy_constraints[i];
double v = lc->eval_constraint(&(np2->solution()[0])); double v = lc->eval_constraint(&(np2->solution()[0]));
bool inf = false; bool inf = false;
bool almost_inf = false; bool almost_inf = 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