CYCLUS
commodity_recipe_context.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_TOOLKIT_COMMODITY_RECIPE_CONTEXT_H_
2 #define CYCLUS_SRC_TOOLKIT_COMMODITY_RECIPE_CONTEXT_H_
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include "cyc_std.h"
9 #include "resource.h"
10 #include "state_wrangler.h"
11 
12 namespace cyclus {
13 namespace toolkit {
14 
15 /// @class CommodityRecipeContext
16 ///
17 /// @brief a CommodityRecipeContext contains relationships between commodities,
18 /// recipes and resources
20  public:
21  /// @brief add an input commodity and its relations
22  void AddInCommod(std::string in_commod,
23  std::string in_recipe,
24  std::string out_commod,
25  std::string out_recipe);
26 
27  /// @brief add a resource and its commodity affiliation
28  void AddRsrc(std::string commod, Resource::Ptr rsrc);
29 
30  /// @brief update a resource and its commodity affiliation
31  void UpdateRsrc(std::string commod, Resource::Ptr rsrc);
32 
33  /// @brief removes a resource from the context
34  void RemoveRsrc(Resource::Ptr rsrc);
35 
36  /// @brief update an input recipe and its commodity affiliation
37  void UpdateInRec(std::string in_commod, std::string recipe);
38 
39  /// @return input commodities
40  inline const std::set<std::string>& in_commods() const {
41  return in_commods_;
42  }
43 
44  /// @return output commodities
45  inline const std::set<std::string>& out_commods() const {
46  return out_commods_;
47  }
48 
49  /// @return output commodity of an input commodity
50  inline std::string out_commod(std::string in_commod) {
51  return out_commod_map_[in_commod];
52  }
53 
54  /// @return input recipe of an input commodity
55  inline std::string in_recipe(std::string in_commod) {
56  return in_recipes_[in_commod];
57  }
58 
59  /// @return output recipe of an input recipe
60  inline std::string out_recipe(std::string in_commod) {
61  return out_recipes_[in_commod];
62  }
63 
64  /// @return commodity of a material
65  /// @warning returns a blank string if material isn't found
66  inline std::string commod(Resource::Ptr rsrc) {
67  return rsrc_commod_map_[rsrc->obj_id()];
68  }
69 
70  inline bool operator==(const CommodityRecipeContext& other) const {
71  return (in_commods_.size() == other.in_commods_.size()
72  && out_commods_.size() == other.out_commods_.size()
73  && map_compare(out_commod_map_, other.out_commod_map_)
74  && map_compare(in_recipes_, other.in_recipes_)
75  && map_compare(out_recipes_, other.out_recipes_)
76  && map_compare(rsrc_commod_map_, other.rsrc_commod_map_));
77  }
78 
79  inline bool operator!=(const CommodityRecipeContext& other) const {
80  return !operator==(other);
81  }
82 
83  virtual CommodityRecipeContext* Clone();
84  virtual void InfileToDb(InfileTree* qe, DbInit di);
85  virtual void InitFrom(QueryableBackend* b);
86  virtual void Snapshot(DbInit di);
87  virtual std::string schema();
88 
89  private:
90  std::set<std::string> in_commods_;
91  std::set<std::string> out_commods_;
92  std::map<std::string, std::string> out_commod_map_;
93  std::map<std::string, std::string> in_recipes_;
94  std::map<std::string, std::string> out_recipes_;
95  std::map<int, std::string> rsrc_commod_map_;
96 };
97 
98 } // namespace toolkit
99 } // namespace cyclus
100 
101 #endif // CYCLUS_SRC_TOOLKIT_COMMODITY_RECIPE_CONTEXT_H_
An abjstract interface that must be implemented by all simulation agents and all agent member variabl...
void UpdateRsrc(std::string commod, Resource::Ptr rsrc)
update a resource and its commodity affiliation
virtual void Snapshot(DbInit di)
Snapshots agent-internal state to the output db via di.
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition: pyne.cc:11180
A class for extracting information from a given XML parser.
Definition: infile_tree.h:22
virtual void InfileToDb(InfileTree *qe, DbInit di)
Translates info for the object from input file information to the database by reading parameters from...
bool operator==(const CommodityRecipeContext &other) const
const std::set< std::string > & out_commods() const
std::string out_recipe(std::string in_commod)
void AddRsrc(std::string commod, Resource::Ptr rsrc)
add a resource and its commodity affiliation
virtual std::string schema()
Returns an object&#39;s xml rng schema for initializing from input files.
void AddInCommod(std::string in_commod, std::string in_recipe, std::string out_commod, std::string out_recipe)
add an input commodity and its relations
a CommodityRecipeContext contains relationships between commodities, recipes and resources ...
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Definition: db_init.h:14
const std::set< std::string > & in_commods() const
bool map_compare(Map const &lhs, Map const &rhs)
Definition: cyc_std.h:20
void UpdateInRec(std::string in_commod, std::string recipe)
update an input recipe and its commodity affiliation
boost::shared_ptr< Resource > Ptr
Definition: resource.h:24
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
std::string in_recipe(std::string in_commod)
void RemoveRsrc(Resource::Ptr rsrc)
removes a resource from the context
bool operator!=(const CommodityRecipeContext &other) const
virtual void InitFrom(QueryableBackend *b)
Intializes an agent&#39;s internal state from an output database.
Interface implemented by backends that support rudimentary querying.
virtual CommodityRecipeContext * Clone()
Return a newly created/allocated object that is an exact copy of this.
std::string out_commod(std::string in_commod)