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