Commit ea58da28 authored by Ulrich Kemloh's avatar Ulrich Kemloh

* all memory leaks fixed.

* proprieatary xmlparser replaced with tinyxml
* new demos files added
* different pedestians can now follow different strategies and be assigned different routes/targets.
* other minor bugs fixed
parent e675d5eb
......@@ -18,7 +18,12 @@ file(
Simulation.cpp
general/ArgumentParser.cpp
general/xmlParser.cpp
tinyxml/tinystr.cpp
tinyxml/tinyxml.cpp
tinyxml/tinyxmlerror.cpp
tinyxml/tinyxmlparser.cpp
geometry/Building.cpp
geometry/Line.cpp
......@@ -89,7 +94,8 @@ file(
mpi/LCGrid.h
general/ArgumentParser.h
general/Macros.h
general/xmlParser.h
tinyxml/tinyxml.h
tinyxml/tinystr.h
geometry/Crossing.h
geometry/NavLine.h
geometry/Room.h
......
......@@ -302,7 +302,6 @@ void Simulation::InitArgs(ArgumentParser* args) {
}
s.append("\n");
// IMPORTANT: do not change the order in the following..
_building = new Building();
_building->SetRoutingEngine(routingEngine);
......@@ -318,21 +317,20 @@ void Simulation::InitArgs(ArgumentParser* args) {
_building->LoadRoutingInfo(args->GetRoutingFile());
/////////
//Navigation mesh implementation
NavMesh* nv= new NavMesh(_building);
nv->BuildNavMesh();
//nv->WriteToFile("../pedunc/examples/stadium/arena.nav");
nv->WriteToFileTraVisTo("promenade.nav.xml");
//nv->WriteScenario();
exit(EXIT_FAILURE);
//iod->WriteGeometryRVO(pBuilding);exit(EXIT_FAILURE);
//iod->WriteNavMeshORCA(pBuilding);exit(EXIT_FAILURE);
////////
// in the case the navigation mesh should be written to a file
if(args->GetNavigationMesh()!=""){
Log->Write("INFO: \tWriting the navigation mesh to: " + args->GetNavigationMesh());
//Navigation mesh implementation
NavMesh* nv= new NavMesh(_building);
nv->BuildNavMesh();
//nv->WriteToFile("../pedunc/examples/stadium/arena.nav");
nv->WriteToFile(args->GetNavigationMesh()+".nav");
nv->WriteToFileTraVisTo(args->GetNavigationMesh());
//nv->WriteScenario();
exit(EXIT_FAILURE);
//iod->WriteGeometryRVO(pBuilding);exit(EXIT_FAILURE);
//iod->WriteNavMeshORCA(pBuilding);exit(EXIT_FAILURE);
}
_nPeds=_distribution->Distribute(_building);
......
......@@ -4,15 +4,16 @@
<!-- seed used for initialising random generator -->
<seed>12542</seed>
<!-- geometry file -->
<geometry>inputfiles/T-Junction/T-Junction.xml</geometry>
<geometry>./demos/T-Junction/T-Junction.xml</geometry>
<!--persons information and distribution -->
<person>inputfiles/T-Junction/persons.xml</person>
<person>./demos/T-Junction/persons.xml</person>
<!-- extra routing information -->
<routing>inputfiles/T-Junction/routing.xml</routing>
<routing>./demos/T-Junction/routing.xml</routing>
<!-- traffic information: e.g closed doors -->
<traffic>inputfiles/T-Junction/traffic.xml</traffic>
<traffic>./demos/T-Junction/traffic.xml</traffic>
<!-- trajectories file and format -->
<trajectories format="xml-plain" version="0.4">outputfiles/trajectories.xml
<trajectories format="xml-plain" fps="8" version="0.4">
<file location="./outputfiles/trajectories-tjunction.xml"/>
</trajectories>
<!-- where to store the logs
<logfile>outputfiles/log.txt</logfile>
......@@ -24,7 +25,6 @@
<solver>euler</solver>
<stepsize>0.001</stepsize>
<linkedcells enabled="true" cell_size="2.2"/>
<routeChoiceStrategy>local_shortest</routeChoiceStrategy>
<v0 mu="1.24" sigma="0.001" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
......
This diff is collapsed.
......@@ -31,6 +31,7 @@
#include <string>
#include <vector>
#include <cstdlib>
#include "Macros.h"
using std::string;
using std::vector;
......@@ -45,10 +46,11 @@ private:
string pTrafficFilename; /// traffic information (closed doors,...)
string pNumberFilename; /// initial distribution and person specifications
string pGeometryFilename;
string pPathwayfile; // saving pedestrian path
string pPathwayFilename; // saving pedestrian path
string pHostname;
string pTrajectoriesFile;
string pErrorLogFile;
string pNavMeshFilename;
double pTmax; // maximale Simulationszeit
double pdt; // Zeitschritt
double pfps; //frame rate
......@@ -140,6 +142,7 @@ public:
const string& GetPersonsFilename() const;
const string& GetPathwayFile() const;
const string& GetGeometryFilename() const;
const string& GetNavigationMesh() const;
vector< pair<int, RoutingStrategy> > GetRoutingStrategy() const;
const FileFormat& GetFileFormat() const;
......@@ -156,6 +159,21 @@ public:
* @param inifile
*/
void ParseIniFile(string inifile);
/**
* convert a non null string to int.
*/
void Str2Int(const char* str, int* value){
if(!str) *value=atoi(str);
};
/**
* convert a non null string to double.
*/
void Str2double(const char* str, double* value){
if(!str) *value=atof(str);
};
};
#endif /*ARGPARSER_H_*/
......@@ -25,11 +25,16 @@
*/
#ifndef _MACROS_H
#define _MACROS_H
#define _MACROS_H
#include <cstdlib>
#include <vector>
#include <string.h>
#define _SIMULATOR 1
//#undef _OPENMP
// Genauigkeit
#define J_EPS 0.001
#define J_EPS_DIST 0.05// [m]
......@@ -47,7 +52,6 @@
// Faktor für TraVisTo (cm <-> m)
//#define FAKTOR 100
#define FAKTOR 100
......@@ -85,5 +89,16 @@ enum RoutingStrategy {
ROUTING_UNDEFINED =-1
};
//global functions for convenience
// convenience functions
inline char xmltob(const char * t,char v=0){ if (t&&(*t)) return (char)atoi(t); return v; }
inline int xmltoi(const char * t,int v=0){ if (t&&(*t)) return atoi(t); return v; }
inline long xmltol(const char * t,long v=0){ if (t&&(*t)) return atol(t); return v; }
inline double xmltof(const char * t,double v=0.0){ if (t&&(*t)) return atof(t); return v; }
inline const char * xmltoa(const char * t, const char * v=""){ if (t) return t; return v; }
inline char xmltoc(const char * t,const char v='\0'){ if (t&&(*t)) return *t; return v; }
#endif /* _MACROS_H */
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
......@@ -121,7 +121,6 @@ public:
void AddHline(Hline* line);
// Ein-Ausgabe
void LoadBuilding(std::string filename); // Laedt Geometrie-Datei
void LoadTrafficInfo(std::string filename);
......@@ -135,7 +134,6 @@ public:
//bool IsDirectlyConnected(int room1, int subroom1,int room2, int subroom2);
private:
// wird nur innerhalb von Building benötigt
void StringExplode(std::string str, std::string separator, std::vector<std::string>* results);
};
......
......@@ -12,7 +12,7 @@
<!-- traffic information: e.g closed doors -->
<traffic>inputfiles/traffic.xml</traffic>
<!-- trajectories file and format -->
<trajectories format="xml" fps="8">
<trajectories format="xml-plain" fps="8">
<file location="outputfiles/trajectories.xml"/>
<!--<socket hostname="127.0.0.1" port="8989"/> -->
</trajectories>
......@@ -22,7 +22,7 @@
<!-- These parameters may be overwritten -->
<parameters>
<tmax unit="sec">1</tmax>
<tmax unit="sec">900</tmax>
<solver>euler</solver>
<stepsize>0.001</stepsize>
<exitCrossingStrategy>3</exitCrossingStrategy>
......
......@@ -11,6 +11,12 @@
<dist room_caption="headon" subroom_id="0" number="1" />
</distribution>
<routers>
<router id="1" method="local_shortest"/>
<router id="2" method="global_shortest"/>
<router id="3" method="quickest"/>
<router id="4" method="dummy"/>
</routers>
<!--
<groups>
<group id="0">
......
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<geometry version="0.4" caption="T-Junction" gridSizeX="20"
gridSizeY="25" unit="m">
<rooms>
<room id="0" caption="T-Junction" zpos="0.00">
<subroom id="0" closed="0" class="subroom">
<polygon caption="wall">
<vertex px="0.0" py="-0.0" />
<vertex px="0.0" py="10.0" />
</polygon>
<polygon caption="wall">
<vertex px="5.0" py="0.0" />
<vertex px="5.0" py="10.0" />
</polygon>
</subroom>
<subroom id="1" closed="0" class="corridor">
<polygon caption="wall">
<vertex px="-10.0" py="10.0" />
<vertex px="0.0" py="10.0" />
</polygon>
<polygon caption="wall">
<vertex px="-10.0" py="15.0" />
<vertex px="0.0" py="15.0" />
</polygon>
</subroom>
<subroom id="2" closed="0" class="corridor">
<polygon caption="wall">
<vertex px="-0.0" py="15.0" />
<vertex px="5.0" py="15.0" />
</polygon>
</subroom>
<subroom id="3" closed="0" class="corridor">
<polygon caption="wall">
<vertex px="15.0" py="15.0" />
<vertex px="5.0" py="15.0" />
</polygon>
<polygon caption="wall">
<vertex px="5.0" py="10.0" />
<vertex px="15.0" py="10.0" />
</polygon>
</subroom>
<crossings>
<!-- virtual exits between subrooms -->
<crossing id="0" subroom1_id="0" subroom2_id="2">
<vertex px="0.0" py="10.0" />
<vertex px="5.0" py="10.0" />
</crossing>
<crossing id="1" subroom1_id="2" subroom2_id="1">
<vertex px="0.0" py="10.0" />
<vertex px="0.0" py="15.0" />
</crossing>
<crossing id="2" subroom1_id="2" subroom2_id="3">
<vertex px="5.0" py="10.0" />
<vertex px="5.0" py="15.0" />
</crossing>
</crossings>
</room>
</rooms>
<transitions>
<!-- exits like crossings but between rooms or to outside (room with index
= -1) -->
<transition id="3" caption="main exit" type="emergency"
room1_id="0" subroom1_id="0" room2_id="-1" subroom2_id="-1">
<vertex px="0.0" py="-0.0" />
<vertex px="5.0" py="-0.0" />
</transition>
<transition id="4" caption="main exit" type="emergency"
room1_id="0" subroom1_id="1" room2_id="-1" subroom2_id="-1">
<vertex px="-10.0" py="10.0" />
<vertex px="-10.0" py="15.0" />
</transition>
<transition id="5" caption="main exit" type="emergency"
room1_id="0" subroom1_id="3" room2_id="-1" subroom2_id="-1">
<vertex px="15.0" py="10.0" />
<vertex px="15.0" py="15.0" />
</transition>
</transitions>
</geometry>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persons version="0.4">
<header>
<description>casern, 21.06.2008</description>
<number>7</number>
</header>
<!-- default distribution -->
<!-- TODO: also distribute with room_id only -->
<distribution>
<dist room_caption="T-Junction" subroom_id="3" number="20" />
<dist room_caption="T-Junction" subroom_id="1" number="20" />
</distribution>
<groups>
<group id="1">
<members>1,3,2,4,5,6</members>
<!-- <trip>0</trip> -->
<goal>5</goal>
</group>
<group id="2">
<!-- <members>4,5,6</members>-->
<members>20</members>
<!-- <trip>0:1</trip> -->
<goal>3</goal>
</group>
</groups>
<!-- <person id="1" height="180" startX= startY= startZ="" wishVelo="double"
direction="" goal="" age="18" gender="male"/> -->
<person id="7" goal="4" />
</persons>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<routing version="0.4">
<trips>
<trip id="0">0:1:2:0:1:2:0:1:2:0:1:2:0:1:2</trip>
</trips>
</routing>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<traffic version="0.4">
<rooms>
<room room_id="0" state="good" />
</rooms>
<doors>
<door trans_id="3" state="open" />
<door trans_id="4" state="open" />
<door trans_id="5" state="open" />
</doors>
</traffic>
......@@ -77,7 +77,7 @@ int main(int argc, char **argv) {
//some output
double execTime = difftime(endtime, starttime);
char tmp[CLENGTH];
sprintf(tmp, "\nPedestrians [%d] threads [%d]", sim.GetPedsNumber(),
sprintf(tmp, "\nPedestrians not evacuated [%d] threads [%d]", sim.GetPedsNumber(),
args->GetMaxOpenMPThreads());
Log->Write(tmp);
sprintf(tmp, "\nExec Time [s] : %.2f", execTime);
......
This diff is collapsed.
......@@ -26,7 +26,7 @@
*/
#include "PedDistributor.h"
#include "../general/xmlParser.h"
#include "../tinyxml/tinyxml.h"
#include "../geometry/Obstacle.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
......@@ -51,7 +51,6 @@ StartDistributionRoom::~StartDistributionRoom() {
}
string StartDistributionRoom::GetRoomCaption() const {
return _roomCaption;
}
......@@ -170,34 +169,49 @@ Distribution* PedDistributor::GetTau() const {
void PedDistributor::InitDistributor(string filename){
_initialisationFile=filename;
XMLNode xMainNode=XMLNode::openFileHelper(filename.c_str(),"persons");
Log->Write("INFO: \tLoading and parsing the persons file");
//get the distribution node
XMLNode xDist=xMainNode.getChildNode("distribution");
int nDist=xDist.nChildNode("dist");
for(int i=0;i<nDist;i++){
XMLNode path=xDist.getChildNode("dist",i);
//FIXME: id oder caption
//int room_id=atoi(path.getAttribute("room_id"));
string room_caption=path.getAttribute("room_caption");
int number=atoi(path.getAttribute("number"));
if(path.getAttribute("subroom_id")){
int subroom_id=atoi(path.getAttribute("subroom_id"));
StartDistributionSubroom dis = StartDistributionSubroom();
dis.SetRoomCaption(room_caption);
dis.SetSubroomID(subroom_id);
dis.SetNumberOfPedestrians(number);
_start_dis_sub.push_back(dis);
}else{
StartDistributionRoom dis = StartDistributionRoom();
dis.SetRoomCaption(room_caption);
dis.SetNumberOfPedestrians(number);
_start_dis.push_back(dis);
TiXmlDocument docPersons(filename);
if (!docPersons.LoadFile()){
Log->Write("ERROR: \t%s", docPersons.ErrorDesc());
Log->Write("ERROR: \t could not parse the person file");
exit(EXIT_FAILURE);
}
TiXmlElement* xRootNode = docPersons.RootElement();
if( ! xRootNode ) {
Log->Write("ERROR:\tRoot element does not exist");
exit(EXIT_FAILURE);
}
if( xRootNode->ValueStr () != "persons" ) {
Log->Write("ERROR:\tRoot element value is not 'persons'");
exit(EXIT_FAILURE);
}
TiXmlNode* xDist=xRootNode->FirstChild("distribution");
for(TiXmlElement* e = xDist->FirstChildElement("dist"); e;
e = e->NextSiblingElement("dist")) {
//FIXME: id oder caption
//int room_id=atoi(path.getAttribute("room_id"));
string room_caption=e->Attribute("room_caption");
int number=atoi(e->Attribute("number"));
if(e->Attribute("subroom_id")){
int subroom_id=atoi(e->Attribute("subroom_id"));
StartDistributionSubroom dis = StartDistributionSubroom();
dis.SetRoomCaption(room_caption);
dis.SetSubroomID(subroom_id);
dis.SetNumberOfPedestrians(number);
_start_dis_sub.push_back(dis);
}else{
StartDistributionRoom dis = StartDistributionRoom();
dis.SetRoomCaption(room_caption);
dis.SetNumberOfPedestrians(number);
_start_dis.push_back(dis);
}
}
Log->Write("INFO: \t done with loading and parsing the persons file");
......@@ -343,16 +357,32 @@ int PedDistributor::Distribute(Building* building) const {
}
}
// now assign individual attributes
XMLNode xMainNode=XMLNode::openFileHelper(_initialisationFile.c_str(),"persons");
Log->Write("INFO: \tLoading and parsing the persons file");
//get the distribution node
int nPersons=xMainNode.nChildNode("person");
for(int i=0;i<nPersons;i++){
XMLNode xPerson=xMainNode.getChildNode("person",i);
int id=xmltoi(xPerson.getAttribute("id"),-1);
TiXmlDocument docPersons(_initialisationFile);
if (!docPersons.LoadFile()){
Log->Write("ERROR: \t%s", docPersons.ErrorDesc());
Log->Write("ERROR: \t could not parse the person file");
exit(EXIT_FAILURE);
}
TiXmlElement* xRootNode = docPersons.RootElement();
if( ! xRootNode ) {
Log->Write("ERROR:\tRoot element does not exist");
exit(EXIT_FAILURE);
}
if( xRootNode->ValueStr () != "persons" ) {
Log->Write("ERROR:\tRoot element value is not 'persons'");
exit(EXIT_FAILURE);
}
for(TiXmlElement* xPerson = xRootNode->FirstChildElement("person"); xPerson;
xPerson = xPerson->NextSiblingElement("person")) {
int id=xmltoi(xPerson->Attribute("id"),-1);
if(id==-1){
Log->Write("ERROR:\tin the person attribute file. The id is mandatory ! skipping the entry");
......@@ -399,30 +429,31 @@ int PedDistributor::Distribute(Building* building) const {
nPeds++;
}
double height=xmltof(xPerson.getAttribute("height"),-1);
double height=xmltof(xPerson->Attribute("height"),-1);
if( height!=-1){
ped->SetHeight(height);
}
double age=xmltof(xPerson.getAttribute("age"),-1);
double age=xmltof(xPerson->Attribute("age"),-1);
if( age!=-1){
ped->SetAge(age);
}
string gender=xmltoa(xPerson.getAttribute("gender"),"-1");
string gender=xmltoa(xPerson->Attribute("gender"),"-1");
if( gender!="-1"){
ped->SetGender(gender);
}
int router= xmltoi(xPerson.getAttribute("router"),-1);
int router= xmltoi(xPerson->Attribute("router"),-1);
if( router != -1){
ped->SetRouter(building->GetRoutingEngine()->GetRouter(router));
}else
{
Log->Write("WARNING: \tNo router was set for ped [%d]. Default router will be used!",ped->GetID());
ped->SetRouter(building->GetRoutingEngine()->GetRouter(ROUTING_LOCAL_SHORTEST));
}
double goal_id=xmltof(xPerson.getAttribute("goal"),-1);
double goal_id=xmltof(xPerson->Attribute("goal"),-1);
if( goal_id!=-1){
if((ped->GetFinalDestination()!=FINAL_DEST_OUT ) &&
(ped->GetFinalDestination()!=goal_id)){
......@@ -436,13 +467,13 @@ int PedDistributor::Distribute(Building* building) const {
building->GetRoutingEngine()->AddFinalDestinationID(goal_id);
}
double wishVelo=xmltof(xPerson.getAttribute("wishVelo"),-1);
double wishVelo=xmltof(xPerson->Attribute("wishVelo"),-1);
if( wishVelo!=-1){
ped->SetV0Norm(wishVelo);
}
double startX=xmltof(xPerson.getAttribute("startX"),-1);
double startY=xmltof(xPerson.getAttribute("startY"),-1);
double startX=xmltof(xPerson->Attribute("startX"),-1);
double startY=xmltof(xPerson->Attribute("startY"),-1);
if(startX!=-1 && startY!=-1){
ped->SetPos(Point(startX,startY));
......@@ -468,17 +499,22 @@ int PedDistributor::Distribute(Building* building) const {
}
}
int nPedsExpected= xmltoi(xMainNode.getChildNode("header").getChildNode("number").getText(),-1);
// read the expected number of pedestrians
int nPedsExpected= atoi(xRootNode->FirstChild("header")->FirstChildElement("number")->GetText());
//now parse the different groups
XMLNode xGroups=xMainNode.getChildNode("groups");
int nGroup=xGroups.nChildNode("group");
for(int i=0;i<nGroup;i++){
XMLNode group=xGroups.getChildNode("group",i);
int group_id=xmltoi(group.getAttribute("id"),-1);
int trip_id=xmltoi(group.getChildNode("trip").getText(),-1);
int goal_id=xmltoi(group.getChildNode("goal").getText(),-1);
int router_id=xmltoi(group.getChildNode("router").getText(),-1);
TiXmlNode* xGroups=xRootNode->FirstChild("groups");
if(xGroups)
for(TiXmlElement* group = xGroups->FirstChildElement("dist"); group;
group = group->NextSiblingElement("dist")) {
int group_id=xmltoi(group->Attribute("id"),-1);
int trip_id=xmltoi(group->FirstChild("trip")->FirstChild()->Value(),-1);
int goal_id=xmltoi(group->FirstChild("goal")->FirstChild()->Value(),-1);
int router_id=xmltoi(group->FirstChild("router")->FirstChild()->Value(),-1);
if((goal_id !=-1) && (trip_id!=-1)){
sprintf(tmp, "ERROR: \ttrip and goal cannot be set for the same group [%d] !",group_id);
......@@ -489,7 +525,7 @@ int PedDistributor::Distribute(Building* building) const {
}
//get the members
string members=group.getChildNode("members").getText();
string members=group->FirstChild("members")->FirstChild()->Value();
char* str = (char*) members.c_str();
char *p = strtok(str, ",");
......@@ -533,7 +569,6 @@ int PedDistributor::Distribute(Building* building) const {
//now do the last check if all pedestrians were distributed:
if(nPedsExpected!=nPeds){
sprintf(tmp, "ERROR:\tThe number of distributed pedestrians [%d] does not match \n"
" \tthe total number of specified pedestrians in the header [%d]!",nPeds,nPedsExpected);
......