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// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 rsrc_commod_map_[rsrc->obj_id()] = commod;
33}
34
35// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 std::string recipe) {
38 in_recipes_[incommod] = recipe;
39}
40
44
46 int nfuel = qe->NMatches("fuel");
47 for (int i = 0; i < nfuel; i++) {
48 InfileTree* fuel = qe->SubTree("fuel", i);
49 di.NewDatum("CommodityRecipeContext_inoutmap")
50 ->AddVal("in_commod", fuel->GetString("incommodity"))
51 ->AddVal("in_recipe", fuel->GetString("inrecipe"))
52 ->AddVal("out_commod", fuel->GetString("outcommodity"))
53 ->AddVal("out_recipe", fuel->GetString("outrecipe"))
54 ->Record();
55 }
56}
57
59 QueryResult qr = b->Query("CommodityRecipeContext_inoutmap", NULL);
60 for (int i = 0; i < qr.rows.size(); ++i) {
61 AddInCommod(qr.GetVal<std::string>("in_commod", i),
62 qr.GetVal<std::string>("in_recipe", i),
63 qr.GetVal<std::string>("out_commod", i),
64 qr.GetVal<std::string>("out_recipe", i));
65 }
66
67 try {
68 qr = b->Query("CommodityRecipeContext_resmap", NULL);
69 } catch(std::exception err) { return; } // Table doesn't exist (okay)
70
71 for (int i = 0; i < qr.rows.size(); ++i) {
72 std::string commod = qr.GetVal<std::string>("commod", i);
73 int id = qr.GetVal<int>("res_id", i);
74 rsrc_commod_map_[id] = commod;
75 }
76}
77
79 std::set<std::string>::iterator it2;
80 for (it2 = in_commods_.begin(); it2 != in_commods_.end(); ++it2) {
81 std::string c = *it2;
82 di.NewDatum("CommodityRecipeContext_inoutmap")
83 ->AddVal("in_commod", c)
84 ->AddVal("in_recipe", in_recipes_[c])
85 ->AddVal("out_commod", out_commod_map_[c])
86 ->AddVal("out_recipe", out_recipes_[c])
87 ->Record();
88 }
89
90 std::map<int, std::string>::iterator it = rsrc_commod_map_.begin();
91 for (; it != rsrc_commod_map_.end(); ++it) {
92 di.NewDatum("CommodityRecipeContext_resmap")
93 ->AddVal("commod", it->second)
94 ->AddVal("res_id", it->first)
95 ->Record();
96 }
97}
98
100 return
101 " <oneOrMore> \n"
102 " <element name=\"fuel\"> \n"
103 " <element name=\"incommodity\"><text/></element>\n"
104 " <element name=\"inrecipe\"><text/></element>\n"
105 " <element name=\"outcommodity\"><text/></element>\n"
106 " <element name=\"outrecipe\"><text/></element>\n"
107 " </element> \n"
108 " </oneOrMore> \n";
109}
110
111} // namespace toolkit
112} // namespace cyclus
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Definition db_init.h:14
A class for extracting information from a given XML parser.
Definition infile_tree.h:22
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
Meta data and results of a query.
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters