1#ifndef CYCLUS_SRC_CONTEXT_H_
2#define CYCLUS_SRC_CONTEXT_H_
13#include <boost/uuid/uuid_generators.hpp>
41class RandomNumberGenerator;
68 std::string
handle, std::string
d);
147 friend class ::SimInitTest;
161 boost::uuids::uuid
sim_id();
186 inline const std::set<Trader*>&
traders()
const {
209 casted =
dynamic_cast<T*
>(clone);
260 void AddPackage(std::string name,
double fill_min = 0,
261 double fill_max = std::numeric_limits<double>::max(),
262 std::string strategy =
"first");
274 int fill_max = std::numeric_limits<int>::max(),
275 std::string strategy =
"first");
297 double high=std::numeric_limits<double>::max());
301 int high=std::numeric_limits<int>::max());
334 if (solver_ ==
NULL) {
349 return n_prototypes_[type];
355 return n_specs_[
impl];
360 inline void RegisterAgent(
Agent*
a) {
361 n_prototypes_[
a->prototype()]++;
362 n_specs_[
a->spec()]++;
366 inline void UnregisterAgent(
Agent*
a) {
367 n_prototypes_[
a->prototype()]--;
368 n_specs_[
a->spec()]--;
373 std::set<std::string> rec_ver_;
375 std::map<std::string, Agent*> protos_;
376 std::map<std::string, Composition::Ptr> recipes_;
377 std::map<std::string, Package::Ptr> packages_;
378 std::map<std::string, TransportUnit::Ptr> transport_units_;
379 std::set<Agent*> agent_list_;
380 std::set<Trader*> traders_;
381 std::map<std::string, int> n_prototypes_;
382 std::map<std::string, int> n_specs_;
386 ExchangeSolver* solver_;
389 RandomNumberGenerator* rng_;
The abstract base class used by all types of agents that live and interact in a simulation.
virtual Agent * Clone()=0
Returns a newly created/allocated prototype that is an exact copy of this.
virtual const int id() const
The agent instance's unique ID within a simulation.
For failed casts that shouldn't.
boost::shared_ptr< Composition > Ptr
A simulation context provides access to necessary simulation-global functions and state.
void UnregisterTrader(Trader *e)
Unregisters an agent as a participant in resource exchanges.
Context(Timer *ti, Recorder *rec)
Creates a new context working with the specified timer and datum manager.
const std::set< Trader * > & traders() const
T * CreateAgent(std::string proto_name)
Create a new agent by cloning the named prototype.
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.
void RegisterTrader(Trader *e)
Registers an agent as a participant in resource exchanges.
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...
uint64_t stride()
Returns the stride for the random number generator.
ExchangeSolver * solver()
Returns the exchange solver associated with this context.
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.
void solver(ExchangeSolver *solver)
sets the solver associated with this context
SimInfo sim_info() const
Return static simulation info.
uint64_t dt()
Returns the duration of a single time step in seconds.
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.
uint64_t seed()
Returns the seed for the random number generator.
int n_prototypes(std::string type)
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.
int n_specs(std::string impl)
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.
a very simple interface for solving translated resource exchanges
void sim_ctx(Context *c)
simulation context get/set
The GreedySolver provides the implementation for a "greedy" solution to a resource exchange graph.
For failed retrieval/insertion of key-based data into/from data structures.
boost::shared_ptr< Package > Ptr
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....
Handles initialization of a simulation from the output database.
For failed object state expectations.
The TimeListener class is an inheritable class for any Agent that requires knowlege of ticks and tock...
Controls simulation timestepping and inter-timestep phases.
A simple API for agents that wish to exchange resources in the simulation.
boost::shared_ptr< TransportUnit > Ptr
const uint64_t kDefaultSeed
const uint64_t kDefaultStride
const uint64_t kDefaultTimeStepDur
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
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