1#line 1 "/cycamore/src/growth_region.cc"
13 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
14 "with COIN support.");
24 cyclus::toolkit::PiecewiseFunctionFactory pff;
25 cyclus::toolkit::BasicFunctionFactory bff;
26 bool continuous =
false;
28 std::string type, params;
29 Demand::const_iterator it;
30 for (it = demand.begin(); it != demand.end(); it++) {
32 type = it->second.first;
33 params = it->second.second;
34 pff.AddFunction(bff.GetFunctionPtr(type, params), time, continuous);
39 cyclus::toolkit::Commodity c(commod);
40 sdmanager_.RegisterCommodity(c, pff.GetFunctionPtr());
44 cyclus::Region::EnterNotify();
45 std::set<cyclus::Agent*>::iterator ait;
46 for (ait = cyclus::Agent::children().begin();
47 ait != cyclus::Agent::children().end();
53 std::map<std::string, Demand>::iterator it;
55 LOG(cyclus::LEV_INFO3,
"greg") <<
"Adding demand for commodity "
67 using cyclus::toolkit::CommodityProducerManager;
68 using cyclus::toolkit::Builder;
70 CommodityProducerManager* cpm_cast =
71 dynamic_cast<CommodityProducerManager*
>(agent);
72 if (cpm_cast != NULL) {
73 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
74 << agent->prototype() << agent->id()
75 <<
" as a commodity producer manager.";
79 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
81 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
82 << agent->prototype() << agent->id()
84 buildmanager_.Register(b_cast);
87 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
88 "with COIN support.");
93 using cyclus::toolkit::CommodityProducerManager;
94 using cyclus::toolkit::Builder;
96 CommodityProducerManager* cpm_cast =
97 dynamic_cast<CommodityProducerManager*
>(agent);
99 sdmanager_.UnregisterProducerManager(cpm_cast);
101 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
103 buildmanager_.Unregister(b_cast);
105 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
106 "with COIN support.");
111 double demand, supply, unmetdemand;
112 cyclus::toolkit::Commodity commod;
113 int time = context()->time();
114 std::map<std::string, Demand>::iterator it;
116 commod = cyclus::toolkit::Commodity(it->first);
119 unmetdemand = demand - supply;
121 LOG(cyclus::LEV_INFO3,
"greg") <<
"GrowthRegion: " << prototype()
122 <<
" at time: " << time
123 <<
" has the following values regarding "
124 <<
" commodity: " << commod.name();
125 LOG(cyclus::LEV_INFO3,
"greg") <<
" * demand = " << demand;
126 LOG(cyclus::LEV_INFO3,
"greg") <<
" * supply = " << supply;
127 LOG(cyclus::LEV_INFO3,
"greg") <<
" * unmet demand = " << unmetdemand;
129 if (unmetdemand > 0) {
133 cyclus::Region::Tick();
137 double unmetdemand) {
140 vector<cyclus::toolkit::BuildOrder> orders =
141 buildmanager_.MakeBuildDecision(commodity, unmetdemand);
143 LOG(cyclus::LEV_INFO3,
"greg")
144 <<
"The build orders have been determined. "
146 <<
" different type(s) of prototypes will be built.";
148 cyclus::toolkit::BuildOrder* order;
149 cyclus::Institution* instcast;
150 cyclus::Agent* agentcast;
151 for (
int i = 0; i < orders.size(); i++) {
152 order = &orders.at(i);
153 instcast =
dynamic_cast<cyclus::Institution*
>(order->builder);
154 agentcast =
dynamic_cast<cyclus::Agent*
>(order->producer);
155 if (!instcast || !agentcast) {
156 throw cyclus::CastError(
"growth_region has tried to incorrectly "
157 "cast an already known entity.");
160 LOG(cyclus::LEV_INFO3,
"greg")
161 <<
"A build order for " << order->number
162 <<
" prototype(s) of type "
163 <<
dynamic_cast<cyclus::Agent*
>(agentcast)->prototype()
164 <<
" from builder " << instcast->prototype()
165 <<
" is being placed.";
167 for (
int j = 0; j < order->number; j++) {
168 LOG(cyclus::LEV_DEBUG2,
"greg") <<
"Ordering build number: " << j + 1;
169 context()->SchedBuild(instcast, agentcast->prototype());
173 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
174 "with COIN support.");
179 std::string specification = this->spec();
181 ->NewDatum(
"AgentPosition")
182 ->AddVal(
"Spec", specification)
183 ->AddVal(
"Prototype", this->prototype())
184 ->AddVal(
"AgentId",
id())
This region determines if there is a need to meet a certain capacity (as defined via input) at each t...
void RecordPosition()
Records an agent's latitude and longitude to the output db.
void Unregister_(cyclus::Agent *agent)
unregister a child
GrowthRegion(cyclus::Context *ctx)
The default constructor for the GrowthRegion.
virtual void EnterNotify()
enter the simulation and register any children present
virtual void DecomNotify(Agent *m)
unregister a child
cyclus::toolkit::SupplyDemandManager sdmanager_
manager for Supply and demand
virtual void Tick()
On each tick, the GrowthRegion queries its supply demand manager to determine if there exists some de...
void OrderBuilds(cyclus::toolkit::Commodity &commodity, double unmetdemand)
orders builds given a commodity and an unmet demand for production capacity of that commodity
virtual ~GrowthRegion()
The default destructor for the GrowthRegion.
std::map< std::string, std::vector< std::pair< int, std::pair< std::string, std::string > > > > commodity_demand
void Register_(cyclus::Agent *agent)
register a child
void AddCommodityDemand_(std::string commod, Demand &demand)
add a demand for a commodity on which this region request that facilities be built
std::vector< std::pair< int, std::pair< std::string, std::string > > > Demand
A container of (time, (demand type, demand parameters))
cyclus::Agent * ConstructGrowthRegion(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates