CYCLUS
exchange_solver.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_EXCHANGE_SOLVER_H_
2 #define CYCLUS_SRC_EXCHANGE_SOLVER_H_
3 
4 #include <cstddef>
5 
6 namespace cyclus {
7 
8 class Context;
9 class ExchangeGraph;
10 class Arc;
11 
12 /// @class ExchangeSolver
13 ///
14 /// @brief a very simple interface for solving translated resource exchanges
16  public:
17  /// default value to allow exclusive orders or not
18  static const bool kDefaultExclusive = true;
19 
20  /// return the cost of an arc
21  static double Cost(const Arc& a, bool exclusive_orders = kDefaultExclusive);
22 
23  explicit ExchangeSolver(bool exclusive_orders = kDefaultExclusive)
24  : exclusive_orders_(exclusive_orders),
25  sim_ctx_(NULL),
26  verbose_(false) {}
27  virtual ~ExchangeSolver() {}
28 
29  /// simulation context get/set
30  /// @{
31  inline void sim_ctx(Context* c) { sim_ctx_ = c; }
32  inline Context* sim_ctx() { return sim_ctx_; }
33  /// @}
34 
35  /// tell the solver to be verbose
36  inline void verbose() { verbose_ = true; }
37  inline void graph(ExchangeGraph* graph) { graph_ = graph; }
38  inline ExchangeGraph* graph() const { return graph_; }
39 
40  /// @brief interface for solving a given exchange graph
41  /// @param a pointer to the graph to be solved
42  double Solve(ExchangeGraph* graph = NULL) {
43  if (graph != NULL)
44  graph_ = graph;
45  return this->SolveGraph();
46  }
47 
48  /// @brief Calculates the ratio of the maximum objective coefficient to
49  /// minimum unit capacity plus an added cost. This is guaranteed to be larger
50  /// than any other arc cost measure and can be used as a cost for unmet
51  /// demand.
52  /// @param cost_factor the additional cost for false arc costs, i.e., max_cost
53  /// * (1 + cost_factor)
54  /// @{
55  double PseudoCost();
56  double PseudoCost(double cost_factor);
57  double PseudoCostByCap(double cost_factor);
58  double PseudoCostByPref(double cost_factor);
59  /// @}
60 
61  /// return the cost of an arc
62  inline double ArcCost(const Arc& a) { return Cost(a, exclusive_orders_); }
63 
64  protected:
65  /// @brief Worker function for solving a graph. This must be implemented by
66  /// any solver.
67  virtual double SolveGraph() = 0;
70  bool verbose_;
72 };
73 
74 } // namespace cyclus
75 
76 #endif // CYCLUS_SRC_EXCHANGE_SOLVER_H_
double PseudoCostByCap(double cost_factor)
An arc represents a possible connection between two nodes in the bipartite resource exchange graph...
void graph(ExchangeGraph *graph)
void verbose()
tell the solver to be verbose
static const bool kDefaultExclusive
default value to allow exclusive orders or not
virtual double SolveGraph()=0
Worker function for solving a graph.
ExchangeGraph * graph() const
double ArcCost(const Arc &a)
return the cost of an arc
double Solve(ExchangeGraph *graph=NULL)
interface for solving a given exchange graph
void sim_ctx(Context *c)
simulation context get/set
ExchangeGraph * graph_
double PseudoCostByPref(double cost_factor)
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:128
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
a very simple interface for solving translated resource exchanges
ExchangeSolver(bool exclusive_orders=kDefaultExclusive)
An ExchangeGraph is a resource-neutral representation of a ResourceExchange.
double PseudoCost()
Calculates the ratio of the maximum objective coefficient to minimum unit capacity plus an added cost...
static double Cost(const Arc &a, bool exclusive_orders=kDefaultExclusive)
return the cost of an arc