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 #include "platform.h"
4 #if CYCLUS_HAS_COIN
5 
6 #include <string>
7 
8 #include "CbcEventHandler.hpp"
9 
10 class OsiSolverInterface;
11 
12 namespace cyclus {
13 
14 /// this is taken exactly from driver4.cpp in the Cbc examples
15 static int CbcCallBack(CbcModel * model, int from);
16 
17 /// An event handler that records the time that a better solution is found
18 class ObjValueHandler: public CbcEventHandler {
19  public:
20  ObjValueHandler(double obj, double time, bool found);
21  explicit ObjValueHandler(double obj);
22  virtual ~ObjValueHandler();
23  ObjValueHandler(const ObjValueHandler& other);
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
46  SolverFactory();
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 
63 void SolveProg(OsiSolverInterface* si);
64 void SolveProg(OsiSolverInterface* si, bool verbose);
65 void SolveProg(OsiSolverInterface* si, double greedy_obj);
66 void SolveProg(OsiSolverInterface* si, double greedy_obj, bool verbose);
67 bool HasInt(OsiSolverInterface* si);
68 
69 } // namespace cyclus
70 
71 #endif // CYCLUS_HAS_COIN
72 #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
const std::string solver_t() 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
void SolveProg(OsiSolverInterface *si, double greedy_obj, bool verbose)
A factory class that, given a configuration, returns a Coin::OsiSolverInterface for a solver...