Commit d8083e3d authored by Ulrich Kemloh's avatar Ulrich Kemloh

codebase for the gcfm model

parent 5b783dca
This diff is collapsed.
/*
* File: IODispatcher.h
* Author: andrea
*
* Created on 20. November 2010, 15:20
*/
#ifndef _IODISPATCHER_H
#define _IODISPATCHER_H
#include "OutputHandler.h"
#include "../geometry/Building.h"
extern OutputHandler* Log;
class IODispatcher {
private:
vector<OutputHandler* > pHandlers;
// private Funktionen
string WritePed(Pedestrian* ped);
public:
IODispatcher();
IODispatcher(const IODispatcher& orig);
virtual ~IODispatcher();
void AddIO(OutputHandler* ioh);
const vector<OutputHandler*>& GetIOHandlers();
void Write(string str);
virtual void WriteHeader(int nPeds, int fps, Building* building, int seed=0, int szenarioID=0);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
int AreaLevel(string caption);
template<typename A>
bool IsElementInVector(const std::vector<A> &vec, A& el) {
typename std::vector<A>::const_iterator it;
it = find (vec.begin(), vec.end(), el);
if(it==vec.end()){
return false;
}else{
return true;
}
}
};
class HermesIODispatcher:public IODispatcher {
private:
int pFileSectionFrame;
string pPath;
int pFPS;
int pSeed;
int pScenarioID;
// somehow no one knows where the origin is situated
double pTranslateX;
double pTranslateY;
string WritePed(Pedestrian* ped);
public:
HermesIODispatcher(string path="./", int seed=0, int szenarioID=0, int fileSection=-1);
virtual ~HermesIODispatcher(){};
virtual void WriteHeader(int nPeds, int fps, Building* building, int seed=0, int szenarioID=0);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
private:
string ExecuteSystemCommand(string cmd);
};
class Trajectories:public IODispatcher {
public:
Trajectories();
virtual ~Trajectories(){};
virtual void WriteHeader(int nPeds, int fps, Building* building);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
#endif /* _IODISPATCHER_H */
#include "OutputHandler.h"
void OutputHandler::write(string str) {
}
void STDIOHandler::write(string str) {
if (this != NULL)
cout << str << endl;
}
FileHandler::FileHandler(const char *fn) {
pfp.open(fn);
if (!fn) {
char tmp[CLENGTH];
sprintf(tmp, "Error!!! Datei [%s] konnte nicht geoeffnet werden!", fn);
cerr << tmp << endl;
exit(0);
}
}
FileHandler::~FileHandler() {
pfp.close();
}
void FileHandler::write(string str) {
if (this != NULL) {
pfp << str << endl;
pfp.flush();
}
}
TraVisToHandler::TraVisToHandler() {
client = new TraVisToClient();
brokentags.push_back("<trajectoriesDataset>");
brokentags.push_back("</trajectoriesDataset>");
brokentags.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
}
TraVisToHandler::~TraVisToHandler(){
delete client;
}
void TraVisToHandler::write(string str) {
vector<string>::iterator str_it;
//There are a few broken tags which need to be checked for and removed.
for (str_it = brokentags.begin(); str_it != brokentags.end(); ++str_it) {
int tagstart = str.find(*str_it);
if (tagstart != (int) string::npos) {
str.erase(str.begin() + tagstart, str.begin() + tagstart + (*str_it).size());
}
}
client->sendData(str.c_str());
}
#ifndef OUTPUT_HANDLER_H_
#define OUTPUT_HANDLER_H_
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#include "../IO/TraVisToClient.h"
#include "../general/Macros.h"
class OutputHandler {
public:
virtual void write(string str);
};
class STDIOHandler : public OutputHandler {
public:
void write(string str);
};
class FileHandler : public OutputHandler {
private:
ofstream pfp;
public:
FileHandler(const char *fn);
~FileHandler();
void write(string str);
};
class TraVisToHandler : public OutputHandler {
private:
TraVisToClient* client;
public:
TraVisToHandler();
~TraVisToHandler();
void write(string str);
//Some tags are broken
vector<string> brokentags;
};
#endif /*OUTPUT_HANDLER_H_*/
This diff is collapsed.
/*
* TraVisToClient.h
Copyright (C) <2009> <Ulrich Kemloh>
This file is part of OpenPedSim.
OpenPedSim is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
OpenPedSim is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRAVISTOCLIENT_H_
#define TRAVISTOCLIENT_H_
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#ifdef _WIN32
#endif
#define QUEUE_LENGTH 5 ///< max queue length of pending connections
/******** macro definitions ******************************************/
#ifdef TRACE_LOGGING
#define dtrace(...) _printDebugLine(__FILE__, __LINE__, false, __VA_ARGS__)
#define derror(...) _printDebugLine(__FILE__, __LINE__, true, __VA_ARGS__)
#else
#define dtrace(...) ((void) 0)
#define derror(...) (fprintf(stderr, __VA_ARGS__), _printErrorMessage())
#endif /* TRACE_LOGGING */
#ifndef _WIN32
//#define closesocket close
#define INVALID_SOCKET (-1)
#define SOCKET_ERROR (-1)
#endif
#ifdef _WIN32
#include <winsock.h>
#define WS_MAJOR_VERSION 1 ///< major version of Winsock API
#define WS_MINOR_VERSION 1 ///< minor version of Winsock API
#define SHUT_RDWR SD_BOTH ///< @c SHUT_RDWR is POSIX standard
typedef SOCKET socket_t;
typedef int socklen_t;
#define startSocketSession() _startWin32SocketSession()
#define stopSocketSession() _stopWin32SocketSession()
//bool _startWin32SocketSession(void);
//void _stopWin32SocketSession(void);
#else
#include <unistd.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/socket.h>
typedef int socket_t;
#define u_int_32_t unsigned int
#define startSocketSession() (true)
#define stopSocketSession() ((void) 0)
#endif
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED (5000) ///< up to this number, ports are reserved and should not be used
#endif
/******** public constants *******************************************/
#define PORT 8989
#define HOST "localhost"
class TraVisToClient {
public:
/// create a client with the default parameters
/// create a client with specific parameters
TraVisToClient(const char* hostname = HOST, unsigned short port = PORT);
/// destructor
virtual ~TraVisToClient();
/// send datablock to the server
/// this functions is still blocking unfortunalty, so it may
/// influence the execution time of your program
void sendData(const char* data);
/// close the client (end the connection)
void close();
/// send a datagram using the unreliable
/// udp protokoll
void sendDatagram(char *datagram);
private:
void createConnection();
unsigned long lookupHostAddress(const char *hostName);
socket_t createClientSocket(const char *serverName, unsigned short portNumber);
socket_t createServerSocket(unsigned short portNumber);
bool shutdownAndCloseSocket(socket_t sock);
bool sendMessage(socket_t sock, const void *msg, int msgSize);
bool receiveMessage(socket_t sock, void *msg, int msgSize);
void _printErrorMessage(void);
#ifdef _WIN32
bool _startWin32SocketSession(void);
void _stopWin32SocketSession(void);
#else
#define closesocket close
#endif
private:
bool isConnected;
//bool dataPending;
socket_t tcpSocket;
//FIXME: this could be a security issue. the lenght shuolnd be limited
char hostname[50];
unsigned short port;
std::vector<const char *> msgQueue;
};
#endif /* TRAVISTOCLIENT_H_ */
MCC = mpicxx
CC=g++
VTT= vtcxx -vt:cxx mpicxx
CFLAGS=-c -Wall -ansi
LDFLAGS= -fopenmp
LDEBUG= -g3
LREALEASE= -O3
VERSION=RELEASE
ifeq "$(VERSION)" "DEBUG"
CFLAGS += $(LDEBUG)
else
ifeq "$(VERSION)" "RELEASE"
CFLAGS += $(LREALEASE)
endif
endif
SOURCES=main.cpp Simulation.cpp general/ArgumentParser.cpp general/xmlParser.cpp\
geometry/SubRoom.cpp geometry/Wall.cpp geometry/Transition.cpp geometry/Line.cpp\
geometry/Point.cpp geometry/Room.cpp geometry/Building.cpp geometry/Crossing.cpp\
IO/IODispatcher.cpp IO/TraVisToClient.cpp IO/OutputHandler.cpp\
math/Distribution.cpp math/Mathematics.cpp math/ODESolver.cpp math/ForceModel.cpp\
routing/AccessPoint.cpp routing/GlobalRouter.cpp routing/Routing.cpp\
routing/DirectionStrategy.cpp pedestrian/PedDistributor.cpp pedestrian/Pedestrian.cpp\
pedestrian/Ellipse.cpp mpi/MPIDispatcher.cpp mpi/LCGrid.cpp\
routing/QuickestPathRouter.cpp routing/CircleRouter.cpp\
OBJECTS=$(SOURCES:.cpp=.o)
DEP=$(SOURCES:.cpp=.d)
EXECUTABLE=rebuild.exe
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(MCC) $(LDFLAGS) $(OBJECTS) -o $@
# pull in dependency info for *existing* .o files
-include $(OBJECTS:.o=.d)
.cpp.o:
$(MCC) $(CFLAGS) $(LDFLAGS) $< -o $@
$(MCC) -MM $(CFLAGS) $*.cpp > $*.d
release:
$(MCC) $(LDFLAGS) $(LREALEASE) -o $(EXECUTABLE) $(SOURCES)
vampire:
$(VTT) $(LDFLAGS) $(LDEBUG) -DVTRACE -o $(EXECUTABLE) $(SOURCES)
debug:
$(MCC) $(LDFLAGS) $(LDEBUG) -o $(EXECUTABLE) $(SOURCES)
clean :
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f $(DEP)
purge :
rm -f $(EXECUTABLE)
rm -f $(OBJECTS)
rm -f $(DEP)
rm *xml
rm *dat
rm *txt
rm trace_*
This diff is collapsed.
/*Simulation.h:
The Simulation class represents a simulation of pedestrians
based on a certain model in a specific scenario. A simulation is defined by
various parameters and functions.
Copyright (C) <2009-2010> <Jonas Mehlich and Mohcine Chraibi>
This file is part of OpenPedSim.
OpenPedSim is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
OpenPedSim is distributed in the hope that it will be useful,
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SIMULATION_H_
#define SIMULATION_H_
#include "general/ArgumentParser.h"
#include "geometry/Building.h"
#include "IO/OutputHandler.h"
#include "IO/IODispatcher.h"
#include "math/ForceModel.h"
#include "math/ODESolver.h"
#include "routing/GlobalRouter.h"
#include "routing/QuickestPathRouter.h"
#include "routing/DirectionStrategy.h"
#include "routing/CircleRouter.h"
#include "pedestrian/PedDistributor.h"
#include "mpi/MPIDispatcher.h"
extern OutputHandler* Log;
class Simulation {
private:
bool pOnline; // true, wenn online simulation (TraVisTo)
bool pLinkedCells; // true, wenn LinkedCell-Listen
int pActionPt; // on or off
int pNPeds; // number of pedestrians
double pTmax; // Maximale Simulationszeit
double pDt; // Zeitschritt
double fps; // framerate
Building* pBuilding; // Geometrie mit Rooms, SubRooms und Wänden
PedDistributor* pDistribution; // verteilt die Fußgänger zu Beginn der Simulation
DirectionStrategy* pDirection; // gibt die Richtungswahl zum Ziel an
ForceModel* pModel; // das verwendete Kraftmodell (im Moment nur GCFM)
ODESolver* pSolver; // Löser für die ODE
IODispatcher* iod;
Trajectories* pTrajectories;
//MPI
MPIDispatcher* pMPIDispatcher;
int pNpedsGlobal; // number of pedestrians on all processors
public:
// Konstruktor
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;
Building* GetBuilding() const;
// Sonstige-Funktionen
void InitArgs(ArgumentParser *args);
int InitSimulation();
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
//MPI
void SetMPIDispatcher(MPIDispatcher *mpi);
const MPIDispatcher* GetMPIDispatcher() const;
};
#endif /*SIMULATION_H_*/
This diff is collapsed.
#ifndef ARGUMENTPARSER_H_
#define ARGUMENTPARSER_H_
#include <unistd.h>
#include <getopt.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sstream>
#include <omp.h>
#include "../IO/OutputHandler.h"
using std::string;
using std::vector;
extern OutputHandler* Log;
class ArgumentParser {
private:
string pNumberFilename; // Datei mit Startverteilung
int pSolver; // Löser für DGL
string pGeometryFilename; // Datei mit Geometrie
string pPathwayfile; // saving pedestrian path
double pTmax; // maximale Simulationszeit
double pdt; // Zeitschritt
double pfps; //frame rate
int pExitStrategy; // Strategie zur Richtungswahl (v0)
int pRandomize; // Verteilung inerhalb des Raums
int pRouter; // Routing-Strategie
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
double pV0Sigma; // sigma für die Normalverteilung von v0
double pBmaxMu; // mu für die Normalverteilung von b_max
double pBmaxSigma; // sigma für die Normalverteilung von b_max
double pBminMu; // mu für die Normalverteilung von b_min
double pBminSigma; // sigma für die Normalverteilung von b_min
double pAtauMu; // mu für die Normalverteilung von a_tau
double pAtauSigma; // sigma für die Normalverteilung von a_tau
double pAminMu; // mu für die Normalverteilung von a_min
double pAminSigma; // sigma für die Normalverteilung von a_min
double pTauMu;
double pTauSigma;
double pNuPed;
double pNuWall;
double pIntPWidthPed;
double pIntPWidthWall;
double pMaxFPed;
double pMaxFWall;
double pDistEffMaxPed;
double pDistEffMaxWall;
int pLog;
int pTravisto;
int pTrajektorien;
string pErrorLogFile;
string pTrajOutputDir;
string pDoorsStateFile;
string pRoomsStateFile;
string pEvacuationType;
//string pInputDir;
unsigned int pSeed;
unsigned int pScenarioID;
int pMaxOpenmpThreads;
// private Funktionen
void Usage();
public:
// Konstruktor
ArgumentParser(); // gibt die Programmoptionen aus
// Getter-Funktionen
string GetNumberFilename() const;
string GetPathwayFile() const;
int GetSolver() const;
double GetTmax() const;
double Getdt() const;
string GetGeometryFilename() const;
int GetExitStrategy() const;
int GetRandomize() const;
bool IsOnline() const;
int GetRoutingStrategy() const;
bool GetLinkedCells() const;
double GetLinkedCellSize() const;
int GetMaxOmpThreads() const;
double GetV0Mu() const;
double GetV0Sigma() const;
double GetBmaxMu() const;
double GetBmaxSigma() const;
double GetBminMu() const;
double GetBminSigma() const;
double GetAtauMu() const;
double GetAtauSigma() const;
double GetAminMu() const;
double GetAminSigma() const;
double GetNuPed() const;
double GetNuWall() const;
double GetIntPWidthPed() const;
double GetIntPWidthWall() const;
double GetMaxFPed() const;
double GetMaxFWall() const;
double GetDistEffMaxPed() const;
double GetDistEffMaxWall() const;
double GetTauMu() const;
double GetTauSigma() const;
int GetLog() const;
int GetTravisto() const;
int GetTrajektorien() const;
double Getfps() const;
//input from the ini.txt file
unsigned int GetSeed() const;
unsigned int GetScenarioID() const;
string GetTrajOutputDir() const;
string GetErrorLogFile() const;
string GetRoomsStateFile() const;
string GetDoorsStateFile() const;
string GetEvacuationType() const;
// Sonstige:
void ParseArgs(int argc, char **argv);
void ParseIniFile(string inifile);// parse the ini file found in the current dir
};
#endif /*ARGPARSER_H_*/
/*
* File: Macros.h
* Author: andrea
*
* Created on 16. Juni 2010, 16:59
*/
#ifndef _MACROS_H
#define _MACROS_H
// Genauigkeit
#define EPS 0.001
#define EPS_DIST 0.05// [m]
#define EPS_GOAL 0.05 // [m] Abstand zum Ziel, damit Fußgänger immer zu einem Raum gehört
#define TOLERANZ 0.03 // [m] Toleranz beim erstellen der Linien
#define EPS_V 0.1 // [m/s] wenn v<EPS_V wird mit 0 gerechnet
// zur Versionskontrolle beim Geometrieformat
#define VERSION 0.30
#define OPS_VERSION "1.0.13"
// Länge von char vectoren zur Ausgabe
#define CLENGTH 1000
// Faktor für TraVisTo (cm <-> m)
#define FAKTOR 100
// final destinations for the pedestrians
#define FINAL_DEST_OUT -1 //default
#define FINAL_DEST_PARKING_TOP 1