Commit d5305fd6 authored by Ulrich Kemloh's avatar Ulrich Kemloh

New structure in the code allowing in the same simulation different routing strategies.

Code refactoring
Changes to the input format

some todos/fixme  fixed !
parent 873ee186
......@@ -37,7 +37,7 @@ string IODispatcher::WritePed(Pedestrian* ped) {
int color;
double v0 = ped->GetV0Norm();
if (v0 == 0) {
Log->write("ERROR: IODispatcher::WritePed()\t v0=0");
Log->Write("ERROR: IODispatcher::WritePed()\t v0=0");
exit(0);
}
color = (int) (v / v0 * 255);
......@@ -82,7 +82,7 @@ const vector<OutputHandler*>& IODispatcher::GetIOHandlers() {
void IODispatcher::Write(string str) {
for (vector<OutputHandler*>::iterator it = pHandlers.begin();
it != pHandlers.end(); ++it) {
(*it)->write(str);
(*it)->Write(str);
}
}
......
......@@ -27,12 +27,29 @@
#include "OutputHandler.h"
void OutputHandler::write(string str) {
#include <stdio.h>
#include <stdarg.h>
using namespace std;
void OutputHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
}
void STDIOHandler::write(string str) {
if (this != NULL)
cout << str << endl;
void OutputHandler::Write(const char* string,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, string);
vsprintf (msg,string ,ap);
va_end (ap);
cout<<msg<<endl;
}
void STDIOHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
}
FileHandler::FileHandler(const char *fn) {
......@@ -49,13 +66,23 @@ FileHandler::~FileHandler() {
pfp.close();
}
void FileHandler::write(string str) {
void FileHandler::Write(string str) {
if (this != NULL) {
pfp << str << endl;
pfp.flush();
}
}
void FileHandler::Write(const char* string,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, string);
vsprintf (msg,string ,ap);
va_end (ap);
pfp<<msg<<endl;
pfp.flush();
}
TraVisToHandler::TraVisToHandler(string host, int port) {
client = new TraVisToClient(host, port);
brokentags.push_back("<trajectoriesDataset>");
......@@ -67,7 +94,7 @@ TraVisToHandler::~TraVisToHandler(){
delete client;
}
void TraVisToHandler::write(string str) {
void TraVisToHandler::Write(string str) {
vector<string>::iterator str_it;
......@@ -80,3 +107,8 @@ void TraVisToHandler::write(string str) {
}
client->sendData(str.c_str());
}
......@@ -31,7 +31,6 @@
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#include "../IO/TraVisToClient.h"
......@@ -39,23 +38,25 @@ using namespace std;
class OutputHandler {
public:
virtual void write(string str);
virtual void Write(std::string str);
virtual void Write(const char *string, ...);
virtual ~OutputHandler(){};
};
class STDIOHandler : public OutputHandler {
public:
void write(string str);
void Write(std::string str);
};
class FileHandler : public OutputHandler {
private:
ofstream pfp;
std::ofstream pfp;
public:
FileHandler(const char *fn);
virtual ~FileHandler();
void write(string str);
void Write(std::string str);
void Write(const char *string,...);
};
class TraVisToHandler : public OutputHandler {
......@@ -63,12 +64,12 @@ private:
TraVisToClient* client;
public:
TraVisToHandler(string host, int port);
TraVisToHandler(std::string host, int port);
virtual ~TraVisToHandler();
void write(string str);
void Write(std::string str);
//Some tags are broken
vector<string> brokentags;
std::vector<std::string> brokentags;
};
......
......@@ -124,16 +124,15 @@ void TraVisToClient::createConnection() {
/* start the socket session */
if (!startSocketSession()) {
fprintf(stderr, "startSocketSession() failed!");
fprintf(stderr, "leaving main() with error");
return;
fprintf(stderr, "socket creation failed for host [%s] on port [%d]!",_hostname.c_str(),_port);
exit(EXIT_FAILURE);
}
/* create a new socket and connect the socket to the given service */
if (INVALID_SOCKET == (_tcpSocket = createClientSocket(_hostname.c_str(), _port))) {
fprintf(stderr, "socket creation failed!");
fprintf(stderr, "\nsocket creation failed for host [%s] on port [%d]!\n",_hostname.c_str(),_port);
stopSocketSession();
fprintf(stderr, "leaving main() with error");
return;
exit(EXIT_FAILURE);
}
_isConnected = true;
}
......
......@@ -7,7 +7,7 @@ LDFLAGS= -fopenmp
LDEBUG= -g3
LREALEASE= -O3
VERSION=RELEASE
ENABLE_CGAL=TRUE1
ENABLE_CGAL=TRUE
ifeq "$(ENABLE_CGAL)" "TRUE"
LIBS= -lCGAL -lgmp
......@@ -28,12 +28,12 @@ geometry/Point.cpp geometry/Room.cpp geometry/Building.cpp geometry/Crossing.cpp
geometry/Hline.cpp geometry/Obstacle.cpp IO/IODispatcher.cpp IO/TraVisToClient.cpp\
IO/OutputHandler.cpp geometry/NavLine.cpp\
math/Distribution.cpp math/Mathematics.cpp math/ODESolver.cpp math/ForceModel.cpp\
routing/AccessPoint.cpp routing/GlobalRouter.cpp routing/Routing.cpp routing/DummyRouter.cpp\
routing/AccessPoint.cpp routing/GlobalRouter.cpp routing/Router.cpp routing/DummyRouter.cpp\
routing/DirectionStrategy.cpp pedestrian/PedDistributor.cpp pedestrian/Pedestrian.cpp\
pedestrian/Ellipse.cpp mpi/LCGrid.cpp \
routing/QuickestPathRouter.cpp routing/NavMesh.cpp\
routing/GraphRouter.cpp routing/graph/RoutingGraph.cpp routing/graph/RoutingGraphStorage.cpp\
routing/graph/NavLineState.cpp \
routing/graph/NavLineState.cpp routing/RoutingEngine.cpp\
routing/DTriangulation.cpp \
MCD/AlgorithmBase.cpp MCD/AlgorithmMCD.cpp MCD/AlgorithmMWT.cpp MCD/AlgorithmVP.cpp \
MCD/GeomHomog.cpp MCD/GeomPairDeque.cpp MCD/GeomPoly.cpp MCD/GeomVector.cpp \
......
......@@ -36,9 +36,6 @@ Simulation::~Simulation() {
// Setter-Funktionen
************************************************/
//int Simulation::SetOnline(bool o) {
// return pOnline = o;
//}
int Simulation::SetNPeds(int i) {
return pNPeds = i;
......@@ -52,10 +49,6 @@ int Simulation::SetLinkedCells(bool l) {
// Getter-Funktionen
************************************************/
//bool Simulation::IsOnline() const {
// return pOnline;
//}
bool Simulation::IsLinkedCells() {
return pLinkedCells;
}
......@@ -101,7 +94,7 @@ void Simulation::InitArgs(ArgumentParser* args) {
exit(0);
}
Log->write("INFO: \tOptionen an Simulation geben\n");
Log->Write("INFO: \tOptionen an Simulation geben\n");
if(args->GetPort()!=-1){
switch(args->GetFileFormat())
......@@ -115,19 +108,19 @@ void Simulation::InitArgs(ArgumentParser* args) {
}
case FORMAT_XML_BIN:
{
Log->write("INFO: \tFormat xml-bin not yet supported\n");
Log->Write("INFO: \tFormat xml-bin not yet supported\n");
exit(0);
break;
}
case FORMAT_PLAIN:
{
Log->write("INFO: \tFormat plain not yet supported\n");
Log->Write("INFO: \tFormat plain not yet supported\n");
exit(0);
break;
}
case FORMAT_VTK:
{
Log->write("INFO: \tFormat vtk not yet supported\n");
Log->Write("INFO: \tFormat vtk not yet supported\n");
exit(0);
break;
}
......@@ -148,13 +141,13 @@ void Simulation::InitArgs(ArgumentParser* args) {
}
case FORMAT_XML_BIN:
{
Log->write("INFO: \tFormat xml-bin not yet supported\n");
Log->Write("INFO: \tFormat xml-bin not yet supported\n");
exit(0);
break;
}
case FORMAT_PLAIN:
{
Log->write("INFO: \tFormat plain not yet supported\n");
Log->Write("INFO: \tFormat plain not yet supported\n");
OutputHandler* file = new FileHandler("./Trajektorien.dat");
pTrajectories->AddIO(file);
exit(0);
......@@ -162,7 +155,7 @@ void Simulation::InitArgs(ArgumentParser* args) {
}
case FORMAT_VTK:
{
Log->write("INFO: \tFormat vtk not yet supported\n");
Log->Write("INFO: \tFormat vtk not yet supported\n");
exit(0);
break;
}
......@@ -237,43 +230,77 @@ void Simulation::InitArgs(ArgumentParser* args) {
s.append(tmp);
// Routing
int router = args->GetRoutingStrategy();
sprintf(tmp, "\tRouting Strategy: %d\n", router);
s.append(tmp);
Routing* rout = NULL;
switch (router) {
case 1:
rout = new GlobalRouter();
break;
case 2:
rout = new GlobalRouter();
vector< pair<int, RoutingStrategy> > routers= args->GetRoutingStrategy();
RoutingEngine* routingEngine= new RoutingEngine();
for (unsigned int r= 0;r<routers.size();r++){
RoutingStrategy strategy=routers[r].second;
int routerID=routers[r].first;
switch (strategy) {
case ROUTING_LOCAL_SHORTEST:
{
Router* router=new GlobalRouter();
router->SetID(routerID);
router->SetStrategy(strategy);
routingEngine->AddRouter(router);
s.append("\tRouting Strategy local shortest added\n");
break;
case 3:
rout = new QuickestPathRouter();
}
case ROUTING_GLOBAL_SHORTEST:
{
Router* router=new GlobalRouter();
router->SetID(routerID);
router->SetStrategy(strategy);
routingEngine->AddRouter(router);
s.append("\tRouting Strategy global shortest added\n");
break;
case 4:
rout = new GraphRouter();
}
case ROUTING_QUICKEST:
{
Router* router=new QuickestPathRouter();
router->SetID(routerID);
router->SetStrategy(strategy);
routingEngine->AddRouter(router);
s.append("\tRouting Strategy quickest path added\n");
break;
case 5:
cout<<"router not available"<<endl;
exit(EXIT_FAILURE);
}
case ROUTING_DYNAMIC:
{
Router* router=new GraphRouter();
router->SetID(routerID);
router->SetStrategy(strategy);
routingEngine->AddRouter(router);
s.append("\tRouting Strategy graph router added\n");
break;
case 6:
rout = new DummyRouter();
}
case ROUTING_DUMMY:
{
Router* router=new DummyRouter();
router->SetID(routerID);
router->SetStrategy(strategy);
routingEngine->AddRouter(router);
s.append("\tRouting Strategy dummy router added\n");
break;
}
case ROUTING_UNDEFINED:
default:
cout<<"router not available"<<endl;
exit(EXIT_FAILURE);
break;
}
}
s.append("\n");
// IMPORTANT: do not change the order in the following..
pBuilding = new Building();
pBuilding->SetRouting(rout);
pBuilding->SetRoutingEngine(routingEngine);
sprintf(tmp, "\tGeometrie: [%s]\n", args->GetGeometryFilename().c_str());
s.append(tmp);
Log->write("INFO: \t" + s);
Log->Write("INFO: \t" + s);
pBuilding->LoadBuilding(args->GetGeometryFilename());
pBuilding->AddSurroundingRoom();
pBuilding->InitGeometry(); // create the polygones
......@@ -302,9 +329,10 @@ void Simulation::InitArgs(ArgumentParser* args) {
pNPeds=pDistribution->Distribute(pBuilding);
// initialise the routing engine before doing any other things
rout->Init(pBuilding);
routingEngine->Init(pBuilding);
pBuilding->InitPhiAllPeds(pDt);
//TODO: set the cellsize to geometry bound in the case no linked cells are wished
//using linkedcells
if (pLinkedCells){
pBuilding->InitGrid(args->GetLinkedCellSize());
......
......@@ -35,6 +35,7 @@
#include "routing/DummyRouter.h"
#include "routing/GraphRouter.h"
#include "routing/NavMesh.h"
#include "routing/RoutingEngine.h"
#include "pedestrian/PedDistributor.h"
......@@ -61,11 +62,9 @@ public:
Simulation();
virtual ~Simulation();
// Setter-Funktionen
int SetOnline(bool o); // setzt online auf true oder false
int SetLinkedCells(bool l);
int SetNPeds(int i);
// Getter-Funktionen
bool IsOnline() const;
bool IsLinkedCells();
int GetNPeds() const;
int GetNPedsGlobal() const;
......@@ -76,7 +75,6 @@ public:
int RunSimulation();
void Update(); // update the complete system
void DistributeDestinations(); //assign the pedestrians their final destinations
void InitRoutineClearing(); // set some parameters specific to routine clearing
};
......
This diff is collapsed.
......@@ -34,6 +34,7 @@
#include "Macros.h"
using std::string;
using std::vector;
using std::pair;
class OutputHandler;
extern OutputHandler* Log;
......@@ -50,8 +51,7 @@ private:
double pdt; // Zeitschritt
double pfps; //frame rate
int pExitStrategy; // Strategie zur Richtungswahl (v0)
//int pRandomize; // Verteilung inerhalb des Raums
int pRouter; // Routing-Strategie
vector< pair<int, RoutingStrategy> > pRoutingStrategies;
bool pLinkedCells; // use of linked-cells neighbourhood list
double pLinkedCellSize; // cell size of the linkedcell (default to 2.2m)
double pV0Mu; // mu für die Normalverteilung von v0
......@@ -102,7 +102,7 @@ public:
int GetExitStrategy() const;
int GetRandomize() const;
bool IsOnline() const;
int GetRoutingStrategy() const;
vector< pair<int, RoutingStrategy> > GetRoutingStrategy() const;
bool GetLinkedCells() const;
double GetLinkedCellSize() const;
int GetMaxOpenMPThreads() const;
......
......@@ -59,9 +59,6 @@
// Linked cells
#define LIST_EMPTY -1
//rooms states
//#define ROOM_CLEAN 0
//#define ROOM_SMOKED 1
enum RoomState {
ROOM_CLEAN=0,
......@@ -78,10 +75,11 @@ enum FileFormat {
enum RoutingStrategy {
ROUTING_LOCAL_SHORTEST,
ROUTING_GLOBAL_SHORTEST,
ROUTING_QUCIKEST,
ROUTING_QUICKEST,
ROUTING_DYNAMIC,
ROUTING_FROM_FILE,
ROUTING_DUMMY
ROUTING_DUMMY,
ROUTING_UNDEFINED =-1
};
#endif /* _MACROS_H */
......
/****************************************************************************/
/*! \mainpage XMLParser library
/** mainpage mainpage XMLParser library
* \section intro_sec Introduction
*
* This is a basic XML parser written in ANSI C++ for portability.
......
This diff is collapsed.
......@@ -37,7 +37,7 @@
#include "Room.h"
#include "../general/Macros.h"
#include "../routing/Routing.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
#include "../geometry/Transition.h"
#include "../mpi/LCGrid.h"
......@@ -48,29 +48,28 @@
class Building {
private:
string pCaption; // Name des Projekts
Routing* pRouting;
RoutingEngine* pRoutingEngine;
vector<Room*> pRooms; // Liste der Räume
vector<Pedestrian*> pAllPedestians;
LCGrid* pLinkedCellGrid;
// this is only for the Hermes Project
//bool pSubroomConnectionMap[16][130][16][130];
// pedestrians pathway
/// pedestrians pathway
bool pSavePathway;
ofstream PpathWayStream;
// wird nur innerhalb von Building benötigt
void StringExplode(string str, string separator, vector<string>* results);
map<int, Crossing*> _crossings;
map<int, Transition*> _transitions;
map<int, Hline*> _hLines;
public:
// Konstruktor
Building();
Building(const Building& orig);
virtual ~Building();
// Setter -Funktionen
void SetCaption(string s);
void SetRouting(Routing* r);
void SetRoutingEngine(RoutingEngine* r);
void SetAllRooms(const vector<Room*>& rooms);
void SetRoom(Room* room, int index);
/// delete the ped from the ped vector
......@@ -81,15 +80,21 @@ public:
// Getter - Funktionen
string GetCaption() const;
Routing* GetRouting() const;
RoutingEngine* GetRoutingEngine() const;
const vector<Room*>& GetAllRooms() const;
const vector<Pedestrian*>& GetAllPedestrians() const;
Pedestrian* GetPedestrian( int pedID) const;
int GetAnzRooms() const;
int GetGoalsCount()const;
Room* GetRoom(int index) const; // Gibt Raum der Nummer "index" zurueck
Room* GetRoom(string caption)const;
Transition* GetTransition(string caption) const;
Transition* GetTransition(int id) ;
Crossing* GetGoal(string caption) const;
//FIXME: obsolete shold get rid of this method
Crossing* GetGoal(int id);
int GetAnzPedestrians() const;
LCGrid* GetGrid() const;
......@@ -105,6 +110,15 @@ public:
void AddSurroundingRoom(); // add a final room (outside or world), that encompasses the complete geometry
void DumpSubRoomInRoom(int roomID, int subID);
const map<int, Crossing*>& GetAllCrossings() const;
const map<int, Transition*>& GetAllTransitions() const;
const map<int, Hline*>& GetAllHlines() const;
void AddCrossing(Crossing* line);
void AddTransition(Transition* line);
void AddHline(Hline* line);
// Ein-Ausgabe
void LoadBuilding(string filename); // Laedt Geometrie-Datei
......@@ -118,6 +132,10 @@ public:
// saving computation
//bool IsDirectlyConnected(int room1, int subroom1,int room2, int subroom2);
private:
// wird nur innerhalb von Building benötigt
void StringExplode(string str, string separator, vector<string>* results);
};
#endif /* _BUILDING_H */
......
......@@ -85,7 +85,7 @@ SubRoom* Crossing::GetSubRoom(int ID) const {
else if (pSubRoom2 != NULL && pSubRoom2->GetSubRoomID() == ID)
return pSubRoom2;
else {
Log->write("ERROR: \tCrossing::GetSubRoom() wrong ID");
Log->Write("ERROR: \tCrossing::GetSubRoom() wrong ID");
exit(0);
}
}
......@@ -148,7 +148,7 @@ SubRoom* Crossing::GetOtherSubRoom(int roomID, int subroomID) const {
char tmp[CLENGTH];
sprintf(tmp,"ERROR: \tCrossing::GetOtherSubRoom No exit found "
"on the other side\n ID=%hd, roomID=%hd, subroomID=%hd\n",GetIndex(),roomID,subroomID);
Log->write(tmp);
Log->Write(tmp);
exit(0);
}
}
......@@ -165,7 +165,7 @@ void Crossing::WriteToErrorLog() const {
sprintf(tmp, "\t\t\t\tSubRoom: %d <-> SubRoom: %d\n", GetSubRoom1()->GetSubRoomID(),
GetSubRoom2()->GetSubRoomID());
s.append(tmp);
Log->write(s);
Log->Write(s);
}
// TraVisTo Ausgabe
......
......@@ -39,7 +39,7 @@ class Crossing : public NavLine {
private:
int pID; // eindeutig zwischen ALLEN Crossings und Transitions
Room* pRoom1; // benötigt nur einen Raum in dem beide SubRooms enthalten sind
string pCaption;
std::string pCaption;
SubRoom* pSubRoom1; // SubRoom1
SubRoom* pSubRoom2; // SubRoom2
......@@ -50,12 +50,12 @@ public:
// Setter -Funktionen
void SetIndex(int ID);
void SetRoom1(Room* r);
void SetCaption(string s);
void SetCaption(std::string s);
void SetSubRoom1(SubRoom* r1);
void SetSubRoom2(SubRoom* r2);
// Getter - Funktionen
int GetIndex() const;
string GetCaption() const;
std::string GetCaption() const;
Room* GetRoom1() const;
SubRoom* GetSubRoom(int ID) const;
SubRoom* GetSubRoom1() const;
......@@ -73,7 +73,7 @@ public:
// Ausgabe
virtual void WriteToErrorLog() const;
virtual string WriteElement() const; // TraVisTo Ausgabe
virtual std::string WriteElement() const; // TraVisTo Ausgabe
};
#endif /* _CROSSING_H */
......
......@@ -86,7 +86,7 @@ void Hline::WriteToErrorLog() const {
sprintf(tmp, "\t\t\t\tRoom: %d <-> SubRoom: %d\n", pRoom->GetRoomID(),
pSubRoom->GetSubRoomID());
s.append(tmp);
Log->write(s);
Log->Write(s);
}
// TraVisTo Ausgabe
......
......@@ -26,8 +26,11 @@
#include "Line.h"
using namespace std;
int Line::_UID=0;
/************************************************************
Konstruktoren
************************************************************/
......@@ -123,7 +126,7 @@ Point Line::NormalVec() const {
/* Normieren */
norm = sqrt(nx * nx + ny * ny);
if (fabs(norm) < J_EPS) {
Log->write("ERROR: \tLine::NormalVec() norm==0\n");
Log->Write("ERROR: \tLine::NormalVec() norm==0\n");
exit(0);
}
nx /= norm;
......@@ -213,7 +216,7 @@ bool Line::IsInLine(const Point& p) const {
} else if (fabs(ay - by) > J_EPS_DIST) {
lambda = (py - ay) / (by - ay);
} else {
Log->write("ERROR: \tIsInLine: Endpunkt = Startpunkt!!!");
Log->Write("ERROR: \tIsInLine: Endpunkt = Startpunkt!!!");
exit(0);
}
return (0 <= lambda) && (lambda <= 1);
......@@ -361,14 +364,14 @@ bool Line::IntersectionWithCircle(const Point& centre, double radius /*cm for pe
delta=b*b-4*a*c;
if((x1==x2)&&(y1==y2)){
Log->write("isLineCrossingCircle: Your line is a point");
Log->Write("isLineCrossingCircle: Your line is a point");
return false;
}
if(delta<0.0){
char tmp[CLENGTH];
sprintf(tmp,"there is a bug in 'isLineCrossingCircle', delta(%f) can t be <0 at this point.",delta);
Log->write(tmp);
Log->write("press ENTER");
Log->Write(tmp);
Log->Write("press ENTER");
return false; //fixme
//getc(stdin);
}
......
......@@ -63,7 +63,7 @@ public:
const Point& GetCentre(void) const;
// Ausgabe
virtual string Write() const;
virtual std::string Write() const;
// Sonstiges
Point NormalVec() const; // Normalen_Vector zu Line
......
......@@ -126,7 +126,7 @@ bool Obstacle::Contains(const Point& ped) const {
if(pClosed==0.0) {