Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseAgent.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
39 #ifndef __BASE_AGENT_H__
40 #define __BASE_AGENT_H__
41 
48 // UTILS
49 #include "mengeCommon.h"
50 #include "XMLSimulatorBase.h"
51 #include "PrefVelocity.h"
55 // STL
56 #include <vector>
57 #include <list>
58 
59 namespace Menge {
60 
61  namespace Agents {
62 
63  class Obstacle;
64 
68  class MENGE_API AgentException : public virtual MengeException {
69  public:
74 
80  AgentException( const std::string & s ): MengeException(s) {}
81  };
82 
86  class MENGE_API AgentFatalException : public AgentException, public MengeFatalException {
87  public:
92 
99  };
100 
105  public:
110 
116  AgentImplementationException( const std::string & s ): AgentFatalException(s) {}
117  };
118 
123  class MENGE_API BaseAgent : public ProximityQuery {
124  public:
125 
129  BaseAgent();
130 
134  void initialize();
135 
142  void update( float timeStep );
143 
155  void computeNewVelocity();
156 
163  const BaseAgent * getNeighbor( int idx ) const { return _nearAgents[ idx ].agent; }
164 
171  const Obstacle * getObstacle( int idx ) const { return _nearObstacles[ idx ].obstacle; }
172 
173 
179  void setPreferredVelocity(PrefVelocity &velocity);
180 
186  void addVelModifier( BFSM::VelModifier * v );
187 
188 
189  // Properties of a basic agent
193  float _maxSpeed;
194 
198  float _maxAccel;
199 
203  float _prefSpeed;
204 
209 
214 
219 
227 
242 
247  float _maxAngVel;
248 
253 
259 
260 
266  size_t _class;
267 
275  size_t _obstacleSet;
276 
282  float _priority;
283 
287  size_t _id;
288 
299  float _radius;
300 
305  std::vector<BFSM::VelModifier *> _velModifiers;
306 
313  std::vector<NearAgent> _nearAgents;
314 
321  std::vector<NearObstacle> _nearObstacles;
322 
330  void insertAgentNeighbor(const BaseAgent* agent, float distSq);
331 
339  void insertObstacleNeighbor(const Obstacle* obstacle, float distSq);
340 
341  // TODO: Ultimately, this should go into an intention filter and not the agent itself
350  virtual void setStrideParameters( float stride, float buffer ) {}
351 
352 
353  // Methods needed for a spatial query filter to work
354 
358  virtual void startQuery();
359 
366  virtual void filterAgent(const BaseAgent *agent, float distance);
367 
374  virtual void filterObstacle(const Obstacle *, float distance);
375 
381  virtual Vector2 getQueryPoint(){ return _pos;};
382 
390  virtual float getMaxAgentRange();
391 
399  virtual float getMaxObstacleRange() { return _neighborDist * _neighborDist;};
400  };
401  } // namespace Agents
402 } // namespace Menge
403 #endif // __BASE_AGENT_H__
std::vector< NearObstacle > _nearObstacles
The nearby obstacles to which the agent should respond.
Definition: BaseAgent.h:321
size_t _class
The population class for this agent.
Definition: BaseAgent.h:266
float _radius
The agent's radius.
Definition: BaseAgent.h:299
virtual float getMaxObstacleRange()
updates the max query obstacle range if conditions inside the filter are met typically, we don't shrink the query range until the result set is full
Definition: BaseAgent.h:399
PrefVelocity _velPref
The 2D preferred velocity of the agent.
Definition: BaseAgent.h:218
float _prefSpeed
The preferred speed of the agent.
Definition: BaseAgent.h:203
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Vector2 _vel
The current 2D velocity of the agent.
Definition: BaseAgent.h:213
size_t _obstacleSet
A mask indicating the obstacles with compatible ids which this agent can see.
Definition: BaseAgent.h:275
AgentImplementationException()
Default constructor.
Definition: BaseAgent.h:109
std::vector< BFSM::VelModifier * > _velModifiers
a set of velocity modifiers to be set with the agent. Allows for intermediate velocity changes ...
Definition: BaseAgent.h:305
const Obstacle * getObstacle(int idx) const
Returns a pointer to the obstacle with given index.
Definition: BaseAgent.h:171
Exception for BaseAgent problems.
Definition: BaseAgent.h:68
Vector2 _pos
The current 2D position of the agent.
Definition: BaseAgent.h:208
const BaseAgent * getNeighbor(int idx) const
Returns a pointer to the neighbor with given index.
Definition: BaseAgent.h:163
The definition of a preferred velocity.
std::vector< NearAgent > _nearAgents
The nearby agents to which the agent should respond.
Definition: BaseAgent.h:313
float _maxSpeed
The maximum speed the agent can take.
Definition: BaseAgent.h:193
The definition of how preferred velocity is modified by a filter.
float _maxAccel
The maximum acceleration the agent can experience (interpreted isotropically).
Definition: BaseAgent.h:198
size_t _id
A globally unique identifier for each agent.
Definition: BaseAgent.h:287
virtual void setStrideParameters(float stride, float buffer)
Sets the density sensitivity parameters.
Definition: BaseAgent.h:350
Vector2 _velNew
The new velocity computed in computeNewVelocity.
Definition: BaseAgent.h:226
Base exception class for menge operations.
Definition: MengeException.h:58
AgentException()
Default constructor.
Definition: BaseAgent.h:73
The base class for filtering spatial queries according to proximity.
Definition: ProximityQuery.h:72
Vector2 _orient
The orientation vector (the direction the agent is facing which is not necessarily the same direction...
Definition: BaseAgent.h:241
AgentFatalException()
Default constructor.
Definition: BaseAgent.h:91
AgentFatalException(const std::string &s)
Constructor with message.
Definition: BaseAgent.h:98
The fatal agent exception.
Definition: BaseAgent.h:86
virtual Vector2 getQueryPoint()
gets the start point for the query
Definition: BaseAgent.h:381
Base class for fatal exceptions.
Definition: MengeException.h:99
The set of operations used by SimXMLLoader to apply XML-parsed experiment specification to a simulato...
size_t _maxNeighbors
The number of nearby agents used to plan dynamic respones.
Definition: BaseAgent.h:252
Defines static obstacles in the simulation.
Definition: Obstacle.h:56
float _neighborDist
The maximum distance at which another agent will be considered for a response.
Definition: BaseAgent.h:258
Structs for storing results from spatial queries.
float _priority
The priority of each agent.
Definition: BaseAgent.h:282
The base class for all objects which actually perform filtering and store results from spatial querie...
The definition of a preferred velocity.
Definition: PrefVelocity.h:68
Defines the basic agent properties and functionality that all simulation agents share.
Definition: BaseAgent.h:123
The base class for modifying preferred velocities.
Definition: VelModifier.h:110
The namespace that contains the basic simulation mechanisms.
float _maxAngVel
The agent's maximum angular velocity (in radians/sec) – used for controlling the changes in agent or...
Definition: BaseAgent.h:247
AgentException(const std::string &s)
Constructor with message.
Definition: BaseAgent.h:80
AgentImplementationException(const std::string &s)
Constructor with message.
Definition: BaseAgent.h:116
Special agent exception - used for non-implemented functionality.
Definition: BaseAgent.h:104