21 <<
" to end=" << si_.duration;
26 while (time_ < si_.duration) {
30 want_snapshot_ =
false;
39 DoResEx(&matl_manager, &genrsrc_manager);
46#ifdef CYCLUS_WITH_PYTHON
57 ctx_->NewDatum(
"Finish")
58 ->AddVal(
"EarlyTerm", want_kill_)
59 ->AddVal(
"EndTime", time_ - 1)
66void Timer::DoBuild() {
68 std::vector<std::pair<std::string, Agent*>> build_list = build_queue_[time_];
69 for (
int i = 0; i < build_list.size(); ++i) {
71 Agent* parent = build_list[i].second;
72 CLOG(
LEV_INFO3) <<
"Building a " << build_list[i].first <<
" from parent "
73 << build_list[i].second;
76 parent->BuildNotify(m);
78 CLOG(
LEV_DEBUG1) <<
"Hey! Listen! Built an Agent without a Parent.";
84 for (TimeListener* agent : py_tickers_) {
88#pragma omp parallel for
89 for (
size_t i = 0; i < cpp_tickers_.size(); ++i) {
90 cpp_tickers_[i]->Tick();
100void Timer::DoTock() {
101 for (TimeListener* agent : py_tickers_) {
105#pragma omp parallel for
106 for (
size_t i = 0; i < cpp_tickers_.size(); ++i) {
107 cpp_tickers_[i]->Tock();
110 if (si_.explicit_inventory || si_.explicit_inventory_compact) {
111 std::set<Agent*> ags = ctx_->agent_list_;
112 std::vector<Agent*> agent_vec(ags.begin(), ags.end());
113#pragma omp parallel for
114 for (
int i = 0; i < agent_vec.size(); i++) {
115 Agent* a = agent_vec[i];
116 if (a->enter_time() != -1) {
117 RecordInventories(a);
123void Timer::DoDecision() {
124 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
125 agent != tickers_.end();
127 agent->second->Decision();
131void Timer::RecordInventories(
Agent* a) {
133 Inventories::iterator it2;
134 for (it2 = invs.begin(); it2 != invs.end(); ++it2) {
135 std::string
name = it2->first;
136 std::vector<Resource::Ptr> mats = it2->second;
142 for (
int i = 1; i < mats.size(); i++) {
145 RecordInventory(a, name, m);
150 if (si_.explicit_inventory) {
153 CompMap::iterator it;
154 for (it = c.begin(); it != c.end(); ++it) {
155 ctx_->NewDatum(
"ExplicitInventory")
156 ->AddVal(
"AgentId", a->id())
157 ->AddVal(
"Time", time_)
158 ->AddVal(
"InventoryName", name)
159 ->AddVal(
"NucId", it->first)
160 ->AddVal(
"Quantity", it->second)
161 ->AddVal(
"Units", m->units())
166 if (si_.explicit_inventory_compact) {
169 ctx_->NewDatum(
"ExplicitInventoryCompact")
170 ->AddVal(
"AgentId", a->id())
171 ->AddVal(
"Time", time_)
172 ->AddVal(
"InventoryName", name)
173 ->AddVal(
"Quantity", m->quantity())
174 ->AddVal(
"Units", m->units())
175 ->AddVal(
"Composition", c)
180void Timer::DoDecom() {
182 std::vector<Agent*> decom_list = decom_queue_[time_];
183 for (
int i = 0; i < decom_list.size(); ++i) {
184 Agent* m = decom_list[i];
185 if (m->parent() != NULL) {
186 m->parent()->DecomNotify(m);
193 tickers_[agent->
id()] = agent;
195 py_tickers_.push_back(agent);
197 cpp_tickers_.push_back(agent);
202 tickers_.erase(tl->
id());
204 py_tickers_.erase(std::remove(py_tickers_.begin(), py_tickers_.end(), tl),
208 std::remove(cpp_tickers_.begin(), cpp_tickers_.end(), tl),
215 throw ValueError(
"Cannot schedule build for t < [current-time]");
217 build_queue_[t].push_back(std::make_pair(proto_name, parent));
222 throw ValueError(
"Cannot schedule decommission for t < [current-time]");
230 std::map<int, std::vector<Agent*>>::iterator it;
232 for (it = decom_queue_.begin(); it != decom_queue_.end(); ++it) {
234 std::vector<Agent*> ags = it->second;
235 for (
int i = 0; i < ags.size(); i++) {
237 CLOG(
LEV_WARN) <<
"scheduled over previous decommissioning of "
239 decom_queue_[t].erase(decom_queue_[t].begin() + i);
249 decom_queue_[t].push_back(m);
258 cpp_tickers_.clear();
260 build_queue_.clear();
261 decom_queue_.clear();
266 if (si.
m0 < 1 || si.
m0 > 12) {
267 throw ValueError(
"Invalid month0; must be between 1 and 12 (inclusive).");
284Timer::Timer() : time_(0), si_(0), want_snapshot_(false), want_kill_(false) {}
The abstract base class used by all types of agents that live and interact in a simulation.
virtual void Build(Agent *parent)
Called when the agent enters the smiulation as an active participant and is only ever called once.
virtual const int id() const
The agent instance's unique ID within a simulation.
A simulation context provides access to necessary simulation-global functions and state.
T * CreateAgent(std::string proto_name)
Create a new agent by cloning the named prototype.
The ExchangeManager is designed to house all of the internals involved in executing a resource exchan...
virtual const int id() const =0
boost::shared_ptr< Material > Ptr
Container for a static simulation-global parameters that both describe the simulation and affect its ...
int m0
start month for the simulation: Jan = 1, ..., Dec = 12
int duration
length of the simulation in timesteps (months)
int branch_time
timestep at which simulation branching occurs if any
static void Snapshot(Context *ctx)
Records a snapshot of the current state of the simulation being managed by ctx into the simulation's ...
The TimeListener class is an inheritable class for any Agent that requires knowlege of ticks and tock...
int time()
Returns the current time, in months since the simulation started.
void UnregisterTimeListener(TimeListener *tl)
Removes an agent from receiving tick/tock notifications.
int dur()
Returns the duration of the simulation this Timer's timing.
void SchedBuild(Agent *parent, std::string proto_name, int t)
Schedules the named prototype to be built for the specified parent at timestep t.
void Reset()
resets all data (registered listeners, etc.) to empty or initial state
void RunSim()
Runs the simulation.
void RegisterTimeListener(TimeListener *agent)
Registers an agent to receive tick/tock notifications every timestep.
void Initialize(Context *ctx, SimInfo si)
Sets intial time-related parameters for the simulation.
void SchedDecom(Agent *m, int time)
Schedules the given Agent to be decommissioned at the specified timestep t.
For values that are too big, too small, etc.
Code providing rudimentary logging capability for the Cyclus core.
void Normalize(CompMap *v, double val)
The sum of quantities of all nuclides of v is normalized to val.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
@ LEV_INFO3
Information helpful for simulation users and developers alike.
@ LEV_DEBUG1
debugging information - least verbose
@ LEV_WARN
Use to report questionable simulation state (use extremely sparingly)
@ LEV_INFO2
Information helpful for simulation users and developers alike.
@ LEV_INFO1
Information helpful for simulation users and developers alike.
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
std::vector< typename T::Ptr > ResCast(std::vector< Resource::Ptr > rs)
Casts a vector of Resources into a vector of a specific resource type T.
std::map< std::string, std::vector< Resource::Ptr > > Inventories
map<inventory_name, vector<resources_in_inventory> >.
std::string name(int nuc)