12 this->fileName = fileName;
13 this->doc =
new XMLDocument();
14 this->allAgents =
new std::vector<Agent *>();
17 this->options =
nullptr;
19 this->obstacles =
nullptr;
21 this->plannertype = 0;
29 this->allAgents =
nullptr;
32 this->options =
nullptr;
34 this->obstacles =
nullptr;
36 this->plannertype = 0;
43 fileName = obj.fileName;
51 if(obj.doc !=
nullptr)
53 doc =
new XMLDocument();
54 obj.doc->DeepCopy(doc);
60 plannertype = obj.plannertype;
61 allAgents = (obj.allAgents ==
nullptr) ?
nullptr :
new std::vector<Agent *>(*(obj.allAgents));
62 map = (obj.map ==
nullptr) ?
nullptr :
new Map(*obj.map);
64 grid = (obj.grid ==
nullptr) ?
nullptr :
new std::vector<std::vector<int>>(*obj.grid);
65 obstacles = (obj.obstacles ==
nullptr) ?
nullptr :
new std::vector<std::vector<Point>>(*obj.obstacles);
72 if(allAgents !=
nullptr)
78 if(options !=
nullptr)
94 if(obstacles !=
nullptr)
112 if(this->map !=
nullptr)
125 if(this->options !=
nullptr)
127 *envOpt = this->options;
128 this->options =
nullptr;
138 if(allAgents ==
nullptr || allAgents->size() >= numThreshold)
141 for(
int i = 0; i < numThreshold; i++)
143 agents.push_back((*allAgents)[i]);
145 for(
int i = numThreshold; i < allAgents->size(); i++)
147 delete (*allAgents)[i];
162 if(doc ==
nullptr || allAgents ==
nullptr)
169 if(doc->LoadFile(fileName.c_str()) != XMLError::XML_SUCCESS)
171 std::cout <<
"Error opening input XML file\n";
178 std::cout <<
CNS_TAG_ROOT <<
" element not found in XML file\n";
182 return ReadMap() && ReadAlgorithmOptions() && ReadAgents();
189 fileName = obj.fileName;
195 if(obj.doc !=
nullptr)
197 doc =
new XMLDocument();
198 obj.doc->DeepCopy(doc);
207 if(allAgents !=
nullptr)
211 allAgents = (obj.allAgents ==
nullptr) ?
nullptr :
new std::vector<Agent *>(*(obj.allAgents));
217 map = (obj.map ==
nullptr) ?
nullptr :
new Map(*obj.map);
219 if(options !=
nullptr)
229 grid = (obj.grid ==
nullptr) ?
nullptr :
new std::vector<std::vector<int>>(*obj.grid);
231 if(obstacles !=
nullptr)
235 obstacles = (obj.obstacles ==
nullptr) ?
nullptr :
new std::vector<std::vector<Point>>(*obj.obstacles);
237 plannertype = obj.plannertype;
247 bool XMLReader::ReadMap()
249 XMLElement *tmpElement;
252 XMLElement *mapTag = 0, *element = 0, *mapnode, *obsts = 0, *obstElem = 0;
255 std::stringstream stream;
257 bool hasGridMem =
false, hasGrid =
false, hasHeight =
false, hasWidth =
false, hasCellSize =
false;
258 int height = -1, width = -1, rowIter = 0, gridI = 0, gridJ = 0, obstNum = -1, count = 0;
266 std::cout <<
CNS_TAG_MAP <<
" element not found in XML file\n";
270 for (mapnode = mapTag->FirstChildElement(); mapnode; mapnode = mapnode->NextSiblingElement())
272 element = mapnode->ToElement();
273 value = mapnode->Value();
274 std::transform(value.begin(), value.end(), value.begin(), ::tolower);
281 stream << element->GetText();
284 if (!hasGridMem && hasHeight && hasWidth)
286 grid =
new std::vector<std::vector<int>>(height);
287 for (
int i = 0; i < height; ++i)
288 (*grid)[i] = std::vector<int>(width);
297 std::cout <<
"Warning! Duplicate '" <<
CNS_TAG_HEIGHT <<
"' encountered." << std::endl;
298 std::cout <<
"Only first value of '" <<
CNS_TAG_HEIGHT <<
"' =" << height <<
"will be used." << std::endl;
303 if (!((stream >> height) && (height > 0)))
307 <<
"' tag encountered (or could not convert to integer)." << std::endl;
308 std::cout <<
"Value of '" <<
CNS_TAG_HEIGHT <<
"' tag should be an integer >=0" << std::endl;
309 std::cout <<
"Continue reading XML and hope correct value of '" <<
CNS_TAG_HEIGHT 310 <<
"' tag will be encountered later..." << std::endl;
324 std::cout <<
"Warning! Duplicate '" <<
CNS_TAG_WIDTH <<
"' encountered." << std::endl;
325 std::cout <<
"Only first value of '" <<
CNS_TAG_WIDTH <<
"' =" << width <<
"will be used." << std::endl;
330 if (!((stream >> width) && (width > 0)))
334 <<
"' tag encountered (or could not convert to integer)." << std::endl;
335 std::cout <<
"Value of '" <<
CNS_TAG_WIDTH <<
"' tag should be an integer AND >0" << std::endl;
336 std::cout <<
"Continue reading XML and hope correct value of '" <<
CNS_TAG_WIDTH 337 <<
"' tag will be encountered later..." << std::endl;
351 std::cout <<
"Warning! Duplicate '" <<
CNS_TAG_CELLSIZE <<
"' encountered." << std::endl;
352 std::cout <<
"Only first value of '" <<
CNS_TAG_CELLSIZE <<
"' =" << cellSize <<
"will be used." 357 if (!((stream >> cellSize) && (cellSize > 0))) {
360 <<
"' tag encountered (or could not convert to double)." << std::endl;
362 <<
"' tag should be double AND >0. By default it is defined to '1'" << std::endl;
363 std::cout <<
"Continue reading XML and hope correct value of '" <<
CNS_TAG_CELLSIZE 364 <<
"' tag will be encountered later..." << std::endl;
374 if (!(hasHeight && hasWidth))
380 element = mapnode->FirstChildElement();
381 while (gridI < height)
387 <<
"' tags should be equal (or greater) than the value of '" <<
CNS_TAG_HEIGHT 388 <<
"' tag which is " << height << std::endl;
391 std::string str = element->GetText();
392 std::vector<std::string> elems;
393 std::stringstream ss(str);
395 while (std::getline(ss, item,
' '))
397 elems.push_back(item);
401 if (elems.size() > 0)
403 for(gridJ = 0; gridJ < width; ++gridJ)
405 if(gridJ == elems.size())
411 stream << elems[gridJ];
413 (*grid)[gridI][gridJ] = val;
424 element = element->NextSiblingElement();
431 std::cout <<
CNS_TAG_GRID <<
" element not found in XML file\n";
439 std::cout <<
CNS_TAG_OBSTS <<
" element not found in XML file\n";
443 if (obsts->QueryIntAttribute(
CNS_TAG_ATTR_NUM, &obstNum) != XMLError::XML_SUCCESS)
449 obstacles =
new std::vector<std::vector<Point>>(obstNum);
452 for(count = 0; obstElem && count < obstNum; obstElem = obstElem->NextSiblingElement(
CNS_TAG_OBST), count++)
456 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_X, &oX) != XMLError::XML_SUCCESS)
461 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_Y, &oY) != XMLError::XML_SUCCESS)
466 (*obstacles)[count].push_back(
Point(oX, oY));
477 map =
new Map(cellSize, *grid, *obstacles);
481 bool XMLReader::ReadAlgorithmOptions()
483 XMLElement *tmpElement;
491 XMLElement *alg = root->FirstChildElement(
CNS_TAG_ALG);
494 std::cout <<
CNS_TAG_ALG <<
" element not found in XML file\n";
507 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_ST)) && tmpElement->GetText();
516 auto tmpst = std::string(tmpElement->GetText());
531 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_BT)) && (tmpElement->QueryBoolText(&(options->breakingties)) == XMLError::XML_SUCCESS);
539 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_AS)) && (tmpElement->QueryBoolText(&(options->allowsqueeze)) == XMLError::XML_SUCCESS);
547 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_CC)) && (tmpElement->QueryBoolText(&(options->cutcorners)) == XMLError::XML_SUCCESS);
555 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_HW)) && (tmpElement->QueryFloatText(&(options->hweight)) == XMLError::XML_SUCCESS);
563 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_TS)) && (tmpElement->QueryFloatText(&(options->timestep)) == XMLError::XML_SUCCESS);
571 tagFlag = (tmpElement = alg->FirstChildElement(
CNS_TAG_DEL)) && (tmpElement->QueryFloatText(&(options->delta)) == XMLError::XML_SUCCESS);
581 bool XMLReader::ReadAgents()
583 XMLElement *tmpElement;
598 if(agents->QueryIntAttribute(
CNS_TAG_ATTR_NUM, &agentsNumber) != XMLError::XML_SUCCESS)
603 if(agents->QueryStringAttribute(
CNS_TAG_ATTR_TYPE, &agType) != XMLError::XML_SUCCESS)
615 std::cout <<
CNS_TAG_DEF_PARAMS <<
" element not found in XML file. The following default values was defined\n";
673 float stx = 0, sty = 0, gx = 0, gy = 0;
675 for(count = 0; tmpElement; tmpElement = tmpElement->NextSiblingElement(
CNS_TAG_AGENT), count++)
681 if (tmpElement->QueryIntAttribute(
CNS_TAG_ATTR_ID, &
id) != XMLError::XML_SUCCESS)
683 std::cout <<
CNS_TAG_ATTR_ID <<
" element not found in XML file at agent №"<<count<<
"\n";
687 for(
auto agent : *allAgents)
689 if(
id == agent->GetID())
691 std::cout <<
"There is an agent with same ID ("<<
id<<
")\n";
696 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_STX, &stx) != XMLError::XML_SUCCESS)
698 std::cout <<
CNS_TAG_ATTR_STX <<
" element not found in XML file at agent №"<<count<<
"\n";
701 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_STY, &sty) != XMLError::XML_SUCCESS)
703 std::cout <<
CNS_TAG_ATTR_STY <<
" element not found in XML file at agent "<<
id<<
"\n";
706 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_GX, &gx) != XMLError::XML_SUCCESS)
708 std::cout <<
CNS_TAG_ATTR_GX <<
" element not found in XML file at agent "<<
id<<
"\n";
711 if (tmpElement->QueryFloatAttribute(
CNS_TAG_ATTR_GY, &gy) != XMLError::XML_SUCCESS)
713 std::cout <<
CNS_TAG_ATTR_GY <<
" element not found in XML file at agent "<<
id<<
"\n";
719 std::cout <<
CNS_TAG_ATTR_SIZE <<
" element not found in XML file (or it is incorrect) at agent "<<
id<<
"\n";
726 std::cout <<
CNS_TAG_ATTR_MAXSPEED <<
" element not found in XML file (or it is incorrect) at agent "<<
id<<
"\n";
761 std::cout <<
CNS_TAG_ATTR_REPS <<
" element not found in XML file (or it is incorrect) at agent "<<
id<<
"\n";
771 stx >= (map->GetWidth() * map->GetCellSize()) - param.
radius ||
772 gx >= (map->GetWidth() * map->GetCellSize()) - param.
radius ||
773 sty >= (map->GetHeight() * map->GetCellSize()) - param.
radius ||
774 gy >= (map->GetHeight() * map->GetCellSize()) - param.
radius)
776 std::cout <<
"Start or goal position of agent "<<
id<<
" is out of map or too close to boundaries\n";
781 for(
auto agent : *allAgents)
783 float sqRadiusSum =
static_cast<float>(std::pow((agent->GetRadius() + param.
radius), 2.0));
784 float sqDist = (
Point(stx, sty) - agent->GetPosition()).SquaredEuclideanNorm();
785 if(sqDist <= sqRadiusSum)
787 std::cout <<
"Position of agent "<<
id<<
" is too close to another agent\n";
793 Node tmpStNode = map->GetClosestNode(
Point(stx, sty));
794 Node tmpGlNode = map->GetClosestNode(
Point(gx, gy));
797 if(!positionChecker.checkTraversability(tmpStNode.
i, tmpStNode.
j, *map) || !positionChecker.checkTraversability(tmpGlNode.
i, tmpGlNode.
j, *map))
799 std::cout <<
"Position of agent "<<
id<<
" is too close to some obstacle\n";
806 std::cout<<
"Agent "<<
id<<
" was skipped\n\n";
811 std::cout<<
"Agent "<<
id<<
" was added at position "<<
Point(stx, sty).
ToString()<<
"\n";
814 std::string agTypeStr = std::string(agType);
843 allAgents->push_back(a);
#define CN_DEFAULT_HWEIGHT
Default H-weight for Theta* value.
#define CNS_TAG_ROW
XML tag or attribute.
#define CNS_TAG_ATTR_SIGHTRADIUS
XML tag or attribute.
#define CN_DEFAULT_AGENTS_MAX_NUM
Default agent max neighbours number value.
#define CNS_TAG_DEF_PARAMS
XML tag or attribute.
XMLReader & operator=(const XMLReader &obj)
Assignment operator.
float sightRadius
Radius in which the agent takes neighbors into account.
#define CNS_TAG_HW
XML tag or attribute.
#define CNS_TAG_OBSTS
XML tag or attribute.
#define CNS_TAG_ATTR_REPS
XML tag or attribute.
The Node class defines a cell of grid (see Map class)
#define CNS_TAG_ATTR_STX
XML tag or attribute.
#define CNS_TAG_VERTEX
XML tag or attribute.
float radius
Size of the agent (radius of the agent).
#define CNS_TAG_ATTR_MAXSPEED
XML tag or attribute.
bool GetMap(Map **map) override
Creates object with static environment data.
DirectPlanner class implements simple planner, which creates direct path from start to goal position...
File contains XMLReader class.
#define CNS_SP_ST_DIR
XML text constant.
bool ReadData() override
Starts input data reading from XML-file.
float rEps
Buffer size (more about buffer see Main page).
XMLReader()
XMLReader default constructor.
bool GetAgents(std::vector< Agent * > &agents, const int &numThreshold) override
Creates object for all agents.
#define CNS_TAG_ATTR_GX
XML tag or attribute.
The Point class defines a position (or euclidean vector from (0,0)) in 2D space.
float timeBoundaryObst
Time within which ORCA algorithm ensures collision avoidance with neighbor obstacles.
#define CN_DEFAULT_CUTCORNERS
Default Theta* CUTCORNERS value.
int agentsMaxNum
Number of neighbors, that the agent takes into account.
#define CNS_TAG_ST
XML tag or attribute.
void SetPlanner(const Planner &pl)
Set global planner object.
#define CN_DEFAULT_REPS
Default agent buffer size value.
Class AgentParam contains agent and algoritms parameters.
#define CN_DEFAULT_RADIUS_OF_SIGHT
Default agent radius of sight value.
#define CNS_TAG_MAP
XML tag or attribute.
#define CNS_DEFAULT_AGENT_TYPE
Default collision avoidance algorithm.
#define CNS_TAG_CELLSIZE
XML tag or attribute.
#define CNS_TAG_OBST
XML tag or attribute.
#define CN_DEFAULT_TIME_BOUNDARY
Default ORCA time boundary value.
#define CN_DEFAULT_METRIC_TYPE
Default Theta* heuristic-function value.
#define CNS_TAG_CC
XML tag or attribute.
Agent class implements base agent interface and behavior.
XMLReader * Clone() const override
Method for cloning objects. Create copy of object in memmory and return pointer to copy...
#define CNS_TAG_ATTR_TIMEBOUNDARY
XML tag or attribute.
std::string ToString() const
Creates STL string, which contains x,y values.
#define CNS_TAG_HEIGHT
XML tag or attribute.
~XMLReader() override
XMLReader destructor.
#define CNS_AT_ST_ORCA
XML text constant.
float timeBoundary
Time within which ORCA algorithm ensures collision avoidance with neighbor agents.
#define CN_DEFAULT_MAX_SPEED
Default agent max speed value.
The XMLReader class implements interface for input data reading from XML-file with a specific structu...
#define CN_SP_ST_DIR
Direct planning algorithm constant.
#define CN_DEFAULT_OBS_TIME_BOUNDARY
Default ORCA time boundary for obstacles value.
#define CNS_TAG_ATTR_GY
XML tag or attribute.
#define CNS_TAG_ATTR_SIZE
XML tag or attribute.
#define CNS_TAG_ATTR_X
XML tag or attribute.
#define CNS_TAG_ALG
XML tag or attribute.
Class EnvironmentOptions contains environment and algoritms parameters.
#define CNS_DEFAULT_ST
Default path planning algorithm.
Map class describes static environment.
#define CNS_TAG_TS
XML tag or attribute.
#define CNS_TAG_BT
XML tag or attribute.
float maxSpeed
Maximum speed of agent.
int i
The number of row. Part of (i,j) address of cell on grid.
#define CN_DEFAULT_SIZE
Default agent size value.
#define CNS_TAG_ROOT
Enable full output to std stream.
#define CNS_TAG_ATTR_ID
XML tag or attribute.
ThetaStar class implements Theta* algorithm, which creates path from start to goal position...
#define CN_DEFAULT_ST
Default path planning algorithm.
#define CNS_TAG_AGENT
XML tag or attribute.
ORCAAgent class implements agent with ORCA algoritm behavior.
#define CNS_TAG_DEL
XML tag or attribute.
#define CNS_TAG_ATTR_TYPE
XML tag or attribute.
#define CNS_TAG_ATTR_AGENTSMAXNUM
XML tag or attribute.
int j
The number of column. Part of (i,j) address of cell on grid.
#define CNS_TAG_WIDTH
XML tag or attribute.
This class implements line-of-sight function between two cells on the grid for a variable size of age...
#define CNS_SP_ST_THETA
XML text constant.
#define CNS_TAG_ATTR_TIMEBOUNDARYOBST
XML tag or attribute.
#define CN_SP_ST_THETA
Theta* path planning algorithm constant.
#define CNS_TAG_AS
XML tag or attribute.
#define CNS_TAG_GRID
XML tag or attribute.
#define CNS_TAG_AGENTS
XML tag or attribute.
#define CNS_TAG_ATTR_Y
XML tag or attribute.
#define CNS_TAG_ATTR_STY
XML tag or attribute.
#define CNS_TAG_ATTR_NUM
XML tag or attribute.
bool GetEnvironmentOptions(EnvironmentOptions **envOpt) override
Creates object with algorithms and environment parameters.
#define CN_DEFAULT_BREAKINGTIES
Default Theta* BREAKINGTIES value.
#define CN_DEFAULT_TIME_STEP
Default simulation timestep value.
#define CN_DEFAULT_ALLOWSQUEEZE
Default Theta* ALLOWSQUEEZE value.
#define CN_DEFAULT_DELTA
Default delta value.