Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit f43596f4 authored by LOPEZ GANDIA Axel's avatar LOPEZ GANDIA Axel
Browse files

Resolve "Split Social Force"

parent 917da361
......@@ -52,3 +52,13 @@ target_link_libraries(my_app)
#target_link_libraries(test_ttcaDca)
#message(${Boost_LIBRARIES})
#message(${Boost_LIBRARY_DIRS})
foreach(_source IN ITEMS ${source_files})
get_filename_component(_source_path "${_source}" PATH)
file(RELATIVE_PATH _source_path_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source_path}")
string(REPLACE "include/" "" _source_path_rel ${_source_path_rel})
string(REPLACE "src/" "" _source_path_rel ${_source_path_rel})
string(REPLACE "/" "\\" _group_path "${_source_path_rel}")
source_group("${_group_path}" FILES "${_source}")
endforeach()
source_group("3rd-party" FILES ${tinyxml_src})
\ No newline at end of file
......@@ -27,6 +27,7 @@
#define LIB_FOE_AVOIDANCE_H
#include <core/costFunction.h>
#include <string>
/*
* Deviates the trajectory of the agent to prevent collisions.
......@@ -38,6 +39,7 @@ class FOEAvoidance : public CostFunction
public:
const static std::string Name;
FOEAvoidance();
/**
......
......@@ -27,6 +27,7 @@
#define LIB_GENERIC_COST_H
#include <core/costFunction.h>
#include <string>
/*
* Empty Cost Function, use as template.
......@@ -36,7 +37,7 @@ class GenericCost : public CostFunction
private:
public:
const static std::string Name;
GenericCost();
/**
......
......@@ -23,22 +23,22 @@
** Contact: crowd_group@inria.fr
*/
#ifndef LIB_GOAL_REACHING_H
#define LIB_GOAL_REACHING_H
#ifndef LIB_SOCIAL_FORCES_AVOIDANCE_H
#define LIB_SOCIAL_FORCES_AVOIDANCE_H
#include <core/costFunction.h>
/*
* Performs goal reaching at the desired speed of the agent.
* CF = ADS*(GP - AP) · AV
* CF: Cost function, ADS: Agent Desired Speed, AP: Agent Position, GP: Goal Position, AV: Agent current Velocity.
* Implements social forces algorithm.
*/
class GoalReaching : public CostFunction
class SocialForcesAvoidance : public CostFunction
{
private:
public:
GoalReaching();
const static std::string Name;
SocialForcesAvoidance();
/**
* Computes the value and gradient of the cost function.
......@@ -46,7 +46,7 @@ class GoalReaching : public CostFunction
*/
virtual CostFunctionValues GetCostFunctionGradient(Agent* agent, World * world);
virtual ~GoalReaching();
virtual ~SocialForcesAvoidance();
};
#endif //LIB_GOAL_REACHING_H
#endif //LIB_SOCIAL_FORCES_AVOIDANCE_H
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
**
**
** Authors: Axel Lopez Gandia, Javad Amirian, Florian Berton,
** Julien Legros, Lucas Pelerin, Beatriz Cabrero Daniel, Fabien Grzeskowiak
**
** Contact: crowd_group@inria.fr
*/
#ifndef LIB_SOCIAL_FORCES_GOAL_H
#define LIB_SOCIAL_FORCES_GOAL_H
#include <core/costFunction.h>
/*
* Implements social forces algorithm.
*/
class SocialForcesGoalReaching : public CostFunction
{
private:
public:
const static std::string Name;
SocialForcesGoalReaching();
/**
* Computes the value and gradient of the cost function.
* Return the values to the policy to update the agent.
*/
virtual CostFunctionValues GetCostFunctionGradient(Agent* agent, World * world);
virtual ~SocialForcesGoalReaching();
};
#endif //LIB_SOCIAL_FORCES_GOAL_H
......@@ -38,6 +38,8 @@ class GoalReaching : public CostFunction
private:
public:
const static std::string Name;
GoalReaching();
/**
......
......@@ -36,6 +36,9 @@ class SocialForces : public CostFunction
private:
public:
const static std::string Name;
float AtractorForce = 1;
float RepulsionForce = 3;
......
......@@ -34,7 +34,10 @@
#include <memory>
using namespace std;
#define SMALL_NUMBER 0.01
const std::string FOEAvoidance::Name = "FOEAvoidance";
constexpr auto SMALL_NUMBER = 0.01;
FOEAvoidance::FOEAvoidance() {
name_ = "FOEAvoidance";
......
......@@ -31,6 +31,8 @@
#include <iostream>
using namespace std;
const std::string GenericCost::Name = "Generic";
GenericCost::GenericCost() {
name_ = "Generic";
}
......
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
**
**
** Authors: Axel Lopez Gandia, Javad Amirian, Florian Berton,
** Julien Legros, Lucas Pelerin, Beatriz Cabrero Daniel, Fabien Grzeskowiak
**
** Contact: crowd_group@inria.fr
*/
#include <CostFunctions/SocialForcesAvoidance.h>
#include <core/agent.h>
#include <core/world.h>
#include <algorithm>
#include <iostream>
using namespace std;
const std::string SocialForcesAvoidance::Name = "SocialForcesAvoidance";
SocialForcesAvoidance::SocialForcesAvoidance() {
name_ = "SocialForces";
}
SocialForcesAvoidance::~SocialForcesAvoidance() {
}
CostFunctionValues SocialForcesAvoidance::GetCostFunctionGradient(Agent* agent, World * world) {
CostFunctionValues Result;
Vector2D AgentPos = agent->getPosition();
vector<Agent*> Neighbors = world->getNeighboursOfAgent(agent->getID(), 100);
Vector2D Repulsion(0, 0); float TotalCost = 0;
float dt = 1;
for (Agent* other : Neighbors) {
if (other == agent) {
continue;
}
Vector2D R = other->getPosition() - AgentPos;
float Vb = other->getPreferdSpeed();
Vector2D eb = (other->getGoal() - other->getPosition()).getnormalized();
float B = 0.5*sqrtf(pow(R.magnitude() + (R - Vb * dt*eb).magnitude(), 2) - pow(Vb*dt, 2));
Vector2D DB = (1/(2*B))*(pow(R.magnitude() + (R - Vb * dt*eb).magnitude(), 2) / (R.magnitude() * (R - Vb * dt*eb).magnitude()))*R;
Repulsion += exp(-B) * DB;
TotalCost += exp(-B);
}
Result.Gradient = Repulsion;
Result.TotalCost = TotalCost;
// cout << Result.Gradient.x() << " " << Result.Gradient.y() << endl;
return Result;
}
/* Crowd Simulator Engine
** Copyright (C) 2018 - Inria Rennes - Rainbow - Julien Pettre
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
**
**
** Authors: Axel Lopez Gandia, Javad Amirian, Florian Berton,
** Julien Legros, Lucas Pelerin, Beatriz Cabrero Daniel, Fabien Grzeskowiak
**
** Contact: crowd_group@inria.fr
*/
#include <CostFunctions/SocialForcesGoalReaching.h>
#include <core/agent.h>
#include <core/world.h>
#include <algorithm>
#include <iostream>
using namespace std;
const std::string SocialForcesGoalReaching::Name = "SocialForcesGoalReaching";
SocialForcesGoalReaching::SocialForcesGoalReaching() {
name_ = "SocialForces";
}
SocialForcesGoalReaching::~SocialForcesGoalReaching() {
}
CostFunctionValues SocialForcesGoalReaching::GetCostFunctionGradient(Agent* agent, World * world) {
CostFunctionValues Result;
Vector2D Goal = agent->getGoal();
Vector2D AgentPos = agent->getPosition();
float PreferedSpeed = agent->getPreferdSpeed();
Vector2D CurrentVel = agent->getVelocity();
Vector2D GoalAgent = Goal - AgentPos;
Vector2D GoalDir = GoalAgent.getnormalized();
Vector2D Atraction = (CurrentVel - GoalDir*PreferedSpeed);
Result.Gradient = Atraction;
Result.TotalCost = 0.5*(CurrentVel - GoalDir * PreferedSpeed).sqrMagnitude();
return Result;
}
......@@ -29,6 +29,8 @@
#include <iostream>
using namespace std;
const std::string GoalReaching::Name = "GoalReaching";
GoalReaching::GoalReaching() {
name_ = "GoalReaching";
}
......
......@@ -31,6 +31,8 @@
#include <iostream>
using namespace std;
const std::string SocialForces::Name = "SocialForces";
SocialForces::SocialForces() {
name_ = "SocialForces";
}
......
#include "../include/core/costFunctionFactory.h"
#include "../include/CostFunctions/FOEAvoidance.h"
#include "../include/CostFunctions/GenericCost.h"
#include "../include/CostFunctions/goalReaching.h"
#include "../include/CostFunctions/socialforces.h"
#include "../include/CostFunctions/TtcaDca.h"
#include "core/costFunctionFactory.h"
#include "CostFunctions/FOEAvoidance.h"
#include "CostFunctions/GenericCost.h"
#include "CostFunctions/goalReaching.h"
#include "CostFunctions/socialforces.h"
#include "CostFunctions/SocialForcesAvoidance.h"
#include "CostFunctions/SocialForcesGoalReaching.h"
#include "CostFunctions/TtcaDca.h"
#include <iostream>
CostFunctionFactory::CostFunctionFactory()
{
......@@ -17,21 +19,24 @@ CostFunctionFactory::~CostFunctionFactory()
std::shared_ptr<CostFunction>
CostFunctionFactory::CreateCostFunction(const std::string& name) {
if (name == GenericCost().getName()) {
if (name == GenericCost::Name) {
return std::make_shared<GenericCost>();
}
if (name == FOEAvoidance().getName()) {
if (name == FOEAvoidance::Name) {
return std::make_shared<FOEAvoidance>();
}
if (name == GenericCost().getName()) {
return std::make_shared<GenericCost>();
}
if (name == GoalReaching().getName()) {
if (name == GoalReaching::Name) {
return std::make_shared<GoalReaching>();
}
if (name == SocialForces().getName()) {
if (name == SocialForces::Name) {
return std::make_shared<SocialForces>();
}
if (name == SocialForcesAvoidance::Name) {
return std::make_shared<SocialForcesAvoidance>();
}
if (name == SocialForcesGoalReaching::Name) {
return std::make_shared<SocialForcesGoalReaching>();
}
if (name == TtcaDcaAvoidance().getName()) {
return std::make_shared<TtcaDcaAvoidance>();
}
......
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