4#include <boost/uuid/uuid_generators.hpp>
27 explicit_inventory(
false),
28 explicit_inventory_compact(
false),
42 explicit_inventory(
false),
43 explicit_inventory_compact(
false),
57 explicit_inventory(
false),
58 explicit_inventory_compact(
false),
65 int branch_time, std::string parent_type,
72 parent_sim(parent_sim),
73 parent_type(parent_type),
74 branch_time(branch_time),
75 explicit_inventory(
false),
76 explicit_inventory_compact(
false),
91 if (solver_ !=
NULL) {
99 std::vector<Agent*>
to_del;
100 std::set<Agent*>::iterator
it;
101 for (
it = agent_list_.begin();
it != agent_list_.end(); ++
it) {
102 if ((*it)->parent() ==
NULL) {
106 for (
int i = 0; i <
to_del.size(); ++i) {
112 int n = agent_list_.erase(m);
124 int pid = (parent !=
NULL) ? parent->id() : -1;
155 if (!
overwrite && protos_.find(name) != protos_.end()) {
156 throw KeyError(
"Prototype name " + name +
" has already been added" +
157 " and cannot be overwritten.");
164 ->
AddVal(
"Prototype", name)
169 std::string spec =
p->spec();
170 if (rec_ver_.count(spec) == 0) {
171 rec_ver_.insert(spec);
174 ->
AddVal(
"Version",
p->version())
188 if (recipes_.count(name) == 0) {
189 throw KeyError(
"Invalid recipe name " + name);
191 return recipes_[name];
195 std::string strategy) {
196 if (packages_.count(name) == 0) {
198 packages_[name] =
pkg;
201 throw KeyError(
"Package " + name +
" already exists!");
218 if (packages_.size() == 0 ) {
219 throw KeyError(
"No user-created packages exist");
221 if (packages_.count(name) == 0) {
222 throw KeyError(
"Invalid package name " + name);
224 return packages_[name];
228 std::string strategy) {
229 if (transport_units_.count(name) == 0) {
232 transport_units_[name] =
tu;
235 throw KeyError(
"TransportUnit " + name +
" already exists!");
241 ->
AddVal(
"TransportUnitName",
tu->name())
244 ->
AddVal(
"Strategy",
tu->strategy())
253 if (transport_units_.size() == 0 ) {
254 throw KeyError(
"No user-created transport units exist");
256 if (transport_units_.count(name) == 0) {
257 throw KeyError(
"Invalid transport unit name " + name);
259 return transport_units_[name];
269 ->
AddVal(
"Seed",
static_cast<int>(
si.seed))
270 ->
AddVal(
"Stride",
static_cast<int>(
si.stride))
271 ->
AddVal(
"ParentSimId",
si.parent_sim)
272 ->
AddVal(
"ParentType",
si.parent_type)
273 ->
AddVal(
"BranchTime",
si.branch_time)
288 ->
AddVal(
"RecordInventory",
si.explicit_inventory)
289 ->
AddVal(
"RecordInventoryCompact",
si.explicit_inventory_compact)
295 ->
AddVal(
"DurationSecs",
static_cast<int>(
si.dt))
300 ->
AddVal(
"ResourceEpsilon",
si.eps_rsrc)
The abstract base class used by all types of agents that live and interact in a simulation.
virtual const int id() const
The agent instance's unique ID within a simulation.
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.
double random_01()
wrappers for boost::random distributions
int random_uniform_int(int low, int high)
generate a random integer between [low, high)
double random_uniform_real(double low, double high)
generate a random real number between [low, high)
void Initialize(SimInfo si)
Initialize from seed.
double random_normal_real(double mean, double std_dev, double low=0, double high=std::numeric_limits< double >::max())
generate a double from a normal distribution, with truncation at low and high
int random_normal_int(double mean, double std_dev, int low=0, int high=std::numeric_limits< int >::max())
generates an integer from a normal distribution, with truncation uses rounding to convert double to i...
Collects and manages output data generation for the cyclus core and agents during a simulation.
boost::uuids::uuid sim_id()
returns the unique id associated with this cyclus simulation.
Datum * NewDatum(std::string title)
Creates a new datum namespaced under the specified title.
Container for a static simulation-global parameters that both describe the simulation and affect its ...
SimInfo()
constructs a SimInfo instance with default variables
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...
Controls simulation timestepping and inter-timestep phases.
void KillSim()
Schedules the simulation to be terminated at the end of this timestep.
int time()
Returns the current time, in months since the simulation started.
void Snapshot()
Schedules a snapshot of simulation state to output database to occur at the beginning of the next tim...
void UnregisterTimeListener(TimeListener *tl)
Removes an agent from receiving tick/tock notifications.
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 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.
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.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters