5#include "OsiClpSolverInterface.hpp"
7#include "CbcSolver.hpp"
19 if (!model->status() && model->secondaryStatus())
45 found_ = other.
found();
52 found_ = other.
found();
53 CbcEventHandler::operator=(other);
63 if (!found_ && (e == solution || e == heuristicSolution)) {
64 const CbcModel* m = getModel();
65 double cbcobj = m->getObjValue();
67 time_ = CoinCpuTime() -
68 m->getDblParam(CbcModel::CbcStartSeconds);
76#define CYCLUS_SOLVER_TIMEOUT 10800
85 if (t_ ==
"clp" || t_ ==
"cbc") {
86 OsiClpSolverInterface* s =
new OsiClpSolverInterface();
87 s->getModelPtr()->setMaximumSeconds(tmax_);
90 throw ValueError(
"invalid SolverFactory type '" + t_ +
"'");
95 const double* objs = si->getObjCoefficients();
96 const double* clbs = si->getColLower();
97 const double* cubs = si->getColUpper();
98 int ncol = si->getNumCols();
99 std::cout <<
"Column info\n";
100 for (
int i = 0; i != ncol; i ++) {
102 <<
" obj" <<
": " << objs[i]
103 <<
" lb" <<
": " << clbs[i]
104 <<
" ub" <<
": " << cubs[i]
105 <<
" int" <<
": " << std::boolalpha << si->isInteger(i) <<
'\n';
108 const CoinPackedMatrix* m = si->getMatrixByRow();
109 const double* rlbs = si->getRowLower();
110 const double* rubs = si->getRowUpper();
111 int nrow = si->getNumRows();
112 std::cout <<
"Row info\n";
113 for (
int i = 0; i != nrow; i ++) {
115 <<
" lb" <<
": " << rlbs[i]
116 <<
" ub" <<
": " << rubs[i] <<
'\n';
118 std::cout <<
"matrix:\n";
122void SolveProg(OsiSolverInterface* si,
double greedy_obj,
bool verbose) {
129 model.passInEventHandler(&handler);
130 model.setLogLevel(0);
131 model.initialSolve();
132 model.branchAndBound();
133 si->setColSolution(model.bestSolution());
135 std::cout <<
"Greedy equivalent time: " << handler.
time()
136 <<
" and obj " << handler.
obj()
137 <<
" and found " << std::boolalpha << handler.
found() <<
"\n";
145 const double* soln = si->getColSolution();
146 for (
int i = 0; i != si->getNumCols(); i ++) {
147 std::cout <<
"soln " << i <<
": " << soln[i]
148 <<
" integer: " << std::boolalpha << si->isInteger(i) <<
"\n";
158 SolveProg(si, si->getInfinity(), verbose);
161void SolveProg(OsiSolverInterface* si,
double greedy_obj) {
167 for (i = 0; i != si->getNumCols(); i++) {
168 if (si->isInteger(i)) {
An event handler that records the time that a better solution is found.
virtual CbcEventHandler::CbcAction event(CbcEvent e)
ObjValueHandler & operator=(const ObjValueHandler &other)
ObjValueHandler(double obj, double time, bool found)
virtual CbcEventHandler * clone()
virtual ~ObjValueHandler()
OsiSolverInterface * get()
get the configured solver
SolverFactory()
currently supported solver types are 'clp' and 'cbc'
For values that are too big, too small, etc.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
void ReportProg(OsiSolverInterface *si)
void SolveProg(OsiSolverInterface *si, double greedy_obj, bool verbose)
bool HasInt(OsiSolverInterface *si)
int CbcCallBack(CbcModel *model, int from)
this is taken exactly from driver4.cpp in the Cbc examples
#define CYCLUS_SOLVER_TIMEOUT