| 1 |
// (C) Copyright International Business Machines (IBM) 2006 |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// P. Bonami, International Business Machines |
| 7 |
// |
| 8 |
// Date : 12/07/2006 |
| 9 |
|
| 10 |
|
| 11 |
// Code separated from BonOaDecBase to try to clarify OAs |
| 12 |
#ifndef BonSubMipSolver_HPP |
| 13 |
#define BonSubMipSolver_HPP |
| 14 |
#include "IpSmartPtr.hpp" |
| 15 |
#include <string> |
| 16 |
/* forward declarations.*/ |
| 17 |
class OsiSolverInterface; |
| 18 |
class OsiClpSolverInterface; |
| 19 |
class OsiCpxSolverInterface; |
| 20 |
class CbcStrategy; |
| 21 |
class CbcStrategyDefault; |
| 22 |
|
| 23 |
#include "OsiCuts.hpp" |
| 24 |
|
| 25 |
namespace Bonmin { |
| 26 |
class RegisteredOptions; |
| 27 |
class BabSetupBase; |
| 28 |
/** A very simple class to provide a common interface for solving MIPs with Cplex and Cbc.*/ |
| 29 |
class SubMipSolver |
| 30 |
{ |
| 31 |
public: |
| 32 |
enum MILP_solve_strategy{ |
| 33 |
FindGoodSolution, |
| 34 |
GetOptimum}; |
| 35 |
/** Constructor */ |
| 36 |
SubMipSolver(BabSetupBase &b, const std::string &prefix); |
| 37 |
|
| 38 |
/** Copy Constructor */ |
| 39 |
SubMipSolver(const SubMipSolver ©); |
| 40 |
|
| 41 |
~SubMipSolver(); |
| 42 |
|
| 43 |
/** Assign lp solver. */ |
| 44 |
void setLpSolver(OsiSolverInterface * lp); |
| 45 |
|
| 46 |
/** Assign a strategy. */ |
| 47 |
void setStrategy(CbcStrategyDefault * strategy); |
| 48 |
|
| 49 |
/** get the solution found in last local search (return NULL if no solution). */ |
| 50 |
const double * getLastSolution() |
| 51 |
{ |
| 52 |
return integerSolution_; |
| 53 |
} |
| 54 |
|
| 55 |
double getLowerBound() |
| 56 |
{ |
| 57 |
return lowBound_; |
| 58 |
} |
| 59 |
|
| 60 |
void solve(double cutoff, |
| 61 |
int loglevel, |
| 62 |
double maxTime){ |
| 63 |
if(milp_strat_ == FindGoodSolution){ |
| 64 |
find_good_sol(cutoff, loglevel, maxTime); |
| 65 |
} |
| 66 |
else |
| 67 |
optimize(cutoff, loglevel, maxTime); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
/** update cutoff and perform a local search to a good solution. */ |
| 72 |
void find_good_sol(double cutoff, |
| 73 |
int loglevel, |
| 74 |
double maxTime); |
| 75 |
|
| 76 |
/** update cutoff and optimize MIP. */ |
| 77 |
void optimize(double cutoff, |
| 78 |
int loglevel, |
| 79 |
double maxTime); |
| 80 |
|
| 81 |
/** update cutoff, put OA constraints in cs as lazy constraints and optimize MIP. */ |
| 82 |
void optimize_with_lazy_constraints(double cutoff, |
| 83 |
int loglevel, |
| 84 |
double maxTime, const OsiCuts & cs); |
| 85 |
|
| 86 |
/** Returns lower bound. */ |
| 87 |
inline double lowBound() |
| 88 |
{ |
| 89 |
return lowBound_; |
| 90 |
} |
| 91 |
|
| 92 |
/** returns optimality status. */ |
| 93 |
inline bool optimal() |
| 94 |
{ |
| 95 |
return optimal_; |
| 96 |
} |
| 97 |
|
| 98 |
/** Returns number of nodes in last solve.*/ |
| 99 |
inline int nodeCount() |
| 100 |
{ |
| 101 |
return nodeCount_; |
| 102 |
} |
| 103 |
|
| 104 |
/** Returns number of simplex iterations in last solve.*/ |
| 105 |
inline int iterationCount() |
| 106 |
{ |
| 107 |
return iterationCount_; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
OsiSolverInterface * solver(); |
| 112 |
|
| 113 |
/** Register options for that Oa based cut generation method. */ |
| 114 |
static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions); |
| 115 |
private: |
| 116 |
/** If lp solver is clp (then have to use Cbc) (not owned).*/ |
| 117 |
OsiClpSolverInterface *clp_; |
| 118 |
/** If mip solver is cpx this is it (owned). */ |
| 119 |
OsiCpxSolverInterface * cpx_; |
| 120 |
/** lower bound obtained */ |
| 121 |
double lowBound_; |
| 122 |
/** Is optimality proven? */ |
| 123 |
bool optimal_; |
| 124 |
/** Has an integer solution? then it is here*/ |
| 125 |
double * integerSolution_; |
| 126 |
/** Strategy for solving sub mips with cbc. */ |
| 127 |
CbcStrategyDefault * strategy_; |
| 128 |
/** number of nodes in last mip solved.*/ |
| 129 |
int nodeCount_; |
| 130 |
/** number of simplex iteration in last mip solved.*/ |
| 131 |
int iterationCount_; |
| 132 |
/** MILP search strategy.*/ |
| 133 |
MILP_solve_strategy milp_strat_; |
| 134 |
/** setting for gap tolerance.*/ |
| 135 |
double gap_tol_; |
| 136 |
/** say if owns copy of clp_.*/ |
| 137 |
bool ownClp_; |
| 138 |
}; |
| 139 |
|
| 140 |
} |
| 141 |
|
| 142 |
#endif |
| 143 |
|