20 std::stringstream schema(
"");
22 std::string master = schema.str();
24 std::string subschemas;
25 for (
int i = 0; i < specs.size(); ++i) {
27 subschemas +=
"<element name=\"" + specs[i].alias() +
"\">\n";
28 subschemas += m->
schema() +
"\n";
29 subschemas +=
"</element>\n";
34 std::string search_str = std::string(
"@MODEL_SCHEMAS@");
35 size_t pos = master.find(search_str);
36 if (pos != std::string::npos) {
37 master.replace(pos, search_str.size(), subschemas);
45 std::vector<AgentSpec> specs =
ParseSpecs(infile);
67 int num_protos = xqe.
NMatches(
"/*/prototype");
68 for (
int i = 0; i < num_protos; i++) {
70 std::string prototype = qe->
GetString(
"name");
78 agent->Agent::InfileToDb(qe,
DbInit(agent,
true));
83 std::vector<Cond> conds;
84 conds.push_back(
Cond(
"SimId",
"==",
rec_->sim_id()));
85 conds.push_back(
Cond(
"AgentId",
"==", agent->
id()));
86 conds.push_back(
Cond(
"SimTime",
"==",
static_cast<int>(0)));
91 agent->Agent::InitFrom(&pi);
95 ctx_->AddPrototype(prototype, agent);
99 int num_agents = xqe.
NMatches(
"/*/agent");
100 std::map<std::string, std::string> protos;
101 std::map<std::string, std::string> parents;
102 std::set<std::string> agents;
103 std::map<std::string, InfileTree*> invs;
104 for (
int i = 0; i < num_agents; i++) {
106 std::string name = qe->
GetString(
"name");
107 std::string proto = qe->
GetString(
"prototype");
109 protos[name] = proto;
110 parents[name] = parent;
116 std::map<std::string, Agent*> built;
117 std::set<std::string>::iterator it = agents.begin();
118 while (agents.size() > 0) {
119 std::string name = *it;
120 std::string proto = protos[name];
121 std::string parent = parents[name];
126 }
else if (built.count(parent) > 0) {
127 built[name] =
BuildAgent(proto, built[parent]);
133 if (it == agents.end()) {
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.
virtual std::string schema()
Returns an agent's xml rng schema for initializing from input files.
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...
virtual const int id() const
The agent instance's unique ID within a simulation.
Wrapper class for QueryableBackends that injects a set of Cond's into every query before being execut...
Represents a condition used to filter rows returned by a query.
A simulation context provides access to necessary simulation-global functions and state.
void DelAgent(Agent *m)
Destructs and cleans up m (and it's children recursively).
DbInit provides an interface for agents to record data to the output db that automatically injects th...
static Agent * Make(Context *ctx, AgentSpec spec)
Returns a newly constructed agent for the given module spec.
A class for extracting information from a given XML parser.
virtual int NMatches(std::string query)
investigates the current status and returns the number of elements matching a query
virtual std::string GetElementName(int index=0)
investigates the current status and returns a string representing the name of a given index
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
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...
Wrapper class for QueryableBackends that injects prefix in front of the title/table for every query b...
Collects and manages output data generation for the cyclus core and agents during a simulation.
Controls simulation timestepping and inter-timestep phases.
boost::shared_ptr< XMLParser > parser_
the parser
std::string schema_path_
filepath to the schema
std::map< std::string, AgentSpec > specs_
Agent * BuildAgent(std::string proto, Agent *parent)
Creates and builds an agent, notifying its parent.
std::string file_
the input file name
void LoadInitialAgents()
Creates all initial agent instances from the input file.
virtual std::string master_schema()
Code providing rudimentary logging capability for the Cyclus core.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
std::string BuildFlatMasterSchema(std::string schema_path, std::vector< AgentSpec > specs)
Builds and returns a master cyclus input xml schema defining a flat prototype and instance structure ...
std::set< std::string > DiscoverSpecsInCyclusPath()
Discover archetype specifications that live recursively in CYCLUS_PATH directories.
void LoadStringstreamFromFile(std::stringstream &stream, std::string file, std::string format)
Reads the given file path as XML into the passed stream.
std::vector< AgentSpec > ParseSpecs(std::set< std::string > agent_set)
Returns a list of the full module+agent spec for all agents in the given set of agent names.
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters