17int 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"
37 std::string proto = qe->
GetString(
"name");
40 ->AddVal(
"Prototype",
proto)
47 prototype_ =
qr.GetVal<std::string>(
"Prototype");
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");
141 std::set<Agent*>::const_iterator
it =
children.begin();
155 <<
"' is entering the simulation.";
161 enter_time_ = ctx_->
time();
167 ctx_->RegisterAgent(
this);
170void Agent::Connect(
Agent* parent) {
173 "is trying to add itself as its own child.");
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) {
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());
226void Agent::AddToTable() {
231 ->
AddVal(
"Prototype", prototype_)
232 ->
AddVal(
"ParentId", parent_id_)
233 ->
AddVal(
"Lifetime", lifetime_)
234 ->
AddVal(
"EnterTime", enter_time_)
The abstract base class used by all types of agents that live and interact in a simulation.
virtual void InitFrom(QueryableBackend *b)
Intializes an agent's internal state from the database.
const std::string prototype() const
Returns the agent's prototype.
virtual void Build(Agent *parent)
Called when the agent enters the smiulation as an active participant and is only ever called once.
Agent(Context *ctx)
Creates a new agent that is managed by the given context.
std::vector< std::string > GetTreePrintOuts(Agent *m)
returns a vector of strings representing the parent-child tree at the node for Agent m
Context * context() const
Returns this agent's simulation context.
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...
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 int lifetime() const
Returns the number of time steps this agent operates between building and decommissioning (-1 if the ...
const std::set< Agent * > & children() const
Returns a list of children this agent has.
virtual const int id() const
The agent instance's unique ID within a simulation.
virtual void Decommission()
Decommissions the agent, removing it from the simulation.
virtual void Snapshot(DbInit di)=0
Snapshots agent-internal state to the database via the DbInit var di.
std::string PrintChildren()
recursively prints the parent-child tree
virtual ~Agent()
Removes references to self from simulation context, parent, children, etc.
bool InFamilyTree(Agent *other)
returns true if this agent is in the parent-child family tree of an other agent
std::string kind_
describes the agent subclass (e.g.
virtual void EnterNotify()
Called to give the agent an opportunity to register for services (e.g.
Agent * parent() const
Returns parent of this agent. Returns NULL if the agent has no parent.
virtual std::string str()
Description of this agent.
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...
void lifetime_force(int n_timesteps)
Sets the number of time steps this agent operates between building and decommissioning (-1 if the age...
A simulation context provides access to necessary simulation-global functions and state.
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
void DelAgent(Agent *m)
Destructs and cleans up m (and it's children recursively).
virtual int time()
Returns the current simulation timestep.
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...
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...
For failed retrieval/insertion of key-based data into/from data structures.
Meta data and results of a query.
Interface implemented by backends that support rudimentary querying.
For values that are too big, too small, etc.
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
@ LEV_DEBUG3
debugging information
@ LEV_INFO3
Information helpful for simulation users and developers alike.
@ LEV_DEBUG1
debugging information - least verbose
@ LEV_DEBUG2
debugging information
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters