Mentions légales du service

Skip to content
Snippets Groups Projects
Commit ea7cf8b1 authored by NICAS MIQUEL Alicia's avatar NICAS MIQUEL Alicia
Browse files

#28 Remove LQ from doStep + remove checking for self as nearest neighbor

parent 17ab150e
No related branches found
No related tags found
3 merge requests!48Resolve "TinyXml should replace boost parser",!46Resolve "TinyXml should replace boost parser",!42Resolve "Comment lq2D stuff and add temporary solution"
......@@ -49,6 +49,8 @@ class World
std::vector<lqClientProxy2D*> lqProxies;
static void perNeighborCallBackFunction (void* clientObject, float /*distanceSquared*/, void* clientQueryState);
Agent * findNearestNeighborWithinRadius(size_t agent_id, const Vector2D & agentPosition, float search_radius);
public :
World();
......
......@@ -56,8 +56,8 @@ std::vector<Agent *> World::getNeighboursOfAgent(int agent_id, float search_radi
for (size_t i = 0; i < agents_.size(); i++)
{
Vector2D neighborPosition(agents_[i]->getPosition());
Vector2D distance = neighborPosition-agentPosition;
if ((neighborPosition - agentPosition).magnitude() < search_radius)
if (i != agent_id &&
(neighborPosition - agentPosition).magnitude() < search_radius)
{
neighbors.push_back(agents_[i]);
}
......@@ -71,6 +71,31 @@ void World::perNeighborCallBackFunction(void *clientObject, float, void *clientQ
results.push_back ((Agent*)clientObject);
}
//Find the nearest neighbor of an agent within a radius
//The behavior is probably incorrect and needs to be fixed
Agent * World::findNearestNeighborWithinRadius(size_t agent_id, const Vector2D& agentPosition, float search_radius)
{
Agent* nearestNeighbour;
double nearestNeighbourDistance = search_radius;
for (size_t i = 0; i < agents_.size(); i++)
{
Vector2D neighborPosition(agents_[i]->getPosition());
double distance = (neighborPosition - agentPosition).magnitude();
if (agent_id != i &&
distance < search_radius &&
distance < nearestNeighbourDistance)
{
nearestNeighbour = agents_[i];
nearestNeighbourDistance = distance;
}
}
return nearestNeighbour;
}
void World::doStep(double dt)
{
time_ += dt;
......@@ -78,8 +103,11 @@ void World::doStep(double dt)
{
agents_[i]->runPolicy(this);
lqUpdateForNewLocation(lqDB, lqProxies[i], agents_[i]->getPosition().x() + agents_[i]->getNextVelocity().x() * dt,
//Updates the LQ database, not needed if no LQ
/*lqUpdateForNewLocation(lqDB, lqProxies[i], agents_[i]->getPosition().x() + agents_[i]->getNextVelocity().x() * dt,
agents_[i]->getPosition().y() + agents_[i]->getNextVelocity().y() * dt);
*/
}
Vector2D agentPosition;
......@@ -87,14 +115,17 @@ void World::doStep(double dt)
for (size_t i = 0; i < agents_.size(); ++i)
{
// Check for collision with nearest neighbor
agentPosition = agents_[i]->getPosition();
/*agentPosition = agents_[i]->getPosition();
agentVelocity = agents_[i]->getNextVelocity();
if (lqFindNearestNeighborWithinRadius(lqDB,
agentPosition.x() + agentVelocity.x() * dt,
agentPosition.y() + agentVelocity.y() * dt,
agentVelocity.x() * dt, agentVelocity.y() * dt,
agents_[i]->getRadius(),
(void*)agents_[i]) != NULL)
(void*)agents_[i]) != NULL)*/
//The behavior of finding the nearest neighbor is probably incorrect
Vector2D agentNextPosition = agents_[i]->getPosition() + agents_[i]->getNextVelocity() * dt;
if(findNearestNeighborWithinRadius(i, agentNextPosition, agents_[i]->getRadius()) != NULL)
{
// TODO : decide of a strategy in case of collision
// For now, we do nothing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment