Commit bc609699 authored by Ulrich Kemloh's avatar Ulrich Kemloh

fixed: memory leak in agentsparameter

parent 5ec0d196
......@@ -201,7 +201,7 @@ bool EventManager::UpdateAgentKnowledge(Building* _b)
{
for (auto&& door: _b->GetAllTransitions())
{
if(door.second->DistTo(ped->GetPos())<0.5)//distance to door to register its state
if(door.second->DistTo(ped->GetPos())<1)//distance to door to register its state
{
//actualize the information about the newly closed door
if(door.second->IsOpen()==false)
......@@ -274,7 +274,7 @@ bool EventManager::UpdateAgentKnowledge(Building* _b)
//Clear the memory and attempt to reroute
//this can happen if all doors are known to be closed
ped->ClearKnowledge();
Log->Write("ERROR: \t clearing ped knowledge");
//Log->Write("ERROR: \t clearing ped knowledge");
if(UpdateRoute(ped)==false)
{
Log->Write("ERROR: \t cannot reroute the pedestrian. unknown problem");
......@@ -310,8 +310,8 @@ bool EventManager::UpdateRoute(Pedestrian* ped)
}
else
{
Log->Write("WARNING: \t unknown configuration <%s>", key.c_str());
Log->Write("WARNING: \t [%d] router available", _eventEngineStorage.size());
//Log->Write("WARNING: \t unknown configuration <%s>", key.c_str());
//Log->Write("WARNING: \t [%d] router available", _eventEngineStorage.size());
//Log->Write(" : \t trying to create");
//CreateRoutingEngine(_building);
status= false;
......@@ -321,8 +321,8 @@ bool EventManager::UpdateRoute(Pedestrian* ped)
void EventManager::MergeKnowledge(Pedestrian* p1, Pedestrian* p2)
{
auto const & old_info1=p1->GetKnownledge();
auto const & old_info2=p2->GetKnownledge();
auto const & old_info1 = p1->GetKnownledge();
auto const & old_info2 = p2->GetKnownledge();
map<int, Knowledge> merge_info;
//collect the most recent knowledge
......@@ -331,19 +331,19 @@ void EventManager::MergeKnowledge(Pedestrian* p1, Pedestrian* p2)
merge_info[info1.first] = info1.second;
}
for (auto&& info2:old_info2)
for (auto&& info2 : old_info2)
{
//update infos according to a newest time
if(merge_info.count(info2.first)>0)
if (merge_info.count(info2.first) > 0)
{
if(info2.second.GetTime()>merge_info[info2.first].GetTime())
if (info2.second.GetTime() > merge_info[info2.first].GetTime())
{
merge_info[info2.first]=info2.second;
merge_info[info2.first] = info2.second;
}
}
else //the info was not present, just add
{
merge_info[info2.first]=info2.second;
merge_info[info2.first] = info2.second;
}
}
......@@ -352,8 +352,8 @@ void EventManager::MergeKnowledge(Pedestrian* p1, Pedestrian* p2)
p2->ClearKnowledge();
for (auto&& info : merge_info)
{
p1->AddKnownClosedDoor(info.first,info.second.GetTime());
p2->AddKnownClosedDoor(info.first,info.second.GetTime());
p1->AddKnownClosedDoor(info.first, info.second.GetTime());
p2->AddKnownClosedDoor(info.first, info.second.GetTime());
}
}
......@@ -509,29 +509,29 @@ void EventManager::ChangeRouting(int id, const std::string& state)
//Pedestrians sollen, damit es realitaetsnaeher wird, je nachdem wo sie stehen erst spaeter(abh. von der
//Entfernung zur Tuer) merken, dass sich Tueren aendern. Oder sie bekommen die Info von anderen Pedestrians
Transition *t = _building->GetTransition(id);
//Abstand der aktuellen Position des Pedestrians zur entsprechenden Tuer: Tuer als Linie sehen und mit
//DistTo(ped.GetPos()) den Abstand messen. Reroutezeit dann aus Entfernung und Geschwindigkeit berechnen.
for(auto&& ped:_building->GetAllPedestrians())
{
//if(_allPedestrians[p]->GetExitIndex()==t->GetUniqueID()){
ped->SetNewEventFlag(false);
double dist = t->DistTo(ped->GetPos());
const Point& v = ped->GetV();
double norm = v.Norm();
if (norm == 0.0) {
norm = 0.01;
}
double time = dist / norm;
if (time < 1.0) {
ped->ClearMentalMap();
ped->ResetRerouting();
ped->SetNewEventFlag(true);
} else {
ped->RerouteIn(time);
}
}
//Transition *t = _building->GetTransition(id);
// for(auto&& ped:_building->GetAllPedestrians())
// {
// //if(_allPedestrians[p]->GetExitIndex()==t->GetUniqueID()){
// ped->SetNewEventFlag(false);
// double dist = t->DistTo(ped->GetPos());
// const Point& v = ped->GetV();
// double norm = v.Norm();
// if (norm == 0.0) {
// norm = 0.01;
// }
// double time = dist / norm;
// if (time < 1.0) {
// ped->ClearMentalMap();
// ped->ResetRerouting();
// ped->SetNewEventFlag(true);
// } else {
// ped->RerouteIn(time);
// }
// }
//Create and save a graph corresponding to the actual state of the building.
if(CreateRoutingEngine(_building)==false)
......@@ -573,6 +573,7 @@ void EventManager::GetEvent(char* c)
bool EventManager::CreateRoutingEngine(Building* _b, int first_engine)
{
std::vector<int> closed_doors;
closed_doors.clear();
for(auto&& t:_b->GetAllTransitions())
{
......
......@@ -121,11 +121,12 @@ ArgumentParser::ArgumentParser()
pMaxOpenMPThreads = omp_get_thread_num();
_profilingFlag = false;
_hpcFlag = 0;
_agentsParameters= std::map<int, AgentsParameters*>();
_agentsParameters= std::map<int, std::shared_ptr<AgentsParameters> >();
p_routingengine = std::shared_ptr<RoutingEngine>(new RoutingEngine());
_showStatistics=false;
}
bool ArgumentParser::ParseArgs(int argc, char **argv)
{
//special case of the default configuration ini.xml
......@@ -172,16 +173,11 @@ bool ArgumentParser::ParseArgs(int argc, char **argv)
return false;
}
const std::map<int, AgentsParameters*>& ArgumentParser::GetAgentsParameters() const
const std::map<int, std::shared_ptr<AgentsParameters> >& ArgumentParser::GetAgentsParameters() const
{
return _agentsParameters;
}
void ArgumentParser::SetAgentsParameters(const std::map<int, AgentsParameters*>& agentsParameters)
{
_agentsParameters = agentsParameters;
}
bool ArgumentParser::ParseIniFile(string inifile)
{
Log->Write("INFO: \tLoading and parsing the project file <%s>",
......@@ -648,7 +644,8 @@ void ArgumentParser::ParseAgentParameters(TiXmlElement* operativModel)
//get the group ID
int para_id= xmltoi(xAgentPara->Attribute("agent_parameter_id"),-1);
Log->Write("INFO: \tParsing the group parameter id [%d]",para_id);
AgentsParameters* agentParameters = new AgentsParameters(para_id,pSeed);
auto agentParameters=std::shared_ptr<AgentsParameters>(new AgentsParameters(para_id,pSeed));
_agentsParameters[para_id]=agentParameters;
//desired speed
......@@ -1209,3 +1206,5 @@ bool ArgumentParser::ParseStepSize(TiXmlNode &stepNode)
}
return false;
}
......@@ -103,7 +103,7 @@ private:
bool _profilingFlag;
bool _showStatistics;
int _hpcFlag; //Flag fuer die HPC-Archtitektur (0=CPU, 1=GPU, 2=XeonPhi)
std::map<int, AgentsParameters*> _agentsParameters;
std::map<int, std::shared_ptr<AgentsParameters> > _agentsParameters;
/*
* return objects for other classes as shared pointers
......@@ -148,8 +148,8 @@ private:
bool ParseStepSize(TiXmlNode &stepNode);
public:
// Konstruktor
ArgumentParser(); // gibt die Programmoptionen aus
// constructor
ArgumentParser();
// Getter-Funktionen
bool IsOnline() const;
......@@ -220,9 +220,7 @@ public:
vector<pair<int, RoutingStrategy> > GetRoutingStrategy() const;
const FileFormat& GetFileFormat() const;
const std::map<int, AgentsParameters*>& GetAgentsParameters() const;
void SetAgentsParameters(
const std::map<int, AgentsParameters*>& agentsParameters);
const std::map<int, std::shared_ptr<AgentsParameters> >& GetAgentsParameters() const;
/**
* Parse the commands passed to the command line
......
......@@ -86,8 +86,8 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<model operational_model_id="1" description="gcfm">
<model_parameters>
<solver>euler</solver>
<stepsize>0.001</stepsize>
<exit_crossing_strategy>4</exit_crossing_strategy>
<stepsize>0.01</stepsize>
<exit_crossing_strategy>3</exit_crossing_strategy>
<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" />
......
......@@ -196,7 +196,7 @@ void StartDistributionSubroom::SetSubroomID(int i)
PedDistributor
************************************************************/
PedDistributor::PedDistributor(const string& fileName, const std::map<int, AgentsParameters*>& agentPars, unsigned int seed)
PedDistributor::PedDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed)
{
_start_dis = vector<StartDistributionRoom* > ();
_start_dis_sub = vector<StartDistributionSubroom* > ();
......@@ -218,7 +218,7 @@ PedDistributor::~PedDistributor()
//empty the parameters maps
}
bool PedDistributor::InitDistributor(const string& fileName, const std::map<int, AgentsParameters*>& agentPars, unsigned int seed)
bool PedDistributor::InitDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed)
{
Log->Write("INFO: \tLoading and parsing the persons attributes");
......@@ -299,7 +299,7 @@ bool PedDistributor::InitDistributor(const string& fileName, const std::map<int,
Log->Write("ERROR:\t Default values are not implemented yet");
return false;
}
dis->SetGroupParameters(agentPars.at(agent_para_id));
dis->SetGroupParameters(agentPars.at(agent_para_id).get());
if(e->Attribute("start_x") && e->Attribute("start_y")) {
double startX = xmltof(e->Attribute("start_x"),NAN);
......
......@@ -136,7 +136,7 @@ private:
std::vector<StartDistributionSubroom*> _start_dis_sub; // ID startraum, subroom und Anz
//std::string _projectFilename; // store the file for later user
//std::map<int, AgentsParameters*> _agentsParameters;
bool InitDistributor(const string&, const std::map<int, AgentsParameters*>&, unsigned int);
bool InitDistributor(const string&, const std::map<int, std::shared_ptr<AgentsParameters> >& , unsigned int);
static std::vector<Point> PositionsOnFixX(double max_x, double min_x, double max_y, double min_y,
const SubRoom& r, double bufx, double bufy, double dy);
static std::vector<Point> PositionsOnFixY(double max_x, double min_x, double max_y, double min_y,
......@@ -146,7 +146,7 @@ public:
/**
* constructor
*/
PedDistributor(const string& fileName, const std::map<int, AgentsParameters*>& agentPars, unsigned int seed);
PedDistributor(const string& fileName, const std::map<int, std::shared_ptr<AgentsParameters> >& agentPars, unsigned int seed);
/**
* desctructor
......
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