11 this->fileName = fileName;
12 this->inpFileName = inpFileName;
14 this->doc =
new XMLDocument();
16 doc->InsertFirstChild(root);
23 fileName = obj.fileName;
27 inpFileName = obj.inpFileName;
41 if(doc ==
nullptr || !CloneInputFile())
45 root->InsertEndChild(log);
46 return (doc->SaveFile(fileName.c_str()) == XMLError::XML_SUCCESS);
61 log->InsertFirstChild(tmpsum);
67 const std::unordered_map<
int, std::vector<Point>> &goalsLog,
68 const std::unordered_map<
int, std::pair<bool, int>> &resultsLog)
72 XMLElement *tmpagent, *tmppath, *tmpstep;
75 for(
auto &agentPath : stepsLog)
84 for(
int i = 0; i < agentPath.second.size(); i++)
86 Point step = agentPath.second[i];
92 tmpstep->SetAttribute(
"next.xr", goalsLog.at(agentPath.first)[i].X());
93 tmpstep->SetAttribute(
"next.yr", goalsLog.at(agentPath.first)[i].Y());
96 tmppath->InsertEndChild(tmpstep);
99 tmpagent->InsertEndChild(tmppath);
100 log->InsertEndChild(tmpagent);
109 str.append(inpFileName);
110 size_t found = str.find_last_of(
".");
111 std::string piece =
"_" + std::to_string(agentsNum) +
"_log";
112 if (found != std::string::npos)
113 str.insert(found, piece);
123 bool XMLLogger::CloneInputFile()
126 if(file.LoadFile(inpFileName.c_str()) == XMLError::XML_SUCCESS)
128 XMLNode *prev =
nullptr;
129 for(XMLNode *node = file.RootElement()->FirstChild(); node; node = node->NextSibling())
131 XMLNode *clone = node->DeepClone(doc);
133 doc->RootElement()->InsertFirstChild(clone);
135 doc->RootElement()->InsertAfterChild(prev, clone);
static std::string GenerateLogFileName(std::string inpFileName, int agentsNum)
Creates a string of form "inpFileName_agentsNum_log.xml".
void SetSummary(const Summary &res) override
Sets brief information about execution results.
XMLLogger class implements interface for system state logging to XML-file.
#define CNS_TAG_ATTR_STEPS
XML tag or attribute.
int collisions
Shows the number of collisions between agents while execution of task.
float successRate
Shows the percent of agents, which succsed their tasks.
Class Summary contains brief information about execution results.
#define CNS_TAG_LOG
XML tag or attribute.
float runTime
Shows the time of running of task.
void SetResults(const std::unordered_map< int, std::vector< Point >> &stepsLog, const std::unordered_map< int, std::vector< Point >> &goalsLog, const std::unordered_map< int, std::pair< bool, int >> &resultsLog) override
Sets full information about execution, including states on each step, curren goals on each step...
File contains XMLLogger class.
float Y() const
Returns Y-coordinate of the point.
#define CNS_TAG_ATTR_COL_AGNT
XML tag or attribute.
XMLLogger()
XMLLogger default constructor.
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
#define CNS_TAG_ATTR_COL_OBST
XML tag or attribute.
#define CNS_TAG_ATTR_SR
XML tag or attribute.
bool GenerateLog() override
Method for creating final log in XML-file.
#define CNS_TAG_ATTR_RUNTIME
XML tag or attribute.
float makeSpan
Shows the maximum value of time steps of amoung all agents.
float flowTime
Shows the sum of time steps of all agents.
#define CNS_TAG_ATTR_X
XML tag or attribute.
#define CNS_TAG_SUM
XML tag or attribute.
#define CNS_TAG_ROOT
Enable full output to std stream.
#define CNS_TAG_ATTR_ID
XML tag or attribute.
#define CNS_TAG_ATTR_PATHFOUND
XML tag or attribute.
#define CNS_TAG_STEP
XML tag or attribute.
#define CNS_TAG_AGENT
XML tag or attribute.
#define CNS_TAG_ATTR_FLOWTIME
XML tag or attribute.
float X() const
Returns X-coordinate of the point.
XMLLogger * Clone() const override
Method for cloning objects. Implementations of this method creates copy of object in memmory and retu...
#define CNS_TAG_PATH
XML tag or attribute.
#define CNS_TAG_ATTR_MAKESPAN
XML tag or attribute.
#define CNS_TAG_ATTR_Y
XML tag or attribute.
#define CNS_TAG_ATTR_NUM
XML tag or attribute.
~XMLLogger() override
XMLLogger destructor.
int collisionsObst
Shows the number of collisions between agents and static obstacles while execution of task...