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)
_fps = args.Getfps();
sprintf(tmp, "\tfps: %f\n", _fps);
s.append(tmp);
//Log->Write(s.c_str());
_routingEngine = args.GetRoutingEngine();
auto distributor = std::unique_ptr<PedDistributor>(new PedDistributor(_argsParser.GetProjectFile(), _argsParser.GetAgentsParameters(),_argsParser.GetSeed()));
......@@ -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()));
// Initialize the agents sources that have been collected in the pedestrians distributor
_agentSrcManager.SetBuilding(_building.get());
for (const auto& src: distributor->GetAgentsSources())
{
_agentSrcManager.AddSource(src);
......
......@@ -77,7 +77,7 @@ ArgumentParser::ArgumentParser()
//pNumberFilename = "inputfiles/persons.xml";
pSolver = 1;
_projectFile = "";
pTmax = 500;
pTmax = 900;
pfps = 1.0;
pdt = 0.01;
pExitStrategy = 2;
......@@ -116,13 +116,13 @@ ArgumentParser::ArgumentParser()
pSeed = 0;
pFormat = FORMAT_XML_PLAIN;
pPort = -1;
pHostname = "localhost";
_hostname = "localhost";
_embedMesh = 0;
pMaxOpenMPThreads = omp_get_thread_num();
_maxOpenMPThreads = omp_get_thread_num();
_profilingFlag = false;
_hpcFlag = 0;
_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;
}
......@@ -276,19 +276,19 @@ bool ArgumentParser::ParseIniFile(string inifile)
else {
n = max_cpus;
}
pMaxOpenMPThreads = n;
Log->Write("INFO: \tnum_threads <%d>", pMaxOpenMPThreads);
_maxOpenMPThreads = n;
Log->Write("INFO: \tnum_threads <%d>", _maxOpenMPThreads);
#ifdef _OPENMP
if(n < omp_get_max_threads() )
omp_set_num_threads(pMaxOpenMPThreads);
omp_set_num_threads(_maxOpenMPThreads);
#endif
}
else { // no num_threads tag
pMaxOpenMPThreads = max_cpus;
_maxOpenMPThreads = max_cpus;
#ifdef _OPENMP
omp_set_num_threads(pMaxOpenMPThreads);
omp_set_num_threads(_maxOpenMPThreads);
#endif
Log->Write("INFO: \t Default num_threads <%d>", pMaxOpenMPThreads);
Log->Write("INFO: \t Default num_threads <%d>", _maxOpenMPThreads);
}
//logfile
if (xMainNode->FirstChild("logfile"))
......@@ -355,10 +355,10 @@ bool ArgumentParser::ParseIniFile(string inifile)
const char* tmp =
xTrajectories->FirstChildElement("socket")->Attribute("hostname");
if (tmp)
pHostname = tmp;
_hostname = tmp;
xTrajectories->FirstChildElement("socket")->Attribute("port", &pPort);
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)
if (strategy == "local_shortest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_LOCAL_SHORTEST));
Router *r = new GlobalRouter(id, ROUTING_LOCAL_SHORTEST);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "global_shortest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_GLOBAL_SHORTEST));
Router *r = new GlobalRouter(id, ROUTING_GLOBAL_SHORTEST);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "quickest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_QUICKEST));
Router *r = new QuickestPathRouter(id, ROUTING_QUICKEST);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "nav_mesh") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_NAV_MESH));
Router *r = new MeshRouter(id, ROUTING_NAV_MESH);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "dummy") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_DUMMY));
Router *r = new DummyRouter(id, ROUTING_DUMMY);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "global_safest") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_SAFEST));
Router *r = new SafestPathRouter(id, ROUTING_SAFEST);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
}
else if (strategy == "cognitive_map") {
pRoutingStrategies.push_back(make_pair(id, ROUTING_COGNITIVEMAP));
Router *r = new CognitiveMapRouter(id, ROUTING_COGNITIVEMAP);
p_routingengine->AddRouter(r);
_routingengine->AddRouter(r);
Log->Write("\nINFO: \tUsing CognitiveMapRouter");
///Parsing additional options
......@@ -802,7 +802,7 @@ bool ArgumentParser::ParseCogMapOpts(TiXmlNode *routerNode)
}
/// 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;
for (TiXmlElement* e = sensorNode->FirstChildElement("sensor"); e;
......@@ -927,11 +927,11 @@ const FileFormat& ArgumentParser::GetFileFormat() const
}
const string& ArgumentParser::GetHostname() const
{
return pHostname;
return _hostname;
}
void ArgumentParser::SetHostname(const string& hostname)
{
pHostname = hostname;
_hostname = hostname;
}
int ArgumentParser::GetPort() const
{
......@@ -984,7 +984,7 @@ bool ArgumentParser::GetLinkedCells() const
std::shared_ptr<RoutingEngine> ArgumentParser::GetRoutingEngine() const
{
return p_routingengine;
return _routingengine;
}
vector<pair<int, RoutingStrategy> > ArgumentParser::GetRoutingStrategy() const
......@@ -1151,7 +1151,7 @@ const string& ArgumentParser::GetErrorLogFile() const
int ArgumentParser::GetMaxOpenMPThreads() const
{
return pMaxOpenMPThreads;
return _maxOpenMPThreads;
}
const string& ArgumentParser::GetTrajectoriesFile() const
{
......
......@@ -53,7 +53,7 @@ class ArgumentParser
{
private:
string pHostname;
string _hostname;
string pTrajectoriesFile;
string pErrorLogFile;
string pNavMeshFilename;
......@@ -96,7 +96,7 @@ private:
int pLog;
int pPort;
int _embedMesh;
int pMaxOpenMPThreads;
int _maxOpenMPThreads;
int pModel;
FileFormat pFormat;
vector<pair<int, RoutingStrategy> > pRoutingStrategies;
......@@ -110,7 +110,7 @@ private:
*/
std::shared_ptr<DirectionStrategy> p_exit_strategy;
std::shared_ptr<OperationalModel> p_op_model;
std::shared_ptr<RoutingEngine> p_routingengine;
std::shared_ptr<RoutingEngine> _routingengine;
private:
bool ParseGCFMModel(TiXmlElement* xGCFM);
......
......@@ -937,7 +937,6 @@ void Building::InitGrid(double cellSize)
y_max = y_max + 1*cellSize;
double boundaries[4] = { x_min, x_max, y_min, y_max };
int pedsCount = _allPedestians.size();
//no algorithms
// the domain is made of a single cell
......@@ -953,7 +952,8 @@ void Building::InitGrid(double 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);
Log->Write("INFO: \tDone with Initializing the grid ");
......@@ -1169,9 +1169,12 @@ void Building::AddPedestrian(Pedestrian* ped)
void Building::GetPedestrians(int room, int subroom, std::vector<Pedestrian*>& peds) const
{
for(unsigned int p = 0;p<_allPedestians.size();p++){
Pedestrian* ped=_allPedestians[p];
if(room==ped->GetRoomID() && subroom==ped->GetSubRoomID())
//for(unsigned int p = 0;p<_allPedestians.size();p++){
// Pedestrian* ped=_allPedestians[p];
for (auto&& ped : _allPedestians)
{
if ((room == ped->GetRoomID()) && (subroom == ped->GetSubRoomID()))
{
peds.push_back(ped);
}
......
......@@ -75,7 +75,7 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
</agents_distribution>
<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>
</agents_sources>
......
This diff is collapsed.
......@@ -32,7 +32,6 @@
*
**/
#ifndef LCGRID_H_
#define LCGRID_H_
......@@ -44,29 +43,27 @@
class Pedestrian;
class Building;
class LCGrid {
class LCGrid
{
private:
/// the 'first' pedestrian in each cell
int **pCellHead;
int **_cellHead;
/// the next pedestrians. more efficient than the double linked- list
int *pList;
int *_list;
/// number of cells in x- and y-direction respectively.
/// Also to be interpreted as cell coordinates in the grid
int pGridSizeX, pGridSizeY;
int _gridSizeX, _gridSizeY;
/// the cell size default to 2.2 metres
double pCellSize;
double _cellSize;
/// 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
/// will be delete in next versions
Pedestrian** pLocalPedsCopy;
Pedestrian** _localPedsCopy;
///total number of pedestrians
int pNpeds;
int _nPeds;
public:
/**
......
......@@ -7,6 +7,7 @@
#include "AgentsSource.h"
#include "Pedestrian.h"
#include "StartDistribution.h"
#include "../IO/OutputHandler.h"
#include <iostream>
......@@ -64,6 +65,14 @@ const double* AgentsSource::GetBoundaries() const
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
{
return _caption;
......@@ -88,6 +97,12 @@ int AgentsSource::GetMaxAgents() const
{
return _maxAgents;
}
void AgentsSource::SetStartDistribution(std::shared_ptr<StartDistribution> startDistribution)
{
_startDistribution=startDistribution;
}
void AgentsSource::Dump() const
{
Log->Write("\n--------------------------");
......
......@@ -10,9 +10,11 @@
#include <string>
#include <vector>
#include <memory>
class Pedestrian;
class OutputHandler;
class StartDistribution;
// external variables
extern OutputHandler* Log;
......@@ -59,11 +61,13 @@ public:
int GetAgentsGenerated() const;
void SetAgentsGenerated(int agentsGenerated);
const double* GetBoundaries() const;
void Setboundaries(double * bounds);
const std::string& GetCaption() const;
int GetFrequency() const;
int GetGroupId() const;
int GetId() const;
int GetMaxAgents() const;
void SetStartDistribution(std::shared_ptr<StartDistribution>);
private:
......@@ -75,6 +79,7 @@ private:
double _boundaries [4] = {0,0,0,0};
std::string _caption="no caption";
std::vector<Pedestrian*> _agents;
std::shared_ptr<StartDistribution> _startDistribution;
};
......
......@@ -9,6 +9,9 @@
#include "Pedestrian.h"
#include "AgentsQueue.h"
#include "AgentsSource.h"
#include "../voronoi/VoronoiDiagramGenerator.h"
#include "../geometry/Building.h"
#include <iostream>
#include <thread>
#include <chrono>
......@@ -29,35 +32,89 @@ void AgentsSourcesManager::operator()(int value)
//the loop is updated each second.
//it might be better to use a timer
bool finished=false;
long updateFrequency=5;// 1 second
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
for (auto&& ped: peds)
finished=true;
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;
cout<<"Agents generated: "<<peds.size()<<endl;
//src->Dump();
}
//src->Dump();
_lastUpdateTime = current_time;
}
//cout<<"Number of sources: "<<_sources.size()<<endl;
//wait one second
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
//wait some time
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}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);
//
//}
//compute the best position
exit(0);
}
void AgentsSourcesManager::AddSource(std::shared_ptr<AgentsSource> src)
{
_sources.push_back(src);
......@@ -67,3 +124,8 @@ const std::vector<std::shared_ptr<AgentsSource> >& AgentsSourcesManager::GetSour
{
return _sources;
}
void AgentsSourcesManager::SetBuilding(Building* building)
{
_building=building;
}
......@@ -13,6 +13,7 @@
//Forward declarations
class AgentsSource;
class Building;
class AgentsSourcesManager
{
......@@ -43,11 +44,24 @@ public:
*/
const std::vector<std::shared_ptr<AgentsSource> >& GetSources() const;
/**
* Set the building object
*/
void SetBuilding(Building* building);
//void operator()();
private:
/// contain the sources
std::vector<std::shared_ptr<AgentsSource>> _sources;
std::vector<std::shared_ptr<AgentsSource> > _sources;
///to control the trigger of the events
long int _lastUpdateTime = 0;
Building* _building=nullptr;
private:
void ComputeBestPosition(AgentsSource* src);
};
#endif /* AGENTSSOURCESMANAGER_H_ */
......@@ -43,25 +43,25 @@ using namespace std;
PedDistributor::PedDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed)
{
_start_dis = vector<StartDistribution* > ();
_start_dis_sub = vector<StartDistribution* > ();
_start_dis = vector<std::shared_ptr<StartDistribution> > ();
_start_dis_sub = vector<std::shared_ptr<StartDistribution> > ();
InitDistributor(fileName, agentPars, seed);
}
PedDistributor::~PedDistributor()
{
for (unsigned int i = 0; i < _start_dis.size(); i++)
{
delete _start_dis[i];
}
for (unsigned int i = 0; i < _start_dis_sub.size(); i++)
{
delete _start_dis_sub[i];
}
_start_dis_sub.clear();
_start_dis.clear();
// for (unsigned int i = 0; i < _start_dis.size(); i++)
// {
// delete _start_dis[i];
// }
// for (unsigned int i = 0; i < _start_dis_sub.size(); i++)
// {
// delete _start_dis_sub[i];
// }
// _start_dis_sub.clear();
// _start_dis.clear();
}
const vector<std::shared_ptr<AgentsSource> >& PedDistributor::GetAgentsSources() const
......@@ -123,7 +123,7 @@ bool PedDistributor::InitDistributor(const string& fileName, const std::map<int,
return false;
}
StartDistribution* dis=new StartDistribution(seed);
auto dis=std::shared_ptr<StartDistribution> (new StartDistribution(seed) );
dis->SetRoomID(room_id);
dis->SetSubroomID(subroom_id);
dis->SetGroupId(group_id);
......@@ -266,7 +266,7 @@ bool PedDistributor::Distribute(Building* building) const
// Distributing
Log->Write("INFO: \tDistributing %d Agents in Room/Subrom [%d/%d]! Maximum allowed: %d", N, roomID, subroomID, max_pos);
DistributeInSubRoom(sr, N, allpos, &pid,dist,building);
DistributeInSubRoom(sr, N, allpos, &pid,dist.get(),building);
Log->Write("\t...Done");
nPeds += N;
}
......@@ -341,7 +341,7 @@ bool PedDistributor::Distribute(Building* building) const
dist->SetSubroomID(sr->GetSubRoomID());
if (akt_anz[is] > 0)
{
DistributeInSubRoom(sr, akt_anz[is], allFreePosInRoom[is], &pid, dist,building);
DistributeInSubRoom(sr, akt_anz[is], allFreePosInRoom[is], &pid, dist.get(),building);
}
}
nPeds += N;
......@@ -355,6 +355,7 @@ bool PedDistributor::Distribute(Building* building) const
{
if(source->GetGroupId()==dist->GetGroupId())
{
source->SetStartDistribution(dist);
for(int i=0;i<source->GetMaxAgents();i++)
{
source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
......@@ -367,6 +368,7 @@ bool PedDistributor::Distribute(Building* building) const
{
if(source->GetGroupId()==dist->GetGroupId())
{
source->SetStartDistribution(dist);
for(int i=0;i<source->GetMaxAgents();i++)
{
source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
......
......@@ -46,8 +46,8 @@
class PedDistributor
{
private:
std::vector<StartDistribution*> _start_dis; // ID startraum, subroom und Anz
std::vector<StartDistribution*> _start_dis_sub; // ID startraum, subroom und Anz
std::vector<std::shared_ptr<StartDistribution> > _start_dis; // ID startraum, subroom und Anz
std::vector<std::shared_ptr<StartDistribution> > _start_dis_sub; // ID startraum, subroom und Anz
std::vector<std::shared_ptr<AgentsSource> > _start_dis_sources; // contain the sources
//std::string _projectFilename; // store the file for later user
//std::map<int, AgentsParameters*> _agentsParameters;
......
......@@ -39,6 +39,7 @@ using namespace std;
// initialize the static variables
double Pedestrian::_globalTime = 0.0;
int Pedestrian::_agentsCreated=0;
AgentColorMode Pedestrian::_colorMode=BY_VELOCITY;
Pedestrian::Pedestrian()
......@@ -74,7 +75,7 @@ Pedestrian::Pedestrian()
_lastPosition = Point(0,0);
_lastCellPosition = -1;
_recordingTime = 20; //seconds
// _knownDoors = map<int, NavLineState>();
//_knownDoors = map<int, NavLineState>();
_knownDoors.clear();
_height = 170;
_age = 30;
......@@ -86,6 +87,8 @@ Pedestrian::Pedestrian()
_V0DownStairs=0.0;
_distToBlockade=0.0;
_routingStrategy=ROUTING_GLOBAL_SHORTEST;
_agentsCreated++;//increase the number of object created
}
......@@ -825,6 +828,11 @@ void Pedestrian::SetColorMode(AgentColorMode mode)
_colorMode=mode;
}
int Pedestrian::GetAgentsCreated()
{
return _agentsCreated;
}
int Pedestrian::GetColor()
{
//default color is by velocity
......
......@@ -128,6 +128,8 @@ private:
/// a pointer to the complete building
Building * _building;
static int _agentsCreated;
public:
// constructors
Pedestrian();
......@@ -389,6 +391,13 @@ public:
static double GetGlobalTime();
static void SetGlobalTime(double time);
/**
* @return the total number of pedestrians objects created.
* This is useful for the linked-cells algorithm, since it uses the ID of the pedestrians
* and the maximal count must be known in advance.
*/
static int GetAgentsCreated();
/**
* Set the color mode for the pedestrians
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment