1#line 1 "/cycamore/src/growth_region.cc"
8 : cyclus::Region(ctx) {
10 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
11 "with COIN support.");
21 cyclus::toolkit::PiecewiseFunctionFactory pff;
22 cyclus::toolkit::BasicFunctionFactory bff;
23 bool continuous =
false;
25 std::string type, params;
26 Demand::const_iterator it;
27 for (it = demand.begin(); it != demand.end(); it++) {
29 type = it->second.first;
30 params = it->second.second;
31 pff.AddFunction(bff.GetFunctionPtr(type, params), time, continuous);
36 cyclus::toolkit::Commodity c(commod);
37 sdmanager_.RegisterCommodity(c, pff.GetFunctionPtr());
41 cyclus::Region::EnterNotify();
42 std::set<cyclus::Agent*>::iterator ait;
43 for (ait = cyclus::Agent::children().begin();
44 ait != cyclus::Agent::children().end();
50 std::map<std::string, Demand>::iterator it;
52 LOG(cyclus::LEV_INFO3,
"greg") <<
"Adding demand for commodity "
65 using cyclus::toolkit::CommodityProducerManager;
66 using cyclus::toolkit::Builder;
68 CommodityProducerManager* cpm_cast =
69 dynamic_cast<CommodityProducerManager*
>(agent);
70 if (cpm_cast != NULL) {
71 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
72 << agent->prototype() << agent->id()
73 <<
" as a commodity producer manager.";
77 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
79 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
80 << agent->prototype() << agent->id()
82 buildmanager_.Register(b_cast);
85 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
86 "with COIN support.");
91 using cyclus::toolkit::CommodityProducerManager;
92 using cyclus::toolkit::Builder;
94 CommodityProducerManager* cpm_cast =
95 dynamic_cast<CommodityProducerManager*
>(agent);
97 sdmanager_.UnregisterProducerManager(cpm_cast);
99 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
101 buildmanager_.Unregister(b_cast);
103 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
104 "with COIN support.");
109 double demand, supply, unmetdemand;
110 cyclus::toolkit::Commodity commod;
111 int time = context()->time();
112 std::map<std::string, Demand>::iterator it;
114 commod = cyclus::toolkit::Commodity(it->first);
117 unmetdemand = demand - supply;
119 LOG(cyclus::LEV_INFO3,
"greg") <<
"GrowthRegion: " << prototype()
120 <<
" at time: " << time
121 <<
" has the following values regarding "
122 <<
" commodity: " << commod.name();
123 LOG(cyclus::LEV_INFO3,
"greg") <<
" * demand = " << demand;
124 LOG(cyclus::LEV_INFO3,
"greg") <<
" * supply = " << supply;
125 LOG(cyclus::LEV_INFO3,
"greg") <<
" * unmet demand = " << unmetdemand;
127 if (unmetdemand > 0) {
131 cyclus::Region::Tick();
135 double unmetdemand) {
138 vector<cyclus::toolkit::BuildOrder> orders =
139 buildmanager_.MakeBuildDecision(commodity, unmetdemand);
141 LOG(cyclus::LEV_INFO3,
"greg")
142 <<
"The build orders have been determined. "
144 <<
" different type(s) of prototypes will be built.";
146 cyclus::toolkit::BuildOrder* order;
147 cyclus::Institution* instcast;
148 cyclus::Agent* agentcast;
149 for (
int i = 0; i < orders.size(); i++) {
150 order = &orders.at(i);
151 instcast =
dynamic_cast<cyclus::Institution*
>(order->builder);
152 agentcast =
dynamic_cast<cyclus::Agent*
>(order->producer);
153 if (!instcast || !agentcast) {
154 throw cyclus::CastError(
"growth_region has tried to incorrectly "
155 "cast an already known entity.");
158 LOG(cyclus::LEV_INFO3,
"greg")
159 <<
"A build order for " << order->number
160 <<
" prototype(s) of type "
161 <<
dynamic_cast<cyclus::Agent*
>(agentcast)->prototype()
162 <<
" from builder " << instcast->prototype()
163 <<
" is being placed.";
165 for (
int j = 0; j < order->number; j++) {
166 LOG(cyclus::LEV_DEBUG2,
"greg") <<
"Ordering build number: " << j + 1;
167 context()->SchedBuild(instcast, agentcast->prototype());
171 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
172 "with COIN support.");
This region determines if there is a need to meet a certain capacity (as defined via input) at each t...
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)