5#include "OsiClpSolverInterface.hpp"
7#include "CbcSolver.hpp"
19 if (!model->status() && model->secondaryStatus()) ret = 1;
33 : obj_(
obj), time_(0), found_(false){};
38 : CbcEventHandler(other) {
41 found_ = other.
found();
48 found_ = other.
found();
49 CbcEventHandler::operator=(other);
59 if (!found_ && (e == solution || e == heuristicSolution)) {
60 const CbcModel* m = getModel();
61 double cbcobj = m->getObjValue();
63 time_ = CoinCpuTime() - m->getDblParam(CbcModel::CbcStartSeconds);
71#define CYCLUS_SOLVER_TIMEOUT 10800
79 if (t_ ==
"clp" || t_ ==
"cbc") {
80 OsiClpSolverInterface* s =
new OsiClpSolverInterface();
81 s->getModelPtr()->setMaximumSeconds(tmax_);
84 throw ValueError(
"invalid SolverFactory type '" + t_ +
"'");
89 const double* objs = si->getObjCoefficients();
90 const double* clbs = si->getColLower();
91 const double* cubs = si->getColUpper();
92 int ncol = si->getNumCols();
93 std::cout <<
"Column info\n";
94 for (
int i = 0; i != ncol; i++) {
95 std::cout << i <<
" obj" <<
": " << objs[i] <<
" lb" <<
": " << clbs[i]
96 <<
" ub" <<
": " << cubs[i] <<
" int" <<
": " << std::boolalpha
97 << si->isInteger(i) <<
'\n';
100 const CoinPackedMatrix* m = si->getMatrixByRow();
101 const double* rlbs = si->getRowLower();
102 const double* rubs = si->getRowUpper();
103 int nrow = si->getNumRows();
104 std::cout <<
"Row info\n";
105 for (
int i = 0; i != nrow; i++) {
106 std::cout << i <<
" lb" <<
": " << rlbs[i] <<
" ub" <<
": " << rubs[i]
109 std::cout <<
"matrix:\n";
113void SolveProg(OsiSolverInterface* si,
double greedy_obj,
bool verbose) {
119 model.passInEventHandler(&handler);
120 model.setLogLevel(0);
121 model.initialSolve();
122 model.branchAndBound();
123 si->setColSolution(model.bestSolution());
125 std::cout <<
"Greedy equivalent time: " << handler.
time() <<
" and obj "
126 << handler.
obj() <<
" and found " << std::boolalpha
127 << handler.
found() <<
"\n";
135 const double* soln = si->getColSolution();
136 for (
int i = 0; i != si->getNumCols(); i++) {
137 std::cout <<
"soln " << i <<
": " << soln[i]
138 <<
" integer: " << std::boolalpha << si->isInteger(i) <<
"\n";
148 SolveProg(si, si->getInfinity(), verbose);
151void SolveProg(OsiSolverInterface* si,
double greedy_obj) {
157 for (i = 0; i != si->getNumCols(); i++) {
158 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