Commit 7eaa59c7 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Agents that could not be placed using vorovoi are now requeued

parent f9940660
...@@ -71,6 +71,11 @@ void AgentsSource::RemoveAgentsFromPool(std::vector<Pedestrian*>& ped, int count ...@@ -71,6 +71,11 @@ void AgentsSource::RemoveAgentsFromPool(std::vector<Pedestrian*>& ped, int count
} }
} }
void AgentsSource::AddAgentsToPool(std::vector<Pedestrian*>& peds)
{
_agents.insert(_agents.begin(),peds.begin(),peds.end());
}
int AgentsSource::GetPoolSize() const int AgentsSource::GetPoolSize() const
{ {
return _agents.size(); return _agents.size();
......
...@@ -85,6 +85,13 @@ public: ...@@ -85,6 +85,13 @@ public:
*/ */
void RemoveAgentsFromPool(std::vector<Pedestrian*>& peds, int count); void RemoveAgentsFromPool(std::vector<Pedestrian*>& peds, int count);
/**
* Add the agents to the pool. This might be important in the case the removed agents could not
* be placed correctly. They can be requeued using this function.
* @param peds
*/
void AddAgentsToPool(std::vector<Pedestrian*>& peds);
/** /**
* @return the number of agents remaining * @return the number of agents remaining
*/ */
......
...@@ -91,7 +91,7 @@ void AgentsSourcesManager::Run() ...@@ -91,7 +91,7 @@ void AgentsSourcesManager::Run()
_lastUpdateTime = current_time; _lastUpdateTime = current_time;
} }
//wait some time //wait some time
// std::this_thread::sleep_for(std::chrono::milliseconds(1)); // std::this_thread::sleep_for(std::chrono::milliseconds(1));
} while (!finished); } while (!finished);
Log->Write("INFO:\tTerminating agent manager thread"); Log->Write("INFO:\tTerminating agent manager thread");
_isCompleted = true; _isCompleted = true;
...@@ -104,14 +104,14 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -104,14 +104,14 @@ bool AgentsSourcesManager::ProcessAllSources() const
{ {
if (src->GetPoolSize()) if (src->GetPoolSize())
{ {
vector<Pedestrian*> peds; vector<Pedestrian*> peds;
src->RemoveAgentsFromPool(peds,src->GetFrequency()); src->RemoveAgentsFromPool(peds,src->GetFrequency());
Log->Write("INFO:\tSource %d generating %d agents (%d remaining)",src->GetId(),peds.size(),src->GetPoolSize()); Log->Write("INFO:\tSource %d generating %d agents (%d remaining)",src->GetId(),peds.size(),src->GetPoolSize());
//ComputeBestPositionRandom(src.get(), peds); //ComputeBestPositionRandom(src.get(), peds);
//todo: compute the optimal position for insertion using voronoi //todo: compute the optimal position for insertion using voronoi
if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building) ) if( !ComputeBestPositionVoronoiBoost(src.get(), peds, _building) )
Log->Write("INFO:\t there was no place for some pedestrians"); Log->Write("INFO:\t there was no place for some pedestrians");
//ComputeBestPositionTotalRandom(src.get(), peds ); //ComputeBestPositionTotalRandom(src.get(), peds );
//ComputeBestPositionDummy( src.get(), peds ); //ComputeBestPositionDummy( src.get(), peds );
/*for (auto&& ped : peds) /*for (auto&& ped : peds)
...@@ -131,49 +131,49 @@ bool AgentsSourcesManager::ProcessAllSources() const ...@@ -131,49 +131,49 @@ bool AgentsSourcesManager::ProcessAllSources() const
void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src, void AgentsSourcesManager::ComputeBestPositionDummy(AgentsSource* src,
vector<Pedestrian*>& peds)const vector<Pedestrian*>& peds)const
{ {
peds[0]->SetPos( Point(10,5.5) ); peds[0]->SetPos( Point(10,5.5) );
peds[1]->SetPos( Point(10,4.9) ); peds[1]->SetPos( Point(10,4.9) );
peds[2]->SetPos( Point(10,4.3) ); peds[2]->SetPos( Point(10,4.3) );
peds[3]->SetPos( Point(10,3.7) ); peds[3]->SetPos( Point(10,3.7) );
/*peds[0]->SetPos( Point(10,5.4) ); /*peds[0]->SetPos( Point(10,5.4) );
peds[1]->SetPos( Point(10,4.6) ); peds[1]->SetPos( Point(10,4.6) );
peds[2]->SetPos( Point(10,3.8) );*/ peds[2]->SetPos( Point(10,3.8) );*/
for(auto&& ped : peds) for(auto&& ped : peds)
{ {
Point v = (ped->GetExitLine()->ShortestPoint(ped->GetPos())- ped->GetPos()).Normalized(); Point v = (ped->GetExitLine()->ShortestPoint(ped->GetPos())- ped->GetPos()).Normalized();
double speed=ped->GetV0Norm(); double speed=ped->GetV0Norm();
v=v*speed; v=v*speed;
ped->SetV(v); ped->SetV(v);
} }
} }
void AgentsSourcesManager::ComputeBestPositionCompleteRandom(AgentsSource* src, void AgentsSourcesManager::ComputeBestPositionCompleteRandom(AgentsSource* src,
vector<Pedestrian*>& peds)const vector<Pedestrian*>& peds)const
{ {
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);
srand (time(NULL)); srand (time(NULL));
for (auto& ped : peds) for (auto& ped : peds)
{ {
if( positions.size() ) if( positions.size() )
{ {
int index = rand()%positions.size(); int index = rand()%positions.size();
Point new_pos = positions[index]; Point new_pos = positions[index];
positions.erase(positions.begin() + index); positions.erase(positions.begin() + index);
ped->SetPos(new_pos, true); ped->SetPos(new_pos, true);
AdjustVelocityByNeighbour(ped); AdjustVelocityByNeighbour(ped);
} }
else else
{ {
Log->Write("\t No place for a pedestrian"); Log->Write("\t No place for a pedestrian");
break; break;
} }
} }
} }
...@@ -294,7 +294,7 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src, ...@@ -294,7 +294,7 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src,
//compute the best position //compute the best position
//exit(0); //exit(0);
} }
*/ */
......
This diff is collapsed.
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