7 : cyclus::Region(ctx) {
9 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
10 "with COIN support.");
14GrowthRegion::~GrowthRegion() {}
16void GrowthRegion::AddCommodityDemand_(std::string commod,
20 cyclus::toolkit::PiecewiseFunctionFactory pff;
21 cyclus::toolkit::BasicFunctionFactory bff;
22 bool continuous =
false;
24 std::string type, params;
25 Demand::const_iterator it;
26 for (it = demand.begin(); it != demand.end(); it++) {
28 type = it->second.first;
29 params = it->second.second;
30 pff.AddFunction(bff.GetFunctionPtr(type, params), time, continuous);
35 cyclus::toolkit::Commodity c(commod);
36 sdmanager_.RegisterCommodity(c, pff.GetFunctionPtr());
39void GrowthRegion::EnterNotify() {
40 cyclus::Region::EnterNotify();
41 std::set<cyclus::Agent*>::iterator ait;
42 for (ait = cyclus::Agent::children().begin();
43 ait != cyclus::Agent::children().end();
49 std::map<std::string, Demand>::iterator it;
51 LOG(cyclus::LEV_INFO3,
"greg") <<
"Adding demand for commodity "
59void GrowthRegion::DecomNotify(Agent* a) {
63void GrowthRegion::Register_(cyclus::Agent* agent) {
64 using cyclus::toolkit::CommodityProducerManager;
65 using cyclus::toolkit::Builder;
67 CommodityProducerManager* cpm_cast =
68 dynamic_cast<CommodityProducerManager*
>(agent);
69 if (cpm_cast != NULL) {
70 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
71 << agent->prototype() << agent->id()
72 <<
" as a commodity producer manager.";
76 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
78 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
79 << agent->prototype() << agent->id()
81 buildmanager_.Register(b_cast);
84 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
85 "with COIN support.");
89void GrowthRegion::Unregister_(cyclus::Agent* agent) {
90 using cyclus::toolkit::CommodityProducerManager;
91 using cyclus::toolkit::Builder;
93 CommodityProducerManager* cpm_cast =
94 dynamic_cast<CommodityProducerManager*
>(agent);
96 sdmanager_.UnregisterProducerManager(cpm_cast);
98 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
100 buildmanager_.Unregister(b_cast);
102 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
103 "with COIN support.");
107void GrowthRegion::Tick() {
108 double demand, supply, unmetdemand;
109 cyclus::toolkit::Commodity commod;
110 int time = context()->time();
111 std::map<std::string, Demand>::iterator it;
113 commod = cyclus::toolkit::Commodity(it->first);
116 unmetdemand = demand - supply;
118 LOG(cyclus::LEV_INFO3,
"greg") <<
"GrowthRegion: " << prototype()
119 <<
" at time: " << time
120 <<
" has the following values regarding "
121 <<
" commodity: " << commod.name();
122 LOG(cyclus::LEV_INFO3,
"greg") <<
" * demand = " << demand;
123 LOG(cyclus::LEV_INFO3,
"greg") <<
" * supply = " << supply;
124 LOG(cyclus::LEV_INFO3,
"greg") <<
" * unmet demand = " << unmetdemand;
126 if (unmetdemand > 0) {
130 cyclus::Region::Tick();
133void GrowthRegion::OrderBuilds(cyclus::toolkit::Commodity& commodity,
134 double unmetdemand) {
137 vector<cyclus::toolkit::BuildOrder> orders =
138 buildmanager_.MakeBuildDecision(commodity, unmetdemand);
140 LOG(cyclus::LEV_INFO3,
"greg")
141 <<
"The build orders have been determined. "
143 <<
" different type(s) of prototypes will be built.";
145 cyclus::toolkit::BuildOrder* order;
146 cyclus::Institution* instcast;
147 cyclus::Agent* agentcast;
148 for (
int i = 0; i < orders.size(); i++) {
149 order = &orders.at(i);
150 instcast =
dynamic_cast<cyclus::Institution*
>(order->builder);
151 agentcast =
dynamic_cast<cyclus::Agent*
>(order->producer);
152 if (!instcast || !agentcast) {
153 throw cyclus::CastError(
"growth_region has tried to incorrectly "
154 "cast an already known entity.");
157 LOG(cyclus::LEV_INFO3,
"greg")
158 <<
"A build order for " << order->number
159 <<
" prototype(s) of type "
160 <<
dynamic_cast<cyclus::Agent*
>(agentcast)->prototype()
161 <<
" from builder " << instcast->prototype()
162 <<
" is being placed.";
164 for (
int j = 0; j < order->number; j++) {
165 LOG(cyclus::LEV_DEBUG2,
"greg") <<
"Ordering build number: " << j + 1;
166 context()->SchedBuild(instcast, agentcast->prototype());
170 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
171 "with COIN support.");
176 return new GrowthRegion(ctx);
GrowthRegion(cyclus::Context *ctx)
The default constructor for the GrowthRegion.
cyclus::toolkit::SupplyDemandManager sdmanager_
manager for Supply and demand
cyclus::Agent * ConstructGrowthRegion(cyclus::Context *ctx)
cycamore::GrowthRegion commodity_demand
void Unregister_(cyclus::Agent *agent)
unregister a child
void AddCommodityDemand_(std::string commod, Demand &demand)
add a demand for a commodity on which this region request that facilities be built
void OrderBuilds(cyclus::toolkit::Commodity &commodity, double unmetdemand)
orders builds given a commodity and an unmet demand for production capacity of that commodity
void Register_(cyclus::Agent *agent)
register a child