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