27 want_snapshot_ =
false;
43#ifdef CYCLUS_WITH_PYTHON
55 ->
AddVal(
"EarlyTerm", want_kill_)
56 ->
AddVal(
"EndTime", time_-1)
62void Timer::DoBuild() {
64 std::vector<std::pair<std::string, Agent*> >
build_list = build_queue_[time_];
72 parent->BuildNotify(m);
74 CLOG(
LEV_DEBUG1) <<
"Hey! Listen! Built an Agent without a Parent.";
80 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
81 agent != tickers_.end();
83 agent->second->Tick();
94 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
95 agent != tickers_.end();
97 agent->second->Tock();
101 std::set<Agent*>
ags = ctx_->agent_list_;
102 std::set<Agent*>::iterator
it;
105 if (
a->enter_time() == -1) {
108 RecordInventories(
a);
113void Timer::DoDecision() {
114 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
115 agent != tickers_.end();
117 agent->second->Decision();
121void Timer::RecordInventories(Agent*
a) {
123 Inventories::iterator
it2;
126 std::vector<Resource::Ptr>
mats =
it2->second;
132 for (
int i = 1; i <
mats.size(); i++) {
135 RecordInventory(
a, name, m);
139void Timer::RecordInventory(Agent*
a, std::string name,
Material::Ptr m) {
143 CompMap::iterator
it;
144 for (
it =
c.begin();
it !=
c.end(); ++
it) {
147 ->AddVal(
"Time", time_)
148 ->
AddVal(
"InventoryName", name)
151 ->
AddVal(
"Units", m->units())
159 ctx_->
NewDatum(
"ExplicitInventoryCompact")
162 ->
AddVal(
"InventoryName", name)
163 ->
AddVal(
"Quantity", m->quantity())
164 ->
AddVal(
"Units", m->units())
170void Timer::DoDecom() {
172 std::vector<Agent*>
decom_list = decom_queue_[time_];
175 if (m->parent() !=
NULL) {
176 m->parent()->DecomNotify(m);
183 tickers_[agent->
id()] = agent;
187 tickers_.erase(
tl->id());
192 throw ValueError(
"Cannot schedule build for t < [current-time]");
194 build_queue_[t].push_back(std::make_pair(
proto_name, parent));
199 throw ValueError(
"Cannot schedule decommission for t < [current-time]");
207 std::map<int, std::vector<Agent*> >::iterator
it;
209 for (
it = decom_queue_.begin();
it != decom_queue_.end(); ++
it) {
211 std::vector<Agent*>
ags =
it->second;
212 for (
int i = 0; i <
ags.size(); i++) {
214 CLOG(
LEV_WARN) <<
"scheduled over previous decommissioning of " << m->
id();
215 decom_queue_[t].erase(decom_queue_[t].begin()+i);
225 decom_queue_[t].push_back(m);
234 build_queue_.clear();
235 decom_queue_.clear();
240 if (
si.m0 < 1 ||
si.m0 > 12) {
241 throw ValueError(
"Invalid month0; must be between 1 and 12 (inclusive).");
249 if (
si.branch_time > -1) {
250 time_ =
si.branch_time;
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.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
void Record()
Record this datum to its Recorder.
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 ...
bool explicit_inventory_compact
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i....
int duration
length of the simulation in timesteps (months)
bool explicit_inventory
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i....
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 - least verbose.
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
std::map< std::string, std::vector< Resource::Ptr > > Inventories
map<inventory_name, vector<resources_in_inventory> >.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::string name(int nuc)