27 want_snapshot_ =
false;
36 DoResEx(&matl_manager, &genrsrc_manager);
43 #ifdef CYCLUS_WITH_PYTHON 55 ->
AddVal(
"EarlyTerm", want_kill_)
56 ->
AddVal(
"EndTime", time_-1)
62 void Timer::DoBuild() {
64 std::vector<std::pair<std::string, Agent*> > build_list = build_queue_[time_];
65 for (
int i = 0; i < build_list.size(); ++i) {
69 <<
" from parent " << build_list[i].second;
72 parent->BuildNotify(m);
74 CLOG(
LEV_DEBUG1) <<
"Hey! Listen! Built an Agent without a Parent.";
79 void Timer::DoTick() {
80 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
81 agent != tickers_.end();
83 agent->second->Tick();
93 void Timer::DoTock() {
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;
103 for (it = ags.begin(); it != ags.end(); ++it) {
108 RecordInventories(a);
113 void Timer::DoDecision() {
114 for (std::map<int, TimeListener*>::iterator agent = tickers_.begin();
115 agent != tickers_.end();
117 agent->second->Decision();
121 void Timer::RecordInventories(
Agent* a) {
123 Inventories::iterator it2;
124 for (it2 = invs.begin(); it2 != invs.end(); ++it2) {
126 std::vector<Resource::Ptr> mats = it2->second;
127 if (mats.empty() || ResCast<Material>(mats[0]) == NULL) {
132 for (
int i = 1; i < mats.size(); i++) {
133 m->Absorb(ResCast<Material>(mats[i]->Clone()));
135 RecordInventory(a, name, m);
143 CompMap::iterator it;
144 for (it = c.begin(); it != c.end(); ++it) {
147 ->AddVal(
"Time", time_)
148 ->
AddVal(
"InventoryName", name)
149 ->
AddVal(
"NucId", it->first)
150 ->
AddVal(
"Quantity", it->second)
151 ->
AddVal(
"Units", m->units())
159 ctx_->
NewDatum(
"ExplicitInventoryCompact")
161 ->AddVal(
"Time", time_)
162 ->
AddVal(
"InventoryName", name)
163 ->
AddVal(
"Quantity", m->quantity())
164 ->AddVal(
"Units", m->units())
165 ->AddVal(
"Composition", c)
170 void Timer::DoDecom() {
172 std::vector<Agent*> decom_list = decom_queue_[time_];
173 for (
int i = 0; i < decom_list.size(); ++i) {
174 Agent* m = decom_list[i];
175 if (m->
parent() != NULL) {
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).");
258 Timer::Timer() : time_(0), si_(0), want_snapshot_(false), want_kill_(false) {}
Information helpful for simulation users and developers alike.
virtual void Decommission()
Decommissions the agent, removing it from the simulation.
const int enter_time() const
Returns the time step at which this agent's Build function was called (-1 if the agent has never been...
int branch_time
timestep at which simulation branching occurs if any
For values that are too big, too small, etc.
void RegisterTimeListener(TimeListener *agent)
Registers an agent to receive tick/tock notifications every timestep.
boost::shared_ptr< Material > Ptr
virtual const int id() const
The agent instance's unique ID within a simulation.
std::string name(int nuc)
int duration
length of the simulation in timesteps (months)
The ExchangeManager is designed to house all of the internals involved in executing a resource exchan...
void UnregisterTimeListener(TimeListener *tl)
Removes an agent from receiving tick/tock notifications.
int dur()
Returns the duration of the simulation this Timer's timing.
virtual void DecomNotify(Agent *m)
Called when a child of this agent is about to be decommissioned.
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
void Reset()
resets all data (registered listeners, etc.) to empty or initial state
virtual void Build(Agent *parent)
Called when the agent enters the smiulation as an active participant and is only ever called once...
bool explicit_inventory
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i...
std::map< std::string, std::vector< Resource::Ptr > > Inventories
map<inventory_name, vector<resources_in_inventory> >.
virtual const int id() const =0
int parent(int nuc, unsigned int rx, std::string z="n")
void Initialize(Context *ctx, SimInfo si)
Sets intial time-related parameters for the simulation.
Information helpful for simulation users and developers alike - least verbose.
T * CreateAgent(std::string proto_name)
Create a new agent by cloning the named prototype.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
int m0
start month for the simulation: Jan = 1, ..., Dec = 12
static void Snapshot(Context *ctx)
Records a snapshot of the current state of the simulation being managed by ctx into the simulation's ...
Agent * parent() const
Returns parent of this agent. Returns NULL if the agent has no parent.
int time()
Returns the current time, in months since the simulation started.
The TimeListener class is an inheritable class for any Agent that requires knowlege of ticks and tock...
void Execute()
execute the full resource sequence
void RunSim()
Runs the simulation.
Use to report questionable simulation state (use extremely sparingly)
Container for a static simulation-global parameters that both describe the simulation and affect its ...
Code providing rudimentary logging capability for the Cyclus core.
A simulation context provides access to necessary simulation-global functions and state...
bool explicit_inventory_compact
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i...
The abstract base class used by all types of agents that live and interact in a simulation.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
debugging information - least verbose
Information helpful for simulation users and developers alike.
void Record()
Record this datum to its Recorder.
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 SchedDecom(Agent *m, int time)
Schedules the given Agent to be decommissioned at the specified timestep t.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
virtual Inventories SnapshotInv()=0
Snapshots an agent's resource inventories to the database.
void Normalize(CompMap *v, double val)
The sum of quantities of all nuclides of v is normalized to val.
enable_if< has_const_iterator< T >::value, typename T::const_iterator >::type begin(const T &c)