The abstract base class used by all types of agents that live and interact in a simulation.
There are several functions that must be implemented in support of simulation initialization, snapshotting and restart: InfileToDb, InitFrom(QueryableBackend*), Snapshot, SnapshotInv, and InitInv. These functions all do inter-related things. Notably, the InfileToDb, InitFrom, and Snapshot functions must all write/read to/from the same database tables (and table schemas).
Definition at line 49 of file agent.h.
void cyclus::Agent::Build |
( |
Agent * | parent | ) |
|
|
virtual |
Called when the agent enters the smiulation as an active participant and is only ever called once.
Agents should NOT register for services (such as ticks/tocks and resource exchange) in this function. If agents implement this function, they must call their superclass' Build function at the BEGINING of their Build function.
- Parameters
-
parent | this agent's parent. NULL if this agent has no parent. |
Reimplemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 153 of file agent.cc.
void cyclus::Agent::Decommission |
( |
| ) |
|
|
virtual |
Decommissions the agent, removing it from the simulation.
Results in destruction of the agent object. If agents write their own Decommission function, they must call their superclass' Decommission function at the END of their Decommission function.
Reimplemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 182 of file agent.cc.
void cyclus::Agent::EnterNotify |
( |
| ) |
|
|
virtual |
Called to give the agent an opportunity to register for services (e.g.
ticks/tocks and resource exchange). Note that this may be called more than once, and so agents should track their registrations carefully. If agents implement this function, they must call their superclass's EnterNotify function at the BEGINNING of their EnterNotify function.
Reimplemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 166 of file agent.cc.
const int cyclus::Agent::exit_time |
( |
| ) |
const |
|
inline |
Returns the default time step at which this agent will exit the simulation (-1 if the agent has an infinite lifetime).
Deomissioning happens at the end of a time step. With a lifetime of 1, we expect an agent to go through only 1 entire time step. In this case, the agent should be decommissioned on the same time step it was created. Therefore, for agents with non-infinite lifetimes, the exit_time will be the enter time plus its lifetime less 1.
Definition at line 405 of file agent.h.
Translates info for the agent from an input file to the database by reading parameters from the passed InfileTree (parsed from xml) and recording data via the DbInit variable.
The simulation id and agent id are automatically injected in all data transfered to the database through DbInit. This function must be implemented by all agents. This function must call the superclass' InfileToDb function before doing any other work.
Agent parameters in the InfileTree are scoped in the "agent/*‍/" path. The superclass InitFrom expects the scope InfileTree passed to it to be unchanged from the agent's InfileTree arg.
Example:
tree = tree->Query("agent/*");
std::string recipe = tree->
GetString(
"recipe");
std::string in_commod = tree->
GetString(
"in_commod");
->
AddVal(
"in_commod", in_commod)
};
};
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.
DbInit provides an interface for agents to record data to the output db that automatically injects th...
Datum * NewDatum(std::string title)
Returns a new datum to be used exactly as the Context::NewDatum method.
The Facility class is the abstract class/interface used by all facility agents.
virtual void InitFrom(QueryableBackend *b)
Intializes an agent's internal state from the database.
A class for extracting information from a given XML parser.
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
T Query(InfileTree *tree, std::string query, int index=0)
a query method for required parameters
- Warning
- because 'SimId' 'SimTime', and 'AgentId' fields are automatically injected, those labels cannot be used for any other fields.
-
this function MUST NOT modify the agent's state.
Implements cyclus::StateWrangler.
Reimplemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 36 of file agent.cc.
Intializes an agent's internal state from the database.
Appropriate simulation id, agent id, and time filters are automatically included in all queries. If the agent is a direct subclass of the Agent class, than it should NOT call its superclass' InitFrom(QueryableBackend*) function. If, however, it is a subclasses other Agent subclasses (e.g. subclass of Facility, Region, etc.), then it MUST call its superclass' InitFrom(QueryableBackend*) function. Example:
recipe = qr.
GetVal<std::string>(
"recipe");
in_commod = qr.
GetVal<std::string>(
"in_commod");
cap = qr.
GetVal<
double>(
"cap");
};
std::string recipe;
std::string in_commod;
double cap;
};
Meta data and results of a query.
T GetVal(std::string field, int row=0)
Convenience method for retrieving a value from a specific row and named field (column).
Interface implemented by backends that support rudimentary querying.
- Warning
- Agents should NOT create any resource objects in this function.
Implements cyclus::StateWrangler.
Reimplemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 45 of file agent.cc.
void cyclus::Agent::Snapshot |
( |
DbInit | di | ) |
|
|
pure virtual |
Snapshots agent-internal state to the database via the DbInit var di.
The simulation id , agent id, and the simulation time are automatically injected in all information transfered to the database through DbInit. If the agent is a direct subclass of the Agent class, than it should NOT call its superclass' Snapshot function. If, however, it subclasses other Agent subclasses (e.g. subclass of Facility, Region, etc.), then it MUST call its superclass' Snapshot function. Example:
->
AddVal(
"in_commod", in_commod)
};
std::string recipe;
std::string in_commod;
double cap;
};
virtual void Snapshot(DbInit di)
Snapshots agent-internal state to the database via the DbInit var di.
- Warning
- because 'SimId' 'SimTime', and 'AgentId' fields are automatically injected, those labels cannot be used for any other fields.
-
This function MUST NOT modify the agent's internal state.
-
Do not record any information via the context's NewDatum function.
Implements cyclus::StateWrangler.
Implemented in cyclus::Facility, cyclus::Institution, and cyclus::Region.
Definition at line 52 of file agent.cc.