TtcaDca.h 2.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/* 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_TTCADCA_H
#define LIB_TTCADCA_H

#include <core/costFunction.h>
30
#include <string>
31 32

/*
33 34 35 36 37 38 39 40 41 42
 * Performs collision avoidance by maximising two thing:
 *  - Time to closest approach => ttca
 *  - Distance to closest approach => dca
 *
 *  At a given time, if two agents A and B are moving in a 2D plane 
 *  with a speed Va and Vb respectively, then if they keep this speed
 *  fixed, there will be a time in the future called ttca when they are at the closest
 *  distance from each other, called dca.
 *
 *  This cost function maximise those 2 metrics together.
43
 *	Parameters: sigmaTtca, sigmaDca
44
 */
45
class TtcaDca : public CostFunction
46
{
47 48 49 50 51
	/*
	 * Parameters of the cost function
	*/
	float sigTtca_ = 2;
	float sigDca_ = 0.5;
52
 private:
53 54 55
     Vector2D GradDca();
     Vector2D GradTtca();
     float Cost(float ttca, float dca);
56

57 58
  
 public:
59 60
	
	const static std::string GetName() { return "TtcaDca"; }
61 62 63 64 65 66 67 68 69 70 71 72
    /*
     * Name of the cost function, to be used in configuration file
     */
    const static std::string Name;

	TtcaDca();
	virtual ~TtcaDca(){};

    bool setSigTtca(float sigTtca);
    bool setSigDca(float sigDca);
    inline float getSigDca(){ return sigDca_; }
    inline float getSigTtca(){ return sigTtca_; }
73 74 75 76 77
  
  /**
   * Computes the value and gradient of the cost function.
   * Return the values to the policy to update the agent.
   */
78
  virtual CostFunctionValues GetCostFunctionGradient(Agent* agent, WorldBase * world);
79
  void parseParameters(tinyxml2::XMLElement*  v) override;
80 81 82
};

#endif //LIB_TTCADCA_H