Commit 8930d207 authored by Ulrich Kemloh's avatar Ulrich Kemloh

fixed condition for terminating the simulation when there are sources. Fixed few memory leaks.

parent 73f20526
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
{ {
_outputHandler = NULL; _outputHandler = NULL;
}; };
virtual ~Trajectories(){}; virtual ~Trajectories(){delete _outputHandler;};
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed)=0; virtual void WriteHeader(long nPeds, double fps, Building* building, int seed)=0;
virtual void WriteGeometry(Building* building)=0; virtual void WriteGeometry(Building* building)=0;
virtual void WriteFrame(int frameNr, Building* building)=0; virtual void WriteFrame(int frameNr, Building* building)=0;
......
...@@ -225,7 +225,7 @@ bool Simulation::InitArgs(const ArgumentParser& args) ...@@ -225,7 +225,7 @@ bool Simulation::InitArgs(const ArgumentParser& args)
for (const auto& src: distributor->GetAgentsSources()) for (const auto& src: distributor->GetAgentsSources())
{ {
_agentSrcManager.AddSource(src); _agentSrcManager.AddSource(src);
src->Dump(); //src->Dump();
} }
//perform customs initialisation, like computing the phi for the gcfm //perform customs initialisation, like computing the phi for the gcfm
...@@ -299,11 +299,11 @@ int Simulation::RunSimulation() ...@@ -299,11 +299,11 @@ int Simulation::RunSimulation()
//time(&starttime); //time(&starttime);
// main program loop // main program loop
while (_nPeds > 0 && t < _tmax) while ( (_nPeds || !_agentSrcManager.IsCompleted() ) && t < _tmax)
{ {
t = 0 + (frameNr - 1) * _deltaT; t = 0 + (frameNr - 1) * _deltaT;
//process the queue for incomming pedestrians //process the queue for incoming pedestrians
ProcessAgentsQueue(); ProcessAgentsQueue();
// update the positions // update the positions
...@@ -337,7 +337,6 @@ int Simulation::RunSimulation() ...@@ -337,7 +337,6 @@ int Simulation::RunSimulation()
// clock_t goal = timeToWait*1000 + clock(); // clock_t goal = timeToWait*1000 + clock();
// while (goal > clock()); // while (goal > clock());
++frameNr; ++frameNr;
} }
// writing the footer // writing the footer
_iod->WriteFooter(); _iod->WriteFooter();
......
...@@ -49,7 +49,6 @@ Transition::~Transition() ...@@ -49,7 +49,6 @@ Transition::~Transition()
{ {
} }
// Setter-Funktionen
void Transition::Close() void Transition::Close()
{ {
...@@ -71,7 +70,7 @@ void Transition::SetRoom2(Room* r) ...@@ -71,7 +70,7 @@ void Transition::SetRoom2(Room* r)
_room2 = r; _room2 = r;
} }
// Getter-Funktionen
bool Transition::IsOpen() const bool Transition::IsOpen() const
{ {
......
...@@ -8,7 +8,8 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd"> ...@@ -8,7 +8,8 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<seed>12542</seed> <seed>12542</seed>
<!-- geometry file --> <!-- geometry file -->
<geometry>big_room_geo.xml</geometry> <geometry>big_room_geo.xml</geometry>
<events_file>big_room_events.xml</events_file> <events_files>big_room_events.xml</events_files>
<!-- <max_sim_time>15</max_sim_time> -->
<!-- trajectories file and format --> <!-- trajectories file and format -->
<trajectories format="xml-plain" fps="8"> <trajectories format="xml-plain" fps="8">
<file location="big_room_trrajectories.xml" /> <file location="big_room_trrajectories.xml" />
...@@ -70,16 +71,15 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd"> ...@@ -70,16 +71,15 @@ xsi:noNamespaceSchemaLocation="http://xsd.jupedsim.org/0.6/jps_ini_core.xsd">
<!--persons information and distribution --> <!--persons information and distribution -->
<agents operational_model_id="2"> <agents operational_model_id="2">
<agents_distribution> <agents_distribution>
<group group_id="0" room_id="0" subroom_id="0" number="5" router_id="1" agent_parameter_id="1" <group group_id="0" room_id="0" subroom_id="0" number="1" router_id="1" agent_parameter_id="1"
risk_tolerance_mean="0.8" risk_tolerance_sigma="0.01" x_min="14" x_max="16" y_min="14" y_max="16"/> risk_tolerance_mean="0.8" risk_tolerance_sigma="0.01" x_min="14" x_max="16" y_min="14" y_max="16"/>
<group group_id="1" room_id="0" subroom_id="0" number="50" router_id="1" agent_parameter_id="1" /> <group group_id="1" room_id="0" subroom_id="0" number="0" router_id="1" agent_parameter_id="1" />
</agents_distribution> </agents_distribution>
<agents_sources><!-- frequency in persons/minute --> <agents_sources><!-- frequency in persons/seconds -->
<source id="1" frequency="5" agents_max="100" group_id="0" caption="source 1"> <source id="1" frequency="5" agents_max="15" group_id="0" caption="source 1"/>
<sources id="1" frequency="5" agents_max="15" group_id="0" caption="source 1"/>
</source>
</agents_sources> </agents_sources>
</agents> </agents>
......
...@@ -116,4 +116,7 @@ void AgentsSource::Dump() const ...@@ -116,4 +116,7 @@ void AgentsSource::Dump() const
Log->Write("Group ID: %d", _groupID); Log->Write("Group ID: %d", _groupID);
Log->Write("Frequency: %d", _frequency); Log->Write("Frequency: %d", _frequency);
Log->Write("Agents Max: %d", _maxAgents); Log->Write("Agents Max: %d", _maxAgents);
Log->Write("Agents Pool: %d", _agents.size());
//getc(stdin);
} }
...@@ -31,18 +31,20 @@ AgentsSourcesManager::~AgentsSourcesManager() ...@@ -31,18 +31,20 @@ AgentsSourcesManager::~AgentsSourcesManager()
void AgentsSourcesManager::operator()(int value) void AgentsSourcesManager::operator()(int value)
{ {
//cout<<"starting thread"<<endl;
//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
_isCompleted=false;
bool finished = false; bool finished = false;
long updateFrequency = 5; // 1 second long updateFrequency = 5; // 1 second
do do
{ {
int current_time = Pedestrian::GetGlobalTime(); int current_time = Pedestrian::GetGlobalTime();
if ((current_time != _lastUpdateTime) && ((current_time % updateFrequency) == 0)) if ((current_time != _lastUpdateTime) && ((current_time % updateFrequency) == 0))
{ {
//cout<<"TIME:"<<current_time<<endl;
finished = true; finished = true;
for (const auto& src : _sources) for (const auto& src : _sources)
{ {
...@@ -51,25 +53,28 @@ void AgentsSourcesManager::operator()(int value) ...@@ -51,25 +53,28 @@ void AgentsSourcesManager::operator()(int value)
vector<Pedestrian*> peds; vector<Pedestrian*> peds;
src->GenerateByFrequency(peds); src->GenerateByFrequency(peds);
AgentsQueue::Add(peds); ComputeBestPositionRandom(src.get(), peds);
//ComputeBestPositionRandom(src.get(), peds);
// compute the optimal position for insertion // compute the optimal position for insertion
for (auto&& ped : peds) for (auto&& ped : peds)
{ {
//ComputeBestPosition(src.get(), ped); //ComputeBestPositionVoronoi(src.get(), ped);
ped->SetPos(Point(15,15),true); //ped->SetPos(Point(15,15),true);
//ped->Dump(ped->GetID()); //ped->Dump(ped->GetID());
} }
AgentsQueue::Add(peds);
finished = false; finished = false;
//cout<<"Agents generated: "<<peds.size()<<endl; cout<<"Agents generated: "<<peds.size()<<endl;
} }
//src->Dump();exit(0); //src->Dump();//exit(0);
} }
_lastUpdateTime = current_time; _lastUpdateTime = current_time;
//cout<<"size: "<<_sources.size()<<endl;
} }
//wait some time //wait some time
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} while (!finished); } while (!finished);
_isCompleted=true;
} }
void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent) void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent)
...@@ -104,13 +109,16 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestr ...@@ -104,13 +109,16 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestr
//special case with 1, 2 or only three pedestrians in the area //special case with 1, 2 or only three pedestrians in the area
if (peds.size() < 3) if (peds.size() < 3)
{ {
//random position in the area //TODO/random position in the area
return;
} }
// compute the cells and cut with the bounds // compute the cells and cut with the bounds
const int count = peds.size(); const int count = peds.size();
float xValues[count]; float* xValues= new float[count];
float yValues[count]; float* yValues= new float[count];
//float xValues[count];
//float yValues[count];
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
...@@ -171,6 +179,7 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestr ...@@ -171,6 +179,7 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, Pedestr
{ {
cout << "position not set:" << endl; cout << "position not set:" << endl;
cout << "size: " << map_dist_to_position.size() << endl; cout << "size: " << map_dist_to_position.size() << endl;
cout <<" for " <<peds.size()<<" pedestrians"<<endl;
exit(0); exit(0);
} }
//exit(0); //exit(0);
...@@ -191,7 +200,7 @@ void AgentsSourcesManager::ComputeBestPositionRandom(AgentsSource* src, std::vec ...@@ -191,7 +200,7 @@ void AgentsSourcesManager::ComputeBestPositionRandom(AgentsSource* src, std::vec
auto dist=src->GetStartDistribution(); auto dist=src->GetStartDistribution();
auto subroom=_building->GetRoom(dist->GetRoomId())->GetSubRoom(dist->GetSubroomID()); auto subroom=_building->GetRoom(dist->GetRoomId())->GetSubRoom(dist->GetSubroomID());
vector<Point> positions=PedDistributor::PossiblePositions(*subroom); vector<Point> positions=PedDistributor::PossiblePositions(*subroom);
double bounds[4]; double bounds[4]={0,0,0,0};
dist->Getbounds(bounds); dist->Getbounds(bounds);
//int roomID = dist->GetRoomId(); //int roomID = dist->GetRoomId();
//int subroomID = dist->GetSubroomID(); //int subroomID = dist->GetSubroomID();
...@@ -199,7 +208,7 @@ void AgentsSourcesManager::ComputeBestPositionRandom(AgentsSource* src, std::vec ...@@ -199,7 +208,7 @@ void AgentsSourcesManager::ComputeBestPositionRandom(AgentsSource* src, std::vec
for(const auto& ped: peds) for(const auto& ped: peds)
{ {
ped->Dump(ped->GetID()); continue; //ped->Dump(ped->GetID()); continue;
int index = -1; int index = -1;
//in the case a range was specified //in the case a range was specified
...@@ -230,24 +239,24 @@ ped->Dump(ped->GetID()); continue; ...@@ -230,24 +239,24 @@ ped->Dump(ped->GetID()); continue;
ped->SetPos(pos,true); //true for the initial position ped->SetPos(pos,true); //true for the initial position
positions.erase(positions.begin() + index); positions.erase(positions.begin() + index);
// const Point& start_pos = Point(_startX, _startY); // const Point& start_pos = Point(_startX, _startY);
// if ((std::isnan(start_pos._x) == 0) && (std::isnan(start_pos._y) == 0)) // if ((std::isnan(start_pos._x) == 0) && (std::isnan(start_pos._y) == 0))
// { // {
// if (_building->GetRoom(ped->GetRoomID())->GetSubRoom(ped->GetSubRoomID())->IsInSubRoom( // if (_building->GetRoom(ped->GetRoomID())->GetSubRoom(ped->GetSubRoomID())->IsInSubRoom(
// start_pos) == false) // start_pos) == false)
// { // {
// Log->Write( // Log->Write(
// "ERROR: \t cannot distribute pedestrian %d in Room %d at fixed position %s", // "ERROR: \t cannot distribute pedestrian %d in Room %d at fixed position %s",
// *pid, GetRoomId(), start_pos.toString().c_str()); // *pid, GetRoomId(), start_pos.toString().c_str());
// Log->Write( // Log->Write(
// "ERROR: \t Make sure that the position is inside the geometry and belongs to the specified room / subroom"); // "ERROR: \t Make sure that the position is inside the geometry and belongs to the specified room / subroom");
// exit(EXIT_FAILURE); // exit(EXIT_FAILURE);
// } // }
// //
// ped->SetPos(start_pos, true); //true for the initial position // ped->SetPos(start_pos, true); //true for the initial position
// Log->Write("INFO: \t fixed position for ped %d in Room %d %s", *pid, GetRoomId(), // Log->Write("INFO: \t fixed position for ped %d in Room %d %s", *pid, GetRoomId(),
// start_pos.toString().c_str()); // start_pos.toString().c_str());
// } // }
} }
} }
...@@ -266,3 +275,8 @@ void AgentsSourcesManager::SetBuilding(Building* building) ...@@ -266,3 +275,8 @@ void AgentsSourcesManager::SetBuilding(Building* building)
{ {
_building = building; _building = building;
} }
bool AgentsSourcesManager::IsCompleted() const
{
return _isCompleted;
}
...@@ -51,15 +51,21 @@ public: ...@@ -51,15 +51,21 @@ public:
void SetBuilding(Building* building); void SetBuilding(Building* building);
//void operator()(); //void operator()();
/**
* @return true if all agents have been generated
* and the class is ready to leave
*/
bool IsCompleted() const;
private: private:
/// contain the sources /// contain the sources
std::vector<std::shared_ptr<AgentsSource> > _sources; std::vector<std::shared_ptr<AgentsSource> > _sources;
///to control the trigger of the events ///to control the trigger of the events
long int _lastUpdateTime = 0; long int _lastUpdateTime = 0;
/// building object
Building* _building=nullptr; Building* _building=nullptr;
/// whether all agents have been dispatched
bool _isCompleted=true;
private: private:
void ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent); void ComputeBestPositionVoronoi(AgentsSource* src, Pedestrian* agent);
......
...@@ -359,6 +359,7 @@ bool PedDistributor::Distribute(Building* building) const ...@@ -359,6 +359,7 @@ bool PedDistributor::Distribute(Building* building) const
for(int i=0;i<source->GetMaxAgents();i++) for(int i=0;i<source->GetMaxAgents();i++)
{ {
source->Add(dist->GenerateAgent(building, &pid,emptyPositions)); source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
nPeds++;
} }
} }
//cout<<"ID sub: "<<dist->GetGroupId()<<endl; //cout<<"ID sub: "<<dist->GetGroupId()<<endl;
...@@ -372,6 +373,7 @@ bool PedDistributor::Distribute(Building* building) const ...@@ -372,6 +373,7 @@ bool PedDistributor::Distribute(Building* building) const
for(int i=0;i<source->GetMaxAgents();i++) for(int i=0;i<source->GetMaxAgents();i++)
{ {
source->Add(dist->GenerateAgent(building, &pid,emptyPositions)); source->Add(dist->GenerateAgent(building, &pid,emptyPositions));
nPeds++;
} }
} }
//cout<<"ID room: "<<dist->GetGroupId()<<endl; //cout<<"ID room: "<<dist->GetGroupId()<<endl;
......
...@@ -52,7 +52,7 @@ AccessPoint::AccessPoint(int id, double center[2],double radius) ...@@ -52,7 +52,7 @@ AccessPoint::AccessPoint(int id, double center[2],double radius)
AccessPoint::~AccessPoint() AccessPoint::~AccessPoint()
{ {
//if(_navLine) delete _navLine; if(_navLine) delete _navLine;
} }
int AccessPoint::GetID() int AccessPoint::GetID()
...@@ -218,7 +218,9 @@ bool AccessPoint::IsInRange(double xPed, double yPed, int roomID) ...@@ -218,7 +218,9 @@ bool AccessPoint::IsInRange(double xPed, double yPed, int roomID)
void AccessPoint::SetNavLine(NavLine* line) void AccessPoint::SetNavLine(NavLine* line)
{ {
_navLine=line; //todo: check this
//_navLine= line;
_navLine= new NavLine(*line);
} }
NavLine* AccessPoint::GetNavLine() const NavLine* AccessPoint::GetNavLine() const
......
...@@ -81,7 +81,7 @@ GlobalRouter::GlobalRouter(int id, RoutingStrategy s) : Router(id, s) ...@@ -81,7 +81,7 @@ GlobalRouter::GlobalRouter(int id, RoutingStrategy s) : Router(id, s)
GlobalRouter::~GlobalRouter() GlobalRouter::~GlobalRouter()
{ {
if (_distMatrix && _pathsMatrix) { if (_distMatrix && _pathsMatrix) {
const int exitsCnt = _building->GetNumberOfGoals(); const int exitsCnt = _building->GetNumberOfGoals() + _building->GetAllGoals().size();
for (int p = 0; p < exitsCnt; ++p) { for (int p = 0; p < exitsCnt; ++p) {
delete[] _distMatrix[p]; delete[] _distMatrix[p];
delete[] _pathsMatrix[p]; delete[] _pathsMatrix[p];
...@@ -321,7 +321,11 @@ bool GlobalRouter::Init(Building* building) ...@@ -321,7 +321,11 @@ bool GlobalRouter::Init(Building* building)
AccessPoint* to_AP = new AccessPoint(line.GetUniqueID(), center); AccessPoint* to_AP = new AccessPoint(line.GetUniqueID(), center);
to_AP->SetFinalGoalOutside(true); to_AP->SetFinalGoalOutside(true);
to_AP->SetNavLine(new NavLine(line)); //NavLine* tmpline=new NavLine(line);
NavLine tmpline(line);
to_AP->SetNavLine(&tmpline);
//delete tmpline;
char friendlyName[CLENGTH]; char friendlyName[CLENGTH];
sprintf(friendlyName, "finalGoal_%d_located_outside", goal->GetId()); sprintf(friendlyName, "finalGoal_%d_located_outside", goal->GetId());
to_AP->SetFriendlyName(friendlyName); to_AP->SetFriendlyName(friendlyName);
......
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