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 51 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::Region, and cyclus::Institution.
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::Region, and cyclus::Institution.
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::Region, and cyclus::Institution.
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 407 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/*");
*
* double cap = cyclus::Query<double>(tree, "cap");
* ->
AddVal(
"in_commod", in_commod)
*
* };
*
* };
*
- 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::Region, and cyclus::Institution.
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:
cap = qr.
GetVal<
double>(
"cap");
};
double cap;
};
- Warning
- Agents should NOT create any resource objects in this function.
Implements cyclus::StateWrangler.
Reimplemented in cyclus::Facility, cyclus::Region, and cyclus::Institution.
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)
};
double cap;
};
- 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::Region, and cyclus::Institution.
Definition at line 52 of file agent.cc.