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

Cleaning and memomry management.

parent 9fd5ea1e
...@@ -213,6 +213,7 @@ bool Simulation::InitArgs(const ArgumentParser& args) ...@@ -213,6 +213,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
_fps = args.Getfps(); _fps = args.Getfps();
sprintf(tmp, "\tfps: %f\n", _fps); sprintf(tmp, "\tfps: %f\n", _fps);
s.append(tmp); s.append(tmp);
//Log->Write(s.c_str());
_routingEngine = args.GetRoutingEngine(); _routingEngine = args.GetRoutingEngine();
auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed())); auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed()));
...@@ -220,6 +221,7 @@ bool Simulation::InitArgs(const ArgumentParser& args) ...@@ -220,6 +221,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
_building = std::unique_ptr<Building>(new Building(args.GetProjectFile(), args.GetProjectRootDir(), *_routingEngine, *distributor, args.GetLinkedCellSize())); _building = std::unique_ptr<Building>(new Building(args.GetProjectFile(), args.GetProjectRootDir(), *_routingEngine, *distributor, args.GetLinkedCellSize()));
// Initialize the agents sources that have been collected in the pedestrians distributor // Initialize the agents sources that have been collected in the pedestrians distributor
_agentSrcManager.SetBuilding(_building.get());
for (const auto& src: distributor->GetAgentsSources()) for (const auto& src: distributor->GetAgentsSources())
{ {
_agentSrcManager.AddSource(src); _agentSrcManager.AddSource(src);
......
...@@ -77,7 +77,7 @@ ArgumentParser::ArgumentParser() ...@@ -77,7 +77,7 @@ ArgumentParser::ArgumentParser()
//pNumberFilename = "inputfiles/persons.xml"; //pNumberFilename = "inputfiles/persons.xml";
pSolver = 1; pSolver = 1;
_projectFile = ""; _projectFile = "";
pTmax = 500; pTmax = 900;
pfps = 1.0; pfps = 1.0;
pdt = 0.01; pdt = 0.01;
pExitStrategy = 2; pExitStrategy = 2;
...@@ -116,13 +116,13 @@ ArgumentParser::ArgumentParser() ...@@ -116,13 +116,13 @@ ArgumentParser::ArgumentParser()
pSeed = 0; pSeed = 0;
pFormat = FORMAT_XML_PLAIN; pFormat = FORMAT_XML_PLAIN;
pPort = -1; pPort = -1;
pHostname = "localhost"; _hostname = "localhost";
_embedMesh = 0; _embedMesh = 0;
pMaxOpenMPThreads = omp_get_thread_num(); _maxOpenMPThreads = omp_get_thread_num();
_profilingFlag = false; _profilingFlag = false;
_hpcFlag = 0; _hpcFlag = 0;
_agentsParameters= std::map<int, std::shared_ptr<AgentsParameters> >(); _agentsParameters= std::map<int, std::shared_ptr<AgentsParameters> >();
p_routingengine = std::shared_ptr<RoutingEngine>(new RoutingEngine()); _routingengine = std::shared_ptr<RoutingEngine>(new RoutingEngine());
_showStatistics=false; _showStatistics=false;
} }
...@@ -276,19 +276,19 @@ bool ArgumentParser::ParseIniFile(string inifile) ...@@ -276,19 +276,19 @@ bool ArgumentParser::ParseIniFile(string inifile)
else { else {
n = max_cpus; n = max_cpus;
} }
pMaxOpenMPThreads = n; _maxOpenMPThreads = n;
Log->Write("INFO: \tnum_threads <%d>", pMaxOpenMPThreads); Log->Write("INFO: \tnum_threads <%d>", _maxOpenMPThreads);
#ifdef _OPENMP #ifdef _OPENMP
if(n < omp_get_max_threads() ) if(n < omp_get_max_threads() )
omp_set_num_threads(pMaxOpenMPThreads); omp_set_num_threads(_maxOpenMPThreads);
#endif #endif
} }
else { // no num_threads tag else { // no num_threads tag
pMaxOpenMPThreads = max_cpus; _maxOpenMPThreads = max_cpus;
#ifdef _OPENMP #ifdef _OPENMP
omp_set_num_threads(pMaxOpenMPThreads); omp_set_num_threads(_maxOpenMPThreads);
#endif #endif
Log->Write("INFO: \t Default num_threads <%d>", pMaxOpenMPThreads); Log->Write("INFO: \t Default num_threads <%d>", _maxOpenMPThreads);
} }
//logfile //logfile
if (xMainNode->FirstChild("logfile")) if (xMainNode->FirstChild("logfile"))
...@@ -355,10 +355,10 @@ bool ArgumentParser::ParseIniFile(string inifile) ...@@ -355,10 +355,10 @@ bool ArgumentParser::ParseIniFile(string inifile)
const char* tmp = const char* tmp =
xTrajectories->FirstChildElement("socket")->Attribute("hostname"); xTrajectories->FirstChildElement("socket")->Attribute("hostname");
if (tmp) if (tmp)
pHostname = tmp; _hostname = tmp;
xTrajectories->FirstChildElement("socket")->Attribute("port", &pPort); xTrajectories->FirstChildElement("socket")->Attribute("port", &pPort);
Log->Write("INFO: \tStreaming results to output [%s:%d] ", Log->Write("INFO: \tStreaming results to output [%s:%d] ",
pHostname.c_str(), pPort); _hostname.c_str(), pPort);
} }
} }
...@@ -744,37 +744,37 @@ bool ArgumentParser::ParseRoutingStrategies(TiXmlNode *routingNode) ...@@ -744,37 +744,37 @@ bool ArgumentParser::ParseRoutingStrategies(TiXmlNode *routingNode)
if (strategy == "local_shortest") { if (strategy == "local_shortest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_LOCAL_SHORTEST)); pRoutingStrategies.push_back(make_pair(id, ROUTING_LOCAL_SHORTEST));
Router *r = new GlobalRouter(id, ROUTING_LOCAL_SHORTEST); Router *r = new GlobalRouter(id, ROUTING_LOCAL_SHORTEST);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "global_shortest") { else if (strategy == "global_shortest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_GLOBAL_SHORTEST)); pRoutingStrategies.push_back(make_pair(id, ROUTING_GLOBAL_SHORTEST));
Router *r = new GlobalRouter(id, ROUTING_GLOBAL_SHORTEST); Router *r = new GlobalRouter(id, ROUTING_GLOBAL_SHORTEST);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "quickest") { else if (strategy == "quickest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_QUICKEST)); pRoutingStrategies.push_back(make_pair(id, ROUTING_QUICKEST));
Router *r = new QuickestPathRouter(id, ROUTING_QUICKEST); Router *r = new QuickestPathRouter(id, ROUTING_QUICKEST);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "nav_mesh") { else if (strategy == "nav_mesh") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_NAV_MESH)); pRoutingStrategies.push_back(make_pair(id, ROUTING_NAV_MESH));
Router *r = new MeshRouter(id, ROUTING_NAV_MESH); Router *r = new MeshRouter(id, ROUTING_NAV_MESH);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "dummy") { else if (strategy == "dummy") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_DUMMY)); pRoutingStrategies.push_back(make_pair(id, ROUTING_DUMMY));
Router *r = new DummyRouter(id, ROUTING_DUMMY); Router *r = new DummyRouter(id, ROUTING_DUMMY);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "global_safest") { else if (strategy == "global_safest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_SAFEST)); pRoutingStrategies.push_back(make_pair(id, ROUTING_SAFEST));
Router *r = new SafestPathRouter(id, ROUTING_SAFEST); Router *r = new SafestPathRouter(id, ROUTING_SAFEST);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
} }
else if (strategy == "cognitive_map") { else if (strategy == "cognitive_map") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_COGNITIVEMAP)); pRoutingStrategies.push_back(make_pair(id, ROUTING_COGNITIVEMAP));
Router *r = new CognitiveMapRouter(id, ROUTING_COGNITIVEMAP); Router *r = new CognitiveMapRouter(id, ROUTING_COGNITIVEMAP);
p_routingengine->AddRouter(r); _routingengine->AddRouter(r);
Log->Write("\nINFO: \tUsing CognitiveMapRouter"); Log->Write("\nINFO: \tUsing CognitiveMapRouter");
///Parsing additional options ///Parsing additional options
...@@ -802,7 +802,7 @@ bool ArgumentParser::ParseCogMapOpts(TiXmlNode *routerNode) ...@@ -802,7 +802,7 @@ bool ArgumentParser::ParseCogMapOpts(TiXmlNode *routerNode)
} }
/// static_cast to get access to the method 'addOption' of the CognitiveMapRouter /// static_cast to get access to the method 'addOption' of the CognitiveMapRouter
CognitiveMapRouter* r = static_cast<CognitiveMapRouter*>(p_routingengine->GetAvailableRouters().back()); CognitiveMapRouter* r = static_cast<CognitiveMapRouter*>(_routingengine->GetAvailableRouters().back());
std::vector<std::string> sensorVec; std::vector<std::string> sensorVec;
for (TiXmlElement* e = sensorNode->FirstChildElement("sensor"); e; for (TiXmlElement* e = sensorNode->FirstChildElement("sensor"); e;
...@@ -927,11 +927,11 @@ const FileFormat& ArgumentParser::GetFileFormat() const ...@@ -927,11 +927,11 @@ const FileFormat& ArgumentParser::GetFileFormat() const
} }
const string& ArgumentParser::GetHostname() const const string& ArgumentParser::GetHostname() const
{ {
return pHostname; return _hostname;
} }
void ArgumentParser::SetHostname(const string& hostname) void ArgumentParser::SetHostname(const string& hostname)
{ {
pHostname = hostname; _hostname = hostname;
} }
int ArgumentParser::GetPort() const int ArgumentParser::GetPort() const
{ {
...@@ -984,7 +984,7 @@ bool ArgumentParser::GetLinkedCells() const ...@@ -984,7 +984,7 @@ bool ArgumentParser::GetLinkedCells() const
std::shared_ptr<RoutingEngine> ArgumentParser::GetRoutingEngine() const std::shared_ptr<RoutingEngine> ArgumentParser::GetRoutingEngine() const
{ {
return p_routingengine; return _routingengine;
} }
vector<pair<int, RoutingStrategy> > ArgumentParser::GetRoutingStrategy() const vector<pair<int, RoutingStrategy> > ArgumentParser::GetRoutingStrategy() const
...@@ -1151,7 +1151,7 @@ const string& ArgumentParser::GetErrorLogFile() const ...@@ -1151,7 +1151,7 @@ const string& ArgumentParser::GetErrorLogFile() const
int ArgumentParser::GetMaxOpenMPThreads() const int ArgumentParser::GetMaxOpenMPThreads() const
{ {
return pMaxOpenMPThreads; return _maxOpenMPThreads;
} }
const string& ArgumentParser::GetTrajectoriesFile() const const string& ArgumentParser::GetTrajectoriesFile() const
{ {
......
...@@ -53,7 +53,7 @@ class ArgumentParser ...@@ -53,7 +53,7 @@ class ArgumentParser
{ {
private: private:
string pHostname; string _hostname;
string pTrajectoriesFile; string pTrajectoriesFile;
string pErrorLogFile; string pErrorLogFile;
string pNavMeshFilename; string pNavMeshFilename;
...@@ -96,7 +96,7 @@ private: ...@@ -96,7 +96,7 @@ private:
int pLog; int pLog;
int pPort; int pPort;
int _embedMesh; int _embedMesh;
int pMaxOpenMPThreads; int _maxOpenMPThreads;
int pModel; int pModel;
FileFormat pFormat; FileFormat pFormat;
vector<pair<int, RoutingStrategy> > pRoutingStrategies; vector<pair<int, RoutingStrategy> > pRoutingStrategies;
...@@ -110,7 +110,7 @@ private: ...@@ -110,7 +110,7 @@ private:
*/ */
std::shared_ptr<DirectionStrategy> p_exit_strategy; std::shared_ptr<DirectionStrategy> p_exit_strategy;
std::shared_ptr<OperationalModel> p_op_model; std::shared_ptr<OperationalModel> p_op_model;
std::shared_ptr<RoutingEngine> p_routingengine; std::shared_ptr<RoutingEngine> _routingengine;
private: private:
bool ParseGCFMModel(TiXmlElement* xGCFM); bool ParseGCFMModel(TiXmlElement* xGCFM);
......
...@@ -937,7 +937,6 @@ void Building::InitGrid(double cellSize) ...@@ -937,7 +937,6 @@ void Building::InitGrid(double cellSize)
y_max = y_max + 1*cellSize; y_max = y_max + 1*cellSize;
double boundaries[4] = { x_min, x_max, y_min, y_max }; double boundaries[4] = { x_min, x_max, y_min, y_max };
int pedsCount = _allPedestians.size();
//no algorithms //no algorithms
// the domain is made of a single cell // the domain is made of a single cell
...@@ -953,7 +952,8 @@ void Building::InitGrid(double cellSize) ...@@ -953,7 +952,8 @@ void Building::InitGrid(double cellSize)
Log->Write("INFO: \tInitializing the grid with cell size: %f ", cellSize); Log->Write("INFO: \tInitializing the grid with cell size: %f ", cellSize);
} }
_linkedCellGrid = new LCGrid(boundaries, cellSize, pedsCount); //_linkedCellGrid = new LCGrid(boundaries, cellSize, _allPedestians.size());
_linkedCellGrid = new LCGrid(boundaries, cellSize, Pedestrian::GetAgentsCreated());
_linkedCellGrid->ShallowCopy(_allPedestians); _linkedCellGrid->ShallowCopy(_allPedestians);
Log->Write("INFO: \tDone with Initializing the grid "); Log->Write("INFO: \tDone with Initializing the grid ");
...@@ -1169,9 +1169,12 @@ void Building::AddPedestrian(Pedestrian* ped) ...@@ -1169,9 +1169,12 @@ void Building::AddPedestrian(Pedestrian* ped)
void Building::GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const void Building::GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const
{ {
for(unsigned int p = 0;p<_allPedestians.size();p++){ //for(unsigned int p = 0;p<_allPedestians.size();p++){
Pedestrian* ped=_allPedestians[p]; // Pedestrian* ped=_allPedestians[p];
if(room==ped->GetRoomID() && subroom==ped->GetSubRoomID())
for (auto&& ped : _allPedestians)
{
if ((room == ped->GetRoomID()) && (subroom == ped->GetSubRoomID()))
{ {
peds.push_back(ped); peds.push_back(ped);
} }
......
...@@ -75,7 +75,7 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd"> ...@@ -75,7 +75,7 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
</agents_distribution> </agents_distribution>
<agents_sources><!-- frequency in persons/minute --> <agents_sources><!-- frequency in persons/minute -->
<source id="1" frequency="1" agents_max="10" group_id="0" caption="source 1"> <source id="1" frequency="1" agents_max="100" group_id="0" caption="source 1">
</source> </source>
</agents_sources> </agents_sources>
......
This diff is collapsed.
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
* *
**/ **/
#ifndef LCGRID_H_ #ifndef LCGRID_H_
#define LCGRID_H_ #define LCGRID_H_
...@@ -44,29 +43,27 @@ ...@@ -44,29 +43,27 @@
class Pedestrian; class Pedestrian;
class Building; class Building;
class LCGrid
class LCGrid { {
private: private:
/// the 'first' pedestrian in each cell /// the 'first' pedestrian in each cell
int **pCellHead; int **_cellHead;
/// the next pedestrians. more efficient than the double linked- list /// the next pedestrians. more efficient than the double linked- list
int *pList; int *_list;
/// number of cells in x- and y-direction respectively. /// number of cells in x- and y-direction respectively.
/// Also to be interpreted as cell coordinates in the grid /// Also to be interpreted as cell coordinates in the grid
int pGridSizeX, pGridSizeY; int _gridSizeX, _gridSizeY;
/// the cell size default to 2.2 metres /// the cell size default to 2.2 metres
double pCellSize; double _cellSize;
/// rectangular area for linked cells which covers the whole geometry /// rectangular area for linked cells which covers the whole geometry
double pGrid_xmin, pGrid_xmax, pGrid_ymin, pGrid_ymax; double _gridXmin, _gridXmax, _gridYmin, _gridYmax;
/// for convenience /// for convenience
/// will be delete in next versions /// will be delete in next versions
Pedestrian** pLocalPedsCopy; Pedestrian** _localPedsCopy;
///total number of pedestrians ///total number of pedestrians
int pNpeds; int _nPeds;
public: public:
/** /**
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "AgentsSource.h" #include "AgentsSource.h"
#include "Pedestrian.h" #include "Pedestrian.h"
#include "StartDistribution.h"
#include "../IO/OutputHandler.h" #include "../IO/OutputHandler.h"
#include <iostream> #include <iostream>
...@@ -64,6 +65,14 @@ const double* AgentsSource::GetBoundaries() const ...@@ -64,6 +65,14 @@ const double* AgentsSource::GetBoundaries() const
return _boundaries; return _boundaries;
} }
void AgentsSource::Setboundaries(double * bounds)
{
_boundaries[0]=bounds[0];
_boundaries[1]=bounds[1];
_boundaries[2]=bounds[2];
_boundaries[3]=bounds[3];
}
const std::string& AgentsSource::GetCaption() const const std::string& AgentsSource::GetCaption() const
{ {
return _caption; return _caption;
...@@ -88,6 +97,12 @@ int AgentsSource::GetMaxAgents() const ...@@ -88,6 +97,12 @@ int AgentsSource::GetMaxAgents() const
{ {
return _maxAgents; return _maxAgents;
} }
void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution)
{
_startDistribution=startDistribution;
}
void AgentsSource::Dump() const void AgentsSource::Dump() const
{ {
Log->Write("\n--------------------------"); Log->Write("\n--------------------------");
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
class Pedestrian; class Pedestrian;
class OutputHandler; class OutputHandler;
class StartDistribution;
// external variables // external variables
extern OutputHandler* Log; extern OutputHandler* Log;
...@@ -59,11 +61,13 @@ public: ...@@ -59,11 +61,13 @@ public:
int GetAgentsGenerated() const; int GetAgentsGenerated() const;
void SetAgentsGenerated(int agentsGenerated); void SetAgentsGenerated(int agentsGenerated);
const double* GetBoundaries() const; const double* GetBoundaries() const;
void Setboundaries(double * bounds);
const std::string& GetCaption() const; const std::string& GetCaption() const;
int GetFrequency() const; int GetFrequency() const;
int GetGroupId() const; int GetGroupId() const;
int GetId() const; int GetId() const;
int GetMaxAgents() const; int GetMaxAgents() const;
void SetStartDistribution(std::shared_ptr<StartDistribution>);
private: private:
...@@ -75,6 +79,7 @@ private: ...@@ -75,6 +79,7 @@ private:
double _boundaries [4] = {0,0,0,0}; double _boundaries [4] = {0,0,0,0};
std::string _caption="no caption"; std::string _caption="no caption";
std::vector<Pedestrian*> _agents; std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution;
}; };
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
#include "Pedestrian.h" #include "Pedestrian.h"
#include "AgentsQueue.h" #include "AgentsQueue.h"
#include "AgentsSource.h" #include "AgentsSource.h"
#include "../voronoi/VoronoiDiagramGenerator.h"
#include "../geometry/Building.h"
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <chrono> #include <chrono>
...@@ -29,35 +32,89 @@ void AgentsSourcesManager::operator()(int value) ...@@ -29,35 +32,89 @@ void AgentsSourcesManager::operator()(int value)
//the loop is updated each second. //the loop is updated each second.
//it might be better to use a timer //it might be better to use a timer
bool finished=false; bool finished=false;
long updateFrequency=5;// 1 second
do do
{ {
finished=true;
for (const auto& src: _sources) int current_time = Pedestrian::GetGlobalTime();
if ( (current_time != _lastUpdateTime) &&
((current_time % updateFrequency) == 0))
{ {
if(src->GetPoolSize())
{
vector<Pedestrian*> peds;
src->GenerateByFrequency(peds);
AgentsQueue::Add(peds);
// compute the optimal position for insertion finished=true;
for (auto&& ped: peds) for (const auto& src: _sources)
{
if(src->GetPoolSize())
{ {
ped->SetPos(Point(15,15),true); vector<Pedestrian*> peds;
src->GenerateByFrequency(peds);
AgentsQueue::Add(peds);
ComputeBestPosition(src.get());
// compute the optimal position for insertion
for (auto&& ped: peds)
{
ped->SetPos(Point(15,15),true);
}
finished=false;
//cout<<"Agents generated: "<<peds.size()<<endl;
} }
finished=false; //src->Dump();
cout<<"Agents generated: "<<peds.size()<<endl;
} }
//src->Dump(); _lastUpdateTime = current_time;
} }
//cout<<"Number of sources: "<<_sources.size()<<endl; //wait some time
std::this_thread::sleep_for(std::chrono::milliseconds(10));
//wait one second
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}while (!finished); }while (!finished);
} }
void AgentsSourcesManager::ComputeBestPosition(AgentsSource* src)
{
int roomID=0;
int subroomID=0;
//Get all pedestrians in that location
vector<Pedestrian*> peds;
_building->GetPedestrians(roomID,subroomID,peds);
// compute the cells and cut with the bounds
const int count=peds.size();
float xValues[count];
float yValues[count];
for(int i=0;i<count;i++)
{
xValues[i]=peds[i]->GetPos()._x;
yValues[i]=peds[i]->GetPos()._y;
}
VoronoiDiagramGenerator vdg;
vdg.generateVoronoi(xValues,yValues,count, -100,100,-100,100,3);
vdg.resetIterator();
vdg.resetVerticesIterator();
float x1,y1;
printf("\n------vertices---------\n");
while(vdg.getNextVertex(x1,y1))
{
printf("GOT Point (%f,%f)\n",x1,y1);
}
//exit(0);
// float x1,y1,x2,y2;
//while(vdg.getNext(x1,y1,x2,y2))
//{
// printf("GOT Line (%f,%f)->(%f,%f)\n",x1,y1,x2, y2);