5#include <boost/uuid/uuid_generators.hpp>
95 if (solver_ != NULL) {
103 std::vector<Agent*> to_del;
104 std::set<Agent*>::iterator it;
105 for (it = agent_list_.begin(); it != agent_list_.end(); ++it) {
106 if ((*it)->parent() == NULL) {
107 to_del.push_back(*it);
110 for (
int i = 0; i < to_del.size(); ++i) {
116 int n = agent_list_.erase(m);
130 int pid = (parent != NULL) ? parent->id() : -1;
131 ti_->SchedBuild(parent, proto_name, t);
134 ->
AddVal(
"Prototype", proto_name)
147 ti_->SchedDecom(m, t);
157 return rec_->sim_id();
165 if (!overwrite && protos_.find(name) != protos_.end()) {
166 throw KeyError(
"Prototype name " + name +
" has already been added" +
167 " and cannot be overwritten.");
174 ->
AddVal(
"Prototype", name)
179 std::string spec = p->
spec();
180 if (rec_ver_.count(spec) == 0) {
181 rec_ver_.insert(spec);
193 ->
AddVal(
"QualId", c->id())
198 if (recipes_.count(name) == 0) {
199 throw KeyError(
"Invalid recipe name " + name);
201 return recipes_[name];
205 std::string strategy) {
206 if (packages_.count(name) == 0) {
208 packages_[name] = pkg;
211 throw KeyError(
"Package " + name +
" already exists!");
217 ->
AddVal(
"PackageName", pkg->name())
218 ->
AddVal(
"FillMin", pkg->fill_min())
219 ->
AddVal(
"FillMax", pkg->fill_max())
220 ->
AddVal(
"Strategy", pkg->strategy())
228 if (packages_.size() == 0 ) {
229 throw KeyError(
"No user-created packages exist");
231 if (packages_.count(name) == 0) {
232 throw KeyError(
"Invalid package name " + name);
234 return packages_[name];
238 std::string strategy) {
239 if (transport_units_.count(name) == 0) {
242 transport_units_[name] = tu;
245 throw KeyError(
"TransportUnit " + name +
" already exists!");
251 ->
AddVal(
"TransportUnitName", tu->name())
252 ->
AddVal(
"FillMin", tu->fill_min())
253 ->
AddVal(
"FillMax", tu->fill_max())
254 ->
AddVal(
"Strategy", tu->strategy())
263 if (transport_units_.size() == 0 ) {
264 throw KeyError(
"No user-created transport units exist");
266 if (transport_units_.count(name) == 0) {
267 throw KeyError(
"Invalid transport unit name " + name);
269 return transport_units_[name];
305 ->
AddVal(
"DurationSecs",
static_cast<int>(si.
dt))
318 ti_->Initialize(
this, si);
319 rng_->Initialize(si);
328 return rng_->random();
332 return rng_->random_01();
336 return rng_->random_uniform_int(low, high);
340 return rng_->random_uniform_real(low, high);
345 return rng_->random_normal_real(mean, std_dev, low, high);
350 return rng_->random_normal_int(mean, std_dev, low, high);
354 ti_->RegisterTimeListener(tl);
358 ti_->UnregisterTimeListener(tl);
362 return rec_->NewDatum(title);
std::string spec()
The string representation of the agent spec that uniquely identifies the concrete agent class/module.
virtual const int id() const
The agent instance's unique ID within a simulation.
virtual std::string version()
boost::shared_ptr< Composition > Ptr
Context(Timer *ti, Recorder *rec)
Creates a new context working with the specified timer and datum manager.
void SchedBuild(Agent *parent, std::string proto_name, int t=-1)
Schedules the named prototype to be built for the specified parent at timestep t.
void KillSim()
Schedules the simulation to be terminated at the end of this timestep.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
boost::uuids::uuid sim_id()
See Recorder::sim_id documentation.
void Snapshot()
Schedules a snapshot of simulation state to output database to occur at the beginning of the next tim...
void AddPrototype(std::string name, Agent *m)
Adds a prototype to a simulation-wide accessible list, a prototype can not be added more than once.
void DelAgent(Agent *m)
Destructs and cleans up m (and it's children recursively).
Composition::Ptr GetRecipe(std::string name)
Retrieve a registered recipe.
Package::Ptr GetPackage(std::string name)
Retrieve a registered package.
double random_01()
Generates a random number on the range [0,1)].
int random_normal_int(double mean, double std_dev, int low=0, int high=std::numeric_limits< int >::max())
Returns a random number from a lognormal distribution.
double random_normal_real(double mean, double std_dev, double low=0, double high=std::numeric_limits< double >::max())
Returns a random number from a normal distribution.
int random_uniform_int(int low, int high)
Returns a random number from a uniform integer distribution.
~Context()
Clean up resources including destructing the solver and all agents the context is aware of.
void AddRecipe(std::string name, Composition::Ptr c)
Adds a composition recipe to a simulation-wide accessible list.
void AddTransportUnit(std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first")
Adds a transport unit type to a simulation-wide accessible list.
void RecordTransportUnit(TransportUnit::Ptr)
Records transport unit information.
TransportUnit::Ptr GetTransportUnit(std::string name)
Retrieve a registered transport unit.
void AddPackage(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
Adds a package type to a simulation-wide accessible list.
virtual int time()
Returns the current simulation timestep.
void RegisterTimeListener(TimeListener *tl)
Registers an agent to receive tick/tock notifications every timestep.
double random_uniform_real(double low, double high)
Returns a random number from a uniform real distribution.
void RecordPackage(Package::Ptr)
Records package information.
void SchedDecom(Agent *m, int time=-1)
Schedules the given Agent to be decommissioned at the specified timestep t.
void InitSim(SimInfo si)
Initializes the simulation time parameters.
void UnregisterTimeListener(TimeListener *tl)
Removes an agent from receiving tick/tock notifications.
Used to specify and send a collection of key-value pairs to the Recorder for recording.
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.
For failed retrieval/insertion of key-based data into/from data structures.
static Ptr Create(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
static Ptr & unpackaged()
boost::shared_ptr< Package > Ptr
static std::string unpackaged_name()
A random number generator.
Collects and manages output data generation for the cyclus core and agents during a simulation.
Container for a static simulation-global parameters that both describe the simulation and affect its ...
double eps_rsrc
Epsilon for resources in the simulation.
int y0
start year for the simulation (e.g. 1973);
int m0
start month for the simulation: Jan = 1, ..., Dec = 12
bool explicit_inventory_compact
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i....
boost::uuids::uuid parent_sim
id for the parent simulation if any
SimInfo()
constructs a SimInfo instance with default variables
double eps
Epsilon in the simulation.
std::string handle
user-defined label associated with a particular simulation
int duration
length of the simulation in timesteps (months)
uint64_t stride
Stride length.
uint64_t dt
Duration in seconds of a single time step in the simulation.
uint64_t seed
Seed for random number generator.
std::string decay
"manual" if use of the decay function is allowed, "never" otherwise
std::string parent_type
One of "init", "branch", "restart" indicating the relationship of this simulation to its parent simul...
int branch_time
timestep at which simulation branching occurs if any
bool explicit_inventory
True if per-agent inventories should be explicitly queried/recorded every time step in a table (i....
static void SnapAgent(Agent *m)
Records a snapshot of the agent's current internal state into the simulation's output database.
The TimeListener class is an inheritable class for any Agent that requires knowlege of ticks and tock...
static std::string unrestricted_name()
boost::shared_ptr< TransportUnit > Ptr
static Ptr Create(std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first")
create a new transport unit type.
static Ptr & unrestricted()
const uint64_t kDefaultSeed
const uint64_t kDefaultStride
const uint64_t kDefaultTimeStepDur
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
double cy_eps_rsrc
epsilon values to be used by resources
double cy_eps
generic epsilon values
void PyDelAgent(int i)
Removes a single Python agent from the reference cache.