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
}
}
void AgentsSource::AddAgentsToPool(std::vector<Pedestrian*>& peds)
{
_agents.insert(_agents.begin(),peds.begin(),peds.end());
}
int AgentsSource::GetPoolSize() const
{
return _agents.size();
......
......@@ -85,6 +85,13 @@ public:
*/
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
*/
......
......@@ -294,7 +294,7 @@ void AgentsSourcesManager::ComputeBestPositionVoronoi(AgentsSource* src,
//compute the best position
//exit(0);
}
*/
*/
......
......@@ -39,20 +39,20 @@ using boost::polygon::high;
//wrapping the boost objects
namespace boost {
namespace polygon {
template <>
struct geometry_concept<Point> {
template <>
struct geometry_concept<Point> {
typedef point_concept type;
};
};
template <>
struct point_traits<Point> {
template <>
struct point_traits<Point> {
typedef int coordinate_type;
static inline coordinate_type get(
const Point& point, orientation_2d orient) {
return (orient == HORIZONTAL) ? point._x : point._y;
}
};
};
} // polygon
} // boost
......@@ -61,19 +61,24 @@ using namespace std;
//functions
//TODO: refactor the function
bool IsEnoughInSubroom( SubRoom* subroom, Point& pt )
{
std::vector<Wall> walls = subroom->GetAllWalls();
std::vector<Transition*> transitions= subroom->GetAllTransitions();
std::vector<Crossing*> crossings = subroom->GetAllCrossings();
double radius = 0.4; //radius of a person
//checking distance to walls
for(unsigned int i=0; i<walls.size(); i++)
if ( walls[i].DistTo(pt) < radius )
//std::vector<Wall> walls = subroom->GetAllWalls();
// for(unsigned int i=0; i<walls.size(); i++)
// if ( walls[i].DistTo(pt) < radius )
// return false;
//TODO: code refactoring:
for (const auto& wall: subroom->GetAllWalls())
if(wall.DistTo(pt)<radius)
return false;
//checking distance to transitions
for(unsigned int i=0; i<transitions.size(); i++)
if ( transitions[i]->DistTo(pt) < radius )
......@@ -86,8 +91,8 @@ bool IsEnoughInSubroom( SubRoom* subroom, Point& pt )
return true;
}
bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
std::vector<Pedestrian*>& peds, Building* building)
bool ComputeBestPositionVoronoiBoost(AgentsSource* src, std::vector<Pedestrian*>& peds,
Building* building)
{
bool return_value = true;
auto dist = src->GetStartDistribution();
......@@ -97,10 +102,11 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
double radius = 0.4; //DO: change! radius of a person
std::vector<Pedestrian*> existing_peds;
std::vector<Pedestrian*> peds_without_place;
building->GetPedestrians(roomID, subroomID, existing_peds);
SubRoom* subroom = (building->GetRoom( roomID ))->GetSubRoom(subroomID);
vector<Point> room_vertices = subroom->GetPolygon();
SubRoom* subroom = building->GetRoom( roomID )->GetSubRoom(subroomID);
const vector<Point>& room_vertices = subroom->GetPolygon();
double factor = 100; //factor for conversion to integer for the boost voronoi
......@@ -108,7 +114,7 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
Point temp(0,0);
for (unsigned int i=0; i<room_vertices.size(); i++ )
{
Point center_pos = subroom->GetCentroid();
const Point& center_pos = subroom->GetCentroid();
temp.SetX( center_pos.GetX()-room_vertices[i].GetX( ) );
temp.SetY( center_pos.GetY()-room_vertices[i].GetY( ) );
temp = temp/sqrt(temp.NormSquare());
......@@ -119,14 +125,15 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
fake_peds.push_back( temp );
}
for(auto&& ped : peds)
std::vector<Pedestrian*>::iterator iter_ped;
for (iter_ped = peds.begin(); iter_ped != peds.end(); )
{
Pedestrian* ped = (*iter_ped);
if(existing_peds.size() == 0 )
{
Point center_pos = subroom->GetCentroid();
srand (time(NULL));
const Point& center_pos = subroom->GetCentroid();
// we have already initiate a random number generator using the seed from the ini file
//srand (time(NULL));
double x_coor = 3 * ( (double)rand() / (double)RAND_MAX ) - 1.5;
double y_coor = 3 * ( (double)rand() / (double)RAND_MAX ) - 1.5;
Point random_pos(x_coor, y_coor);
......@@ -207,11 +214,18 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
Point pos( chosen_it->x()/factor, chosen_it->y()/factor ); //check!
ped->SetPos(pos , true);
VoronoiAdjustVelocityNeighbour( vd, chosen_it, ped, velocities_vector );
// proceed to the next pedestrian
++iter_ped;
}
else
{
//reject the pedestrian:
// remove from the initial vector since it should only contain the pedestrians that could
// find a place. Put in a different queue, they will be put back in the source.
return_value = false;
//reject the pedestrian
peds_without_place.push_back(*iter_ped);
iter_ped=peds.erase(iter_ped);
}
/*else //try with the maximum distance, don't need this if already using the VoronoiBestVertexMax function
......@@ -234,6 +248,11 @@ bool ComputeBestPositionVoronoiBoost(AgentsSource* src,
existing_peds.push_back(ped);
}//for loop
//maybe not all pedestrians could find a place, requeue them in the source
if(peds_without_place.size()>0)
src->AddAgentsToPool(peds_without_place);
return return_value;
}
......@@ -297,7 +316,7 @@ void VoronoiBestVertexRandMax (const std::vector<Point>& discrete_positions, con
{
std::vector< voronoi_diagram<double>::const_vertex_iterator > possible_vertices;
vector<double> partial_sums;
unsigned int size;
unsigned int size=0;
for (voronoi_diagram<double>::const_vertex_iterator it = vd.vertices().begin(); it != vd.vertices().end(); ++it)
{
......
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