CYCLUS
Loading...
Searching...
No Matches
solver_factory.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_SOLVER_FACTORY_H_
2#define CYCLUS_SRC_SOLVER_FACTORY_H_
3#include "platform.h"
4#if CYCLUS_HAS_COIN
5
6#include <string>
7
8#include "CbcEventHandler.hpp"
9
10class OsiSolverInterface;
11
12namespace cyclus {
13
14/// this is taken exactly from driver4.cpp in the Cbc examples
15static int CbcCallBack(CbcModel * model, int from);
16
17/// An event handler that records the time that a better solution is found
18class ObjValueHandler: public CbcEventHandler {
19 public:
20 ObjValueHandler(double obj, double time, bool found);
21 explicit ObjValueHandler(double obj);
22 virtual ~ObjValueHandler();
25 virtual CbcEventHandler* clone();
26 virtual CbcEventHandler::CbcAction event(CbcEvent e);
27 inline double time() const { return time_; }
28 inline double obj() const { return obj_; }
29 inline bool found() const { return found_; }
30
31 private:
32 double obj_, time_;
33 bool found_;
34};
35
36/// A factory class that, given a configuration, returns a
37/// Coin::OsiSolverInterface for a solver.
38///
39/// @warning it is the caller's responsibility to manage the member of the
40/// interface
42 public:
43 /// currently supported solver types are 'clp' and 'cbc'
44 /// @param t the solver type
45 /// @param tmax the maximum solution time
47 explicit SolverFactory(std::string t);
48 SolverFactory(std::string t, double tmax);
49
50 /// get/set the solver type
51 inline void solver_t(std::string t) { t_ = t; }
52 inline const std::string solver_t() const { return t_; }
53 inline std::string solver_t() { return t_; }
54
55 /// get the configured solver
56 OsiSolverInterface* get();
57
58 private:
59 std::string t_;
60 double tmax_;
61};
62
63void SolveProg(OsiSolverInterface* si);
64void SolveProg(OsiSolverInterface* si, bool verbose);
65void SolveProg(OsiSolverInterface* si, double greedy_obj);
66void SolveProg(OsiSolverInterface* si, double greedy_obj, bool verbose);
67bool HasInt(OsiSolverInterface* si);
68
69} // namespace cyclus
70
71#endif // CYCLUS_HAS_COIN
72#endif // CYCLUS_SRC_SOLVER_FACTORY_H_
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()
A factory class that, given a configuration, returns a Coin::OsiSolverInterface for a solver.
OsiSolverInterface * get()
get the configured solver
const std::string solver_t() const
SolverFactory()
currently supported solver types are 'clp' and 'cbc'
void solver_t(std::string t)
get/set the solver type
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters