17 int Agent::next_id_ = 0;
20 prototype_ = m->prototype_;
23 lifetime_ = m->lifetime_;
28 std::stringstream ret;
29 ret <<
"A(n) " << spec_ <<
" named " << prototype_
31 <<
" received the following error:\n" 38 int lifetime = OptionalQuery<int>(qe,
"lifetime", -1);
40 ->
AddVal(
"Prototype", proto)
41 ->
AddVal(
"Lifetime", lifetime)
48 id_ = qr.
GetVal<
int>(
"AgentId");
49 lifetime_ = qr.
GetVal<
int>(
"Lifetime");
54 ->
AddVal(
"Prototype", prototype_)
55 ->
AddVal(
"Lifetime", lifetime_)
67 spec_(
"UNSPECIFIED") {
68 ctx_->agent_list_.insert(
this);
69 MLOG(
LEV_DEBUG3) <<
"Agent ID=" << id_ <<
", ptr=" <<
this <<
" created.";
74 context()->agent_list_.erase(
this);
76 std::set<Agent*>::iterator it;
77 if (parent_ != NULL) {
80 <<
" has removed child '" <<
prototype() <<
"' ID=" 81 <<
id() <<
" from its list of children.";
82 it = find(parent_->children_.begin(), parent_->children_.end(),
this);
83 if (it != parent_->children_.end()) {
84 parent_->children_.erase(it);
89 for (it = children_.begin(); it != children_.end(); ++it) {
91 child->parent_ = NULL;
92 child->parent_id_ = -1;
98 ss <<
kind_ <<
"_" << prototype_
101 <<
", implementation=" << spec_
102 <<
", name=" << prototype_
103 <<
", parentID=" << parent_id_
109 if (enter_time_ != -1) {
110 throw ValueError(
"cannot set the lifetime of an already-built facility");
112 lifetime_ = n_timesteps;
120 if(enter_time_+n_timesteps <=
context()->time()){
124 lifetime_ = n_timesteps;
131 while (other != NULL) {
141 std::set<Agent*>::const_iterator it = children.begin();
142 for (; it != children.end(); ++it) {
155 <<
"' is entering the simulation.";
161 enter_time_ = ctx_->
time();
167 ctx_->RegisterAgent(
this);
171 if (parent ==
this) {
173 "is trying to add itself as its own child.");
175 if (parent != NULL) {
177 parent_id_ = parent->
id();
178 parent->children_.insert(
this);
184 <<
" is being decommissioned";
189 ctx_->UnregisterAgent(
this);
194 std::stringstream ss(
"");
195 ss <<
"Children of " <<
prototype() <<
":" << std::endl;
197 std::set<Agent*>::iterator it;
198 for (it = children_.begin(); it != children_.end(); ++it) {
201 for (
int j = 0; j < print_outs.size(); j++) {
202 ss <<
"\t" << print_outs.at(j);
209 std::vector<std::string> ret;
210 std::stringstream ss(
"");
212 ret.push_back(ss.str());
213 std::set<Agent*>::iterator it;
214 for (it = children_.begin(); it != children_.end(); ++it) {
217 for (
int j = 0; j < outs.size(); j++) {
219 ss <<
"\t" << outs.at(j) << std::endl;
220 ret.push_back(ss.str());
226 void Agent::AddToTable() {
231 ->
AddVal(
"Prototype", prototype_)
232 ->
AddVal(
"ParentId", parent_id_)
233 ->
AddVal(
"Lifetime", lifetime_)
234 ->
AddVal(
"EnterTime", enter_time_)
virtual void Decommission()
Decommissions the agent, removing it from the simulation.
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
bool InFamilyTree(Agent *other)
returns true if this agent is in the parent-child family tree of an other agent
Meta data and results of a query.
virtual std::string str()
Description of this agent.
virtual void InfileToDb(InfileTree *qe, DbInit di)
Translates info for the agent from an input file to the database by reading parameters from the passe...
const std::string prototype() const
Returns the agent's prototype.
For values that are too big, too small, etc.
A class for extracting information from a given XML parser.
virtual const int id() const
The agent instance's unique ID within a simulation.
virtual std::string InformErrorMsg(std::string msg)
adds agent-specific information prefix to an error message
bool AncestorOf(Agent *other)
returns true if this agent is an ancestor of an other agent (i.e., resides above an other agent in th...
Datum * NewDatum(std::string title)
Returns a new datum to be used exactly as the Context::NewDatum method.
virtual ~Agent()
Removes references to self from simulation context, parent, children, etc.
std::vector< std::string > GetTreePrintOuts(Agent *m)
returns a vector of strings representing the parent-child tree at the node for Agent m ...
virtual void Build(Agent *parent)
Called when the agent enters the smiulation as an active participant and is only ever called once...
T GetVal(std::string field, int row=0)
Convenience method for retrieving a value from a specific row and named field (column).
int child(int nuc, unsigned int rx, std::string z="n")
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...
Agent(Context *ctx)
Creates a new agent that is managed by the given context.
virtual int time()
Returns the current simulation timestep.
virtual void EnterNotify()
Called to give the agent an opportunity to register for services (e.g.
Context * context() const
Returns this agent's simulation context.
std::string kind_
describes the agent subclass (e.g.
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
DbInit provides an interface for agents to record data to the output db that automatically injects th...
virtual void Snapshot(DbInit di)=0
Snapshots agent-internal state to the database via the DbInit var di.
bool DecendentOf(Agent *other)
returns true if this agent is an decendent of an other agent (i.e., resides below an other agent in t...
Agent * parent() const
Returns parent of this agent. Returns NULL if the agent has no parent.
const int lifetime() const
Returns the number of time steps this agent operates between building and decommissioning (-1 if the ...
Code providing rudimentary logging capability for the Cyclus core.
A simulation context provides access to necessary simulation-global functions and state...
virtual QueryResult Query(std::string table, std::vector< Cond > *conds)=0
Return a set of rows from the specificed table that match all given conditions.
The abstract base class used by all types of agents that live and interact in a simulation.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
void lifetime_force(int n_timesteps)
Sets the number of time steps this agent operates between building and decommissioning (-1 if the age...
debugging information - least verbose
Information helpful for simulation users and developers alike.
virtual void InitFrom(QueryableBackend *b)
Intializes an agent's internal state from the database.
void Record()
Record this datum to its Recorder.
const std::set< Agent * > & children() const
Returns a list of children this agent has.
Interface implemented by backends that support rudimentary querying.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
For failed retrieval/insertion of key-based data into/from data structures.
std::string PrintChildren()
recursively prints the parent-child tree
void DelAgent(Agent *m)
Destructs and cleans up m (and it's children recursively).