12 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
13 "with COIN support.");
17GrowthRegion::~GrowthRegion() {}
19void GrowthRegion::AddCommodityDemand_(std::string commod,
23 cyclus::toolkit::PiecewiseFunctionFactory pff;
24 cyclus::toolkit::BasicFunctionFactory bff;
25 bool continuous =
false;
27 std::string type, params;
28 Demand::const_iterator it;
29 for (it = demand.begin(); it != demand.end(); it++) {
31 type = it->second.first;
32 params = it->second.second;
33 pff.AddFunction(bff.GetFunctionPtr(type, params), time, continuous);
38 cyclus::toolkit::Commodity c(commod);
39 sdmanager_.RegisterCommodity(c, pff.GetFunctionPtr());
42void GrowthRegion::EnterNotify() {
43 cyclus::Region::EnterNotify();
44 std::set<cyclus::Agent*>::iterator ait;
45 for (ait = cyclus::Agent::children().begin();
46 ait != cyclus::Agent::children().end();
52 std::map<std::string, Demand>::iterator it;
54 LOG(cyclus::LEV_INFO3,
"greg") <<
"Adding demand for commodity "
61void GrowthRegion::DecomNotify(Agent* a) {
65void GrowthRegion::Register_(cyclus::Agent* agent) {
66 using cyclus::toolkit::CommodityProducerManager;
67 using cyclus::toolkit::Builder;
69 CommodityProducerManager* cpm_cast =
70 dynamic_cast<CommodityProducerManager*
>(agent);
71 if (cpm_cast != NULL) {
72 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
73 << agent->prototype() << agent->id()
74 <<
" as a commodity producer manager.";
78 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
80 LOG(cyclus::LEV_INFO3,
"greg") <<
"Registering agent "
81 << agent->prototype() << agent->id()
83 buildmanager_.Register(b_cast);
86 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
87 "with COIN support.");
91void GrowthRegion::Unregister_(cyclus::Agent* agent) {
92 using cyclus::toolkit::CommodityProducerManager;
93 using cyclus::toolkit::Builder;
95 CommodityProducerManager* cpm_cast =
96 dynamic_cast<CommodityProducerManager*
>(agent);
98 sdmanager_.UnregisterProducerManager(cpm_cast);
100 Builder* b_cast =
dynamic_cast<Builder*
>(agent);
102 buildmanager_.Unregister(b_cast);
104 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
105 "with COIN support.");
109void GrowthRegion::Tick() {
110 double demand, supply, unmetdemand;
111 cyclus::toolkit::Commodity commod;
112 int time = context()->time();
113 std::map<std::string, Demand>::iterator it;
115 commod = cyclus::toolkit::Commodity(it->first);
118 unmetdemand = demand - supply;
120 LOG(cyclus::LEV_INFO3,
"greg") <<
"GrowthRegion: " << prototype()
121 <<
" at time: " << time
122 <<
" has the following values regarding "
123 <<
" commodity: " << commod.name();
124 LOG(cyclus::LEV_INFO3,
"greg") <<
" * demand = " << demand;
125 LOG(cyclus::LEV_INFO3,
"greg") <<
" * supply = " << supply;
126 LOG(cyclus::LEV_INFO3,
"greg") <<
" * unmet demand = " << unmetdemand;
128 if (unmetdemand > 0) {
132 cyclus::Region::Tick();
135void GrowthRegion::OrderBuilds(cyclus::toolkit::Commodity& commodity,
136 double unmetdemand) {
139 vector<cyclus::toolkit::BuildOrder> orders =
140 buildmanager_.MakeBuildDecision(commodity, unmetdemand);
142 LOG(cyclus::LEV_INFO3,
"greg")
143 <<
"The build orders have been determined. "
145 <<
" different type(s) of prototypes will be built.";
147 cyclus::toolkit::BuildOrder* order;
148 cyclus::Institution* instcast;
149 cyclus::Agent* agentcast;
150 for (
int i = 0; i < orders.size(); i++) {
151 order = &orders.at(i);
152 instcast =
dynamic_cast<cyclus::Institution*
>(order->builder);
153 agentcast =
dynamic_cast<cyclus::Agent*
>(order->producer);
154 if (!instcast || !agentcast) {
155 throw cyclus::CastError(
"growth_region has tried to incorrectly "
156 "cast an already known entity.");
159 LOG(cyclus::LEV_INFO3,
"greg")
160 <<
"A build order for " << order->number
161 <<
" prototype(s) of type "
162 <<
dynamic_cast<cyclus::Agent*
>(agentcast)->prototype()
163 <<
" from builder " << instcast->prototype()
164 <<
" is being placed.";
166 for (
int j = 0; j < order->number; j++) {
167 LOG(cyclus::LEV_DEBUG2,
"greg") <<
"Ordering build number: " << j + 1;
168 context()->SchedBuild(instcast, agentcast->prototype());
172 throw cyclus::Error(
"Growth Region requires that Cyclus & Cycamore be compiled "
173 "with COIN support.");
177void GrowthRegion::RecordPosition() {
178 std::string specification = this->spec();
180 ->NewDatum(
"AgentPosition")
181 ->AddVal(
"Spec", specification)
182 ->AddVal(
"Prototype", this->prototype())
183 ->AddVal(
"AgentId",
id())
184 ->AddVal(
"Latitude", latitude)
185 ->AddVal(
"Longitude", longitude)
190 return new GrowthRegion(ctx);
GrowthRegion(cyclus::Context *ctx)
The default constructor for the GrowthRegion.
cyclus::toolkit::SupplyDemandManager sdmanager_
manager for Supply and demand
void RecordPosition()
Records an agent's latitude and longitude to the output db.
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
cyclus::toolkit::Position coordinates