Commit 5bed6ea1 authored by Ulrich Kemloh's avatar Ulrich Kemloh

restore makefile.cmake and clean the building class

parent ab1e3789
......@@ -96,7 +96,8 @@ else(OPENMP_FOUND)
endif(OPENMP_FOUND)
#statically link all gcc stuffs
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
# find and add the CGAL library
#fixme: complete this section
......
......@@ -54,7 +54,7 @@ int OutputHandler::GetErrors()
return _nErrors;
}
void OutputHandler::Write(string str)
void OutputHandler::Write(const string& str)
{
if (this != NULL)
cout << str << endl;
......@@ -89,7 +89,7 @@ void OutputHandler::ProgressBar(double TotalPeds, double NowPeds)
void OutputHandler::Write(const char* message,...)
{
char msg[CLENGTH];
char msg[CLENGTH]="";
va_list ap;
va_start(ap, message);
vsprintf(msg, message, ap);
......@@ -116,7 +116,7 @@ void OutputHandler::Write(const char* message,...)
}
}
void STDIOHandler::Write(string str)
void STDIOHandler::Write(const string& str)
{
if (str.find("ERROR") != string::npos)
{
......@@ -153,7 +153,7 @@ FileHandler::~FileHandler()
_pfp.close();
}
void FileHandler::Write(string str)
void FileHandler::Write(const string& str)
{
if (this != NULL) {
_pfp << str << endl;
......@@ -172,7 +172,7 @@ void FileHandler::Write(string str)
void FileHandler::Write(const char* str_msg,...)
{
char msg[CLENGTH];
char msg[CLENGTH]="";
va_list ap;
va_start (ap, str_msg);
vsprintf (msg,str_msg ,ap);
......@@ -191,7 +191,7 @@ void FileHandler::Write(const char* str_msg,...)
}
}
SocketHandler::SocketHandler(string host, int port)
SocketHandler::SocketHandler(const string& host, int port)
{
client = new TraVisToClient(host, port);
brokentags.push_back("<trajectories>");
......@@ -204,10 +204,11 @@ SocketHandler::~SocketHandler()
delete client;
}
void SocketHandler::Write(string str)
void SocketHandler::Write(const string& stringRef)
{
vector<string>::iterator str_it;
string str=stringRef;
//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) {
......
......@@ -51,13 +51,13 @@ public:
void incrementErrors();
void ProgressBar(double TotalPeds, double NowPeds);
virtual void Write(std::string str);
virtual void Write(const std::string& str);
virtual void Write(const char *string, ...);
};
class STDIOHandler : public OutputHandler {
public:
void Write(std::string str);
void Write(const std::string& str);
};
class FileHandler : public OutputHandler {
......@@ -66,7 +66,7 @@ private:
public:
FileHandler(const char *fn);
virtual ~FileHandler();
void Write(std::string str);
void Write(const std::string& str);
void Write(const char *string,...);
};
......@@ -75,9 +75,9 @@ private:
TraVisToClient* client;
public:
SocketHandler(std::string host, int port);
SocketHandler(const std::string& host, int port);
virtual ~SocketHandler();
void Write(std::string str);
void Write(const std::string& str);
//Some tags are broken
std::vector<std::string> brokentags;
......
.PHONY: release debug clean clean-release clean-debug install
DIRS:= bin bin/release bin/debug
all: $(DIRS) release
$(DIRS):
mkdir $@
release:
( cd bin/release && cmake -DCMAKE_BUILD_TYPE=release ../.. && $(MAKE) --no-print-directory )
# ctags -R --language-force=c++ *.*
# ctags -eR --language-force=c++ *.*
debug:
( cd bin/debug && cmake -DCMAKE_BUILD_TYPE=debug ../.. && $(MAKE) --no-print-directory )
# ctags -R --language-force=c++ *.*
# ctags -eR --language-force=c++ *.*
clean: clean-release clean-debug
clean-release:
( cd bin/release && $(MAKE) --no-print-directory clean )
clean-debug:
( cd bin/debug && $(MAKE) --no-print-directory clean )
#release:
# ( cd build/release && cmake -DCMAKE_BUILD_TYPE=release ../.. && $(MAKE) --no-print-directory && make --no-print-directory install)
# ctags -R --language-force=c++ *.*
# ctags -eR --language-force=c++ *.*
......@@ -68,22 +68,6 @@ Simulation::~Simulation()
delete _em;
}
/************************************************
// Setter-Funktionen
************************************************/
void Simulation::SetPedsNumber(int i)
{
_nPeds = i;
}
/************************************************
// Getter-Funktionen
************************************************/
int Simulation::GetPedsNumber() const
{
return _nPeds;
......@@ -378,20 +362,6 @@ void Simulation::InitArgs(ArgumentParser* args)
_building->InitGeometry(); // create the polygons
_building->LoadTrafficInfo();
// 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);
......@@ -406,10 +376,17 @@ void Simulation::InitArgs(ArgumentParser* args)
// initialize the routing engine before doing any other things
routingEngine->Init(_building);
//this is very specific to the gcfm model
_building->InitPhiAllPeds(_deltaT);
//perform customs initialisation, like computing the phi for the gcfm
//this should be called after the routing engine has been initialised
// because a direction is needed for this initialisation.
_model->Init(_building);
//other initializations
const vector< Pedestrian* >& allPeds = _building->GetAllPedestrians();
for(Pedestrian *ped: allPeds)
{
ped->Setdt(_deltaT);
}
//pBuilding->WriteToErrorLog();
//get the seed
......@@ -419,7 +396,8 @@ void Simulation::InitArgs(ArgumentParser* args)
_building->SanityCheck();
//size of the cells/GCFM/Gompertz
if(args->GetDistEffMaxPed()>args->GetLinkedCellSize()){
Log->Write("ERROR: the linked-cell size [%f] should be bigger than the force range [%f]",args->GetLinkedCellSize(),args->GetDistEffMaxPed());
Log->Write("ERROR: the linked-cell size [%f] should be bigger than the force range [%f]",
args->GetLinkedCellSize(),args->GetDistEffMaxPed());
exit(EXIT_FAILURE);
}
......@@ -447,7 +425,6 @@ int Simulation::RunSimulation()
writeInterval = (writeInterval <= 0) ? 1 : writeInterval; // mustn't be <= 0
double t=0.0;
// writing the header
_iod->WriteHeader(_nPeds, _fps, _building,_seed);
_iod->WriteGeometry(_building);
......@@ -456,9 +433,10 @@ int Simulation::RunSimulation()
//first initialisation needed by the linked-cells
Update();
//needed to control the execution time
time_t starttime, endtime;
time(&starttime);
//needed to control the execution time PART 1
//in the case you want to run in no faster than realtime
//time_t starttime, endtime;
//time(&starttime);
// main program loop
for (t = 0; t < _tmax && _nPeds > 0; ++frameNr) {
......@@ -473,11 +451,11 @@ int Simulation::RunSimulation()
_iod->WriteFrame(frameNr / writeInterval, _building);
}
// in the case you want to run in no faster than realtime
// time(&endtime);
// double timeToWait=t-difftime(endtime, starttime);
// clock_t goal = timeToWait*1000 + clock();
// while (goal > clock());
// needed to control the execution time PART 2
// time(&endtime);
// double timeToWait=t-difftime(endtime, starttime);
// clock_t goal = timeToWait*1000 + clock();
// while (goal > clock());
}
// writing the footer
......@@ -486,10 +464,10 @@ int Simulation::RunSimulation()
//if(_hpc==1)
// ((GPU_GCFMModel*) _model)->DeleteBuffers();
//temporary work around since the total number of frame is only available at the end of the simulation.
if(_argsParser->GetFileFormat()==FORMAT_XML_BIN) {
delete _iod;
_iod=NULL;
delete _iod; _iod=NULL;
// char tmp[CLENGTH];
// int f= frameNr / writeInterval ;
......@@ -499,7 +477,8 @@ int Simulation::RunSimulation()
char replace[CLENGTH];
// open the file and replace the 8th line
sprintf(replace,"sed -i '9s/.*/ %d /' %s", frameNr/ writeInterval, _argsParser->GetTrajectoriesFile().c_str());
system(replace);
int result=system(replace);
Log->Write("INFO:\t Updating the framenumber exits with code [%d]",result);
}
//return the evacuation time
......
......@@ -45,7 +45,6 @@
#include "routing/DirectionStrategy.h"
#include "routing/DummyRouter.h"
#include "routing/GraphRouter.h"
#include "routing/NavMesh.h"
#include "routing/MeshRouter.h"
#include "routing/RoutingEngine.h"
#include "routing/SafestPathRouter.h"
......@@ -93,22 +92,11 @@ public:
Simulation();
virtual ~Simulation();
/**
* Initialize the number of agents in the simulation
*/
void SetPedsNumber(int i);
/**
* Initialize the number of agents in the simulation
*/
int GetPedsNumber() const;
/**
* Returns the number of agents when running on a distributed system (MPI)
* NOT IMPLEMENTED
*/
int GetNPedsGlobal() const;
/**
* @return the building object containing all geometry elements
*/
......@@ -140,6 +128,7 @@ public:
* Get the ProfileFlag
*/
bool GetProfileFlag();
/**
* Get the HPCFlag
*/
......
......@@ -117,7 +117,11 @@ void EventManager::readEventsTxt(double time){
char cstring[256];
int lines=0;
do{
fgets(cstring,30,_file);
if(fgets(cstring,30,_file)==NULL)
{
Log->Write("WARNING: \tCould not read the event file");
return;
}
if(cstring[0]!='#'){// keine Kommentarzeile
lines++;
if(lines>_eventCounter){
......@@ -244,7 +248,7 @@ void EventManager::openDoor(int id){
void EventManager::changeRouting(int id, string state){
RoutingEngine* routingEngine= _building->GetRoutingEngine();
routingEngine->Init(_building);
_building->InitPhiAllPeds(_deltaT);
//_building->InitPhiAllPeds(_deltaT);
const vector<Pedestrian*>& _allPedestrians=_building->GetAllPedestrians();
unsigned int nSize = _allPedestrians.size();
......
......@@ -68,34 +68,39 @@ Building::Building()
Building::~Building()
{
for (int i = 0; i < GetNumberOfRooms(); i++)
delete _rooms[i];
for (int i = 0; i < GetNumberOfRooms(); i++)
delete _rooms[i];
#ifdef _SIMULATOR
delete _routingEngine;
delete _linkedCellGrid;
for(unsigned int p=0;p<_allPedestians.size();p++)
{
//delete _allPedestians[p];
}
_allPedestians.clear();
delete _routingEngine;
delete _linkedCellGrid;
#endif
if (_pathWayStream.is_open())
_pathWayStream.close();
for (map<int, Crossing*>::const_iterator iter = _crossings.begin();
iter != _crossings.end(); ++iter) {
delete iter->second;
}
for (map<int, Transition*>::const_iterator iter = _transitions.begin();
iter != _transitions.end(); ++iter) {
delete iter->second;
}
for (map<int, Hline*>::const_iterator iter = _hLines.begin();
iter != _hLines.end(); ++iter) {
delete iter->second;
}
for (map<int, Goal*>::const_iterator iter = _goals.begin();
iter != _goals.end(); ++iter) {
delete iter->second;
}
if (_pathWayStream.is_open())
_pathWayStream.close();
for (map<int, Crossing*>::const_iterator iter = _crossings.begin();
iter != _crossings.end(); ++iter) {
delete iter->second;
}
for (map<int, Transition*>::const_iterator iter = _transitions.begin();
iter != _transitions.end(); ++iter) {
delete iter->second;
}
for (map<int, Hline*>::const_iterator iter = _hLines.begin();
iter != _hLines.end(); ++iter) {
delete iter->second;
}
for (map<int, Goal*>::const_iterator iter = _goals.begin();
iter != _goals.end(); ++iter) {
delete iter->second;
}
}
/************************************************************
......@@ -873,13 +878,10 @@ void Building::Update()
if ((ped->GetFinalDestination() == FINAL_DEST_OUT)
&& (GetRoom(ped->GetRoomID())->GetCaption() == "outside"))
{
pedsToRemove.push_back(ped);
//DeletePedestrian(ped);
} else if ((ped->GetFinalDestination() != FINAL_DEST_OUT)
&& (_goals[ped->GetFinalDestination()]->Contains(
ped->GetPos()))) {
//DeletePedestrian(ped);
pedsToRemove.push_back(ped);
} else if (!sub->IsInSubRoom(ped)) {
pedsToReposition.push_back(ped);
......@@ -910,7 +912,6 @@ void Building::Update()
break; // stop the loop
}
if (assigned == false) {
//DeletePedestrian(ped);
pedsToRemove.push_back(ped);
}
}
......@@ -934,7 +935,6 @@ void Building::Update()
unsigned int nSize = _allPedestians.size();
int nThreads = omp_get_max_threads();
int partSize = nSize / nThreads;
//assert(partSize!=0);
#pragma omp parallel default(shared) num_threads(nThreads)
{
......@@ -954,48 +954,9 @@ void Building::Update()
}
}
}
}
void Building::InitPhiAllPeds(double pDt)
{
for(unsigned int p=0;p<_allPedestians.size();p++)
{
Pedestrian* ped = _allPedestians[p];
double cosPhi, sinPhi;
ped->Setdt(pDt); //set the simulation step
//a destination could not be found for that pedestrian
if (ped->FindRoute() == -1) {
DeletePedestrian(ped);
//sub->DeletePedestrian(k--);
continue;
}
Line* e = ped->GetExitLine();
const Point& e1 = e->GetPoint1();
const Point& e2 = e->GetPoint2();
Point target = (e1 + e2) * 0.5;
Point d = target - ped->GetPos();
double dist = d.Norm();
if (dist != 0.0) {
cosPhi = d.GetX() / dist;
sinPhi = d.GetY() / dist;
} else {
Log->Write(
"ERROR: \tBuilding::InitPhiAllPeds() cannot initialise phi! "
"dist to target is 0\n");
exit(0);
}
JEllipse E = ped->GetEllipse();
E.SetCosPhi(cosPhi);
E.SetSinPhi(sinPhi);
ped->SetEllipse(E);
}
}
void Building::UpdateGrid()
{
_linkedCellGrid->Update(_allPedestians);
......@@ -1310,40 +1271,6 @@ void Building::InitSavePedPathway(const string &filename)
}
}
void Building::CleanUpTheScene()
{
//return;
static int counter = 0;
counter++;
static int totalSliced = 0;
int updateRate = 80.0 / 0.01; // 20 seconds/pDt
if (counter % updateRate == 0) {
for (unsigned int i = 0; i < _allPedestians.size(); i++) {
Pedestrian* ped = _allPedestians[i];
if (ped->GetDistanceSinceLastRecord() < 0.1) {
//delete from the simulation
DeletePedestrian(ped);
totalSliced++;
char msg[CLENGTH];
sprintf(msg, "INFO:\t slicing Ped %d from room %s, total [%d]",
ped->GetID(),
_rooms[ped->GetRoomID()]->GetCaption().c_str(),
totalSliced);
Log->Write(msg);
} else {
ped->RecordActualPosition();
}
}
}
}
void Building::StringExplode(string str, string separator,
vector<string>* results)
......
......@@ -167,7 +167,6 @@ public:
void InitGeometry();
void InitGrid(double cellSize);
//void InitRoomsAndSubroomsMap();
void InitPhiAllPeds(double pDt); // initialize the direction of the ellipses
void InitSavePedPathway(const std::string &filename);
void AddRoom(Room* room);
void Update();
......@@ -194,8 +193,6 @@ public:
void LoadRoutingInfo(const std::string &filename);
void WriteToErrorLog() const;
void CleanUpTheScene();
/**
* Check the scenario for possible errors and
* output user specific informations.
......
......@@ -28,7 +28,7 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
</routing>
<!--persons information and distribution -->
<agents operational_model_id="1">
<agents operational_model_id="2">
<agents_distribution>
<group group_id="0" agent_parameter_id="1" room_id="0" subroom_id="0" number="10" goal_id="-1" router_id="1" />
</agents_distribution>
......@@ -36,26 +36,62 @@ xsi:noNamespaceSchemaLocation="http://134.94.2.137/jps_ini_core.xsd">
</agents>
<!-- These parameters may be overwritten -->
<operational_models>
<model operational_model_id="1" description="gcfm">
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exitCrossingStrategy>3</exitCrossingStrategy>
<linkedcells enabled="true" cell_size="2.2" />
<force_ped nu="0.3" dist_max="3" disteff_max="2" interpolation_width="0.1" />
<force_wall nu="0.2" dist_max="3" disteff_max="2" interpolation_width="0.1" />
</model_parameters>
<agent_parameters agent_parameter_id="1">
<v0 mu="1.24" sigma="0.001" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
</model>
</operational_models>
<operational_models>
<model operational_model_id="1" description="gcfm">
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exitCrossingStrategy>4</exitCrossingStrategy>
<linkedcells enabled="true" cell_size="2.2" />
<force_ped nu="0.3" dist_max="3" disteff_max="2" interpolation_width="0.1" />
<force_wall nu="0.2" dist_max="3" disteff_max="2" interpolation_width="0.1" />
</model_parameters>
<agent_parameters agent_parameter_id="1">
<v0 mu="0.5" sigma="0.0" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
<agent_parameters agent_parameter_id="2">
<v0 mu="0.5" sigma="0.0" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
</model>
<model operational_model_id="2" description="gompertz">
<model_parameters>
<solver>euler</solver>
<stepsize>0.01</stepsize>
<exitCrossingStrategy>3</exitCrossingStrategy>
<linkedcells enabled="true" cell_size="2.2" />
<force_ped nu="3" b="0.25" c="3.0"/>
<force_wall nu="10" b="0.70" c="3.0"/>
</model_parameters>
<agent_parameters agent_parameter_id="1">
<v0 mu="0.5" sigma="0.0" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
<agent_parameters agent_parameter_id="2">
<v0 mu="0" sigma="0.0" />
<bmax mu="0.25" sigma="0.001" />
<bmin mu="0.20" sigma="0.001" />
<amin mu="0.18" sigma="0.001" />
<tau mu="0.5" sigma="0.001" />
<atau mu="0.5" sigma="0.001" />
</agent_parameters>
</model>
</operational_models>
<route_choice_models>
<router router_id="1" description="global_shortest">
......
......@@ -26,17 +26,13 @@
*
**/
#include "geometry/Building.h"
#include "general/ArgumentParser.h"
#include "./Simulation.h"
int main(int argc, char **argv)
{
//gathering some statistics about the runtime
time_t starttime, endtime;
......
......@@ -62,6 +62,12 @@ public:
*/
virtual void CalculateForce(double t, double tp, Building* building) const = 0;
/**
* Performs whatever initialization is needed/required
* @param building the building object
*/
virtual void Init (Building* building) const = 0;
/**
* @return all model parameters in a nicely formatted string
*/
......
......@@ -68,6 +68,41 @@ GCFMModel::~GCFMModel(void)
}
void GCFMModel::Init (Building* building) const
{
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++)
{
Pedestrian* ped = allPeds[p];
double cosPhi, sinPhi;
//a destination could not be found for that pedestrian
if (ped->FindRoute() == -1) {
building->DeletePedestrian(ped);
continue;
}
Line* e = ped->GetExitLine();
const Point& e1 = e->GetPoint1();
const Point& e2 = e->GetPoint2();
Point target = (e1 + e2) * 0.5;
Point d = target - ped->GetPos();
double dist = d.Norm();
if (dist != 0.0) {
cosPhi = d.GetX() / dist;
sinPhi = d.GetY() / dist;
} else {
Log->Write(
"ERROR: \allPeds::Init() cannot initialise phi! "
"dist to target is 0\n");
exit(EXIT_FAILURE);
}
JEllipse E = ped->GetEllipse();
E.SetCosPhi(cosPhi);
E.SetSinPhi(sinPhi);
ped->SetEllipse(E);
}
}
inline Point GCFMModel::ForceDriv(Pedestrian* ped, Room* room) const
{
const Point& target = _direction->GetTarget(room, ped);
......
......@@ -70,6 +70,7 @@ public:
// virtual function
virtual void CalculateForce(double t, double tp, Building* building) const;
virtual std::string writeParameter() const;
virtual void Init (Building* building) const;
private:
/// define the strategy for crossing a door (used for calculating the driving force)
......
......@@ -68,13 +68,49 @@ GompertzModel::GompertzModel(DirectionStrategy* dir, double nuped, double aped,
}
GompertzModel::~GompertzModel(void) { }
GompertzModel::~GompertzModel() { }
void GompertzModel::Init (Building* building) const
{
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++)