CYCLUS
Loading...
Searching...
No Matches
commodity_recipe_context.cc
Go to the documentation of this file.
1#include <utility>
2
4
5namespace cyclus {
6namespace toolkit {
7
8// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9void CommodityRecipeContext::AddInCommod(std::string in_commod,
10 std::string in_recipe,
11 std::string out_commod,
12 std::string out_recipe) {
13 in_commods_.insert(in_commod);
14 out_commods_.insert(out_commod);
15 out_commod_map_[in_commod] = out_commod;
16 in_recipes_[in_commod] = in_recipe;
17 out_recipes_[in_commod] = out_recipe;
18}
19
20// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22 rsrc_commod_map_[rsrc->obj_id()] = commod;
23}
24
25// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27 rsrc_commod_map_.erase(rsrc->obj_id());
28}
29
30// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32 Resource::Ptr rsrc) {
33 rsrc_commod_map_[rsrc->obj_id()] = commod;
34}
35
36// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37void CommodityRecipeContext::UpdateInRec(std::string incommod,
38 std::string recipe) {
39 in_recipes_[incommod] = recipe;
40}
41
45
47 int nfuel = qe->NMatches("fuel");
48 for (int i = 0; i < nfuel; i++) {
49 InfileTree* fuel = qe->SubTree("fuel", i);
50 di.NewDatum("CommodityRecipeContext_inoutmap")
51 ->AddVal("in_commod", fuel->GetString("incommodity"))
52 ->AddVal("in_recipe", fuel->GetString("inrecipe"))
53 ->AddVal("out_commod", fuel->GetString("outcommodity"))
54 ->AddVal("out_recipe", fuel->GetString("outrecipe"))
55 ->Record();
56 }
57}
58
60 QueryResult qr = b->Query("CommodityRecipeContext_inoutmap", NULL);
61 for (int i = 0; i < qr.rows.size(); ++i) {
62 AddInCommod(qr.GetVal<std::string>("in_commod", i),
63 qr.GetVal<std::string>("in_recipe", i),
64 qr.GetVal<std::string>("out_commod", i),
65 qr.GetVal<std::string>("out_recipe", i));
66 }
67
68 try {
69 qr = b->Query("CommodityRecipeContext_resmap", NULL);
70 } catch (std::exception err) {
71 return;
72 } // Table doesn't exist (okay)
73
74 for (int i = 0; i < qr.rows.size(); ++i) {
75 std::string commod = qr.GetVal<std::string>("commod", i);
76 int id = qr.GetVal<int>("res_id", i);
77 rsrc_commod_map_[id] = commod;
78 }
79}
80
82 std::set<std::string>::iterator it2;
83 for (it2 = in_commods_.begin(); it2 != in_commods_.end(); ++it2) {
84 std::string c = *it2;
85 di.NewDatum("CommodityRecipeContext_inoutmap")
86 ->AddVal("in_commod", c)
87 ->AddVal("in_recipe", in_recipes_[c])
88 ->AddVal("out_commod", out_commod_map_[c])
89 ->AddVal("out_recipe", out_recipes_[c])
90 ->Record();
91 }
92
93 std::map<int, std::string>::iterator it = rsrc_commod_map_.begin();
94 for (; it != rsrc_commod_map_.end(); ++it) {
95 di.NewDatum("CommodityRecipeContext_resmap")
96 ->AddVal("commod", it->second)
97 ->AddVal("res_id", it->first)
98 ->Record();
99 }
100}
101
103 return " <oneOrMore> \n"
104 " <element name=\"fuel\"> \n"
105 " <element name=\"incommodity\"><text/></element>\n"
106 " <element name=\"inrecipe\"><text/></element>\n"
107 " <element name=\"outcommodity\"><text/></element>\n"
108 " <element name=\"outrecipe\"><text/></element>\n"
109 " </element> \n"
110 " </oneOrMore> \n";
111}
112
113} // namespace toolkit
114} // namespace cyclus
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition datum.cc:21
void Record()
Record this datum to its Recorder.
Definition datum.cc:34
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Definition db_init.h:14
Datum * NewDatum(std::string title)
Returns a new datum to be used exactly as the Context::NewDatum method.
Definition db_init.cc:12
A class for extracting information from a given XML parser.
Definition infile_tree.h:22
virtual int NMatches(std::string query)
investigates the current status and returns the number of elements matching a query
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
Meta data and results of a query.
std::vector< QueryRow > rows
ordered results of a query
T GetVal(std::string field, int row=0)
Convenience method for retrieving a value from a specific row and named field (column).
Interface implemented by backends that support rudimentary querying.
boost::shared_ptr< Resource > Ptr
Definition resource.h:27
a CommodityRecipeContext contains relationships between commodities, recipes and resources
std::string in_recipe(std::string in_commod)
virtual void Snapshot(DbInit di)
Snapshots agent-internal state to the output db via di.
virtual void InfileToDb(InfileTree *qe, DbInit di)
Translates info for the object from input file information to the database by reading parameters from...
virtual CommodityRecipeContext * Clone()
Return a newly created/allocated object that is an exact copy of this.
std::string out_commod(std::string in_commod)
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
void RemoveRsrc(Resource::Ptr rsrc)
removes a resource from the context
virtual std::string schema()
Returns an object's xml rng schema for initializing from input files.
void AddRsrc(std::string commod, Resource::Ptr rsrc)
add a resource and its commodity affiliation
void UpdateInRec(std::string in_commod, std::string recipe)
update an input recipe and its commodity affiliation
void UpdateRsrc(std::string commod, Resource::Ptr rsrc)
update a resource and its commodity affiliation
virtual void InitFrom(QueryableBackend *b)
Intializes an agent's internal state from an output database.
std::string out_recipe(std::string in_commod)
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14