Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Goal.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 
44 #ifndef __GOALS_H__
45 #define __GOALS_H__
46 
47 #include "CoreConfig.h"
48 #include "fsmCommon.h"
49 #include "Element.h"
50 #include "ReadersWriterLock.h"
51 #include "MengeException.h"
52 
53 // forward declaration
54 class TiXmlElement;
55 
56 namespace Menge {
57 
58  namespace Agents {
59  class PrefVelocity;
60  }
61 
62  namespace BFSM {
63 
64  // Forward declaration
65  class GoalSet;
66 
70  class MENGE_API GoalException : public virtual MengeException {
71  public:
76 
82  GoalException( const std::string & s ): MengeException(s) {}
83 
84  };
85 
91  public:
96 
103  };
104 
106 
110  class MENGE_API Goal : public Element {
111  public:
116  Goal():Element(),_weight(1.f),_capacity(MAX_CAPACITY),_id(-1),_goalSet(0x0),_population(0){} // -1 is the biggest value for size_t
117 
118  protected:
122  virtual ~Goal(){}
123 
124  public:
131  virtual float squaredDistance( const Vector2 & pt ) const = 0;
132 
146  virtual void setDirections( const Vector2 & q, float r, Agents::PrefVelocity & directions ) const = 0;
147 
148  // TODO: Delete this function= transition uses it determine distance to goal
149  // I would be better off simply returning "squared distance to goal"
165  virtual Vector2 getTargetPoint( const Vector2 & q, float r ) const = 0;
166 
170  virtual Vector2 getCentroid() const = 0;
171 
177  bool hasCapacity() const;
178 
184  void assign( const Agents::BaseAgent * agent );
185 
189  void free();
190 
196  inline void setGoalSet( GoalSet * goalSet ) { _goalSet = goalSet; }
197 
209  inline GoalSet * getGoalSet() { return _goalSet; }
210 
222  inline const GoalSet * getGoalSet() const { return _goalSet; }
223 
229  inline void setWeight( float weight ) { _weight = weight; }
230 
236  inline float getWeight() const { return _weight; }
237 
243  inline void setCapacity( size_t capacity ) { _capacity = capacity; }
244 
250  inline size_t getCapacity() const { return _capacity; }
251 
257  inline void setID( size_t id ) { _id = id; }
258 
264  inline size_t getID() const { return _id; }
265 
269  virtual void drawGL() const;
270 
274  static const size_t MAX_CAPACITY;
275 
276  friend class GoalSet;
277 
278  protected:
282  virtual void drawGLGeometry() const {}
283 
287  float _weight;
288 
292  size_t _capacity;
293 
297  size_t _id;
298 
303 
310  mutable size_t _population;
311 
317  };
318 
327  Goal * parseGoal( TiXmlElement * node, const std::string & behaveFldr );
328 
329  } // namespace BFSM
330 
331 } // namespace Menge
332 #endif //__GOALS_H__
void setGoalSet(GoalSet *goalSet)
Sets this goal's goal set.
Definition: Goal.h:196
size_t getCapacity() const
Returns this goal's capacity.
Definition: Goal.h:250
void setID(size_t id)
Sets the id of the goal.
Definition: Goal.h:257
void setWeight(float weight)
Sets the goal's weight.
Definition: Goal.h:229
size_t _capacity
The maximum capacity of this goal.
Definition: Goal.h:292
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
Sets up the proper compiler directives for platform and dll export/import.
GoalFatalException()
Default constructor.
Definition: Goal.h:95
A set of goals. Maps integer identifiers to instances of goals.
Definition: GoalSet.h:63
GoalException()
Default constructor.
Definition: Goal.h:75
GoalSet * _goalSet
The goal set to which this goal belongs.
Definition: Goal.h:302
The base, abstract class defining goals.
Definition: Goal.h:110
ReadersWriterLock _lock
The lock to maintain readers-writer access to the structure which control available goals...
Definition: Goal.h:316
The definition of a readers-writer lock.
Definition: ReadersWriterLock.h:62
GoalException(const std::string &s)
Constructor with message.
Definition: Goal.h:82
virtual void drawGLGeometry() const
Draws the goal geometry.
Definition: Goal.h:282
The base definition for exceptions in Menge.
Base class for all Menge elements.
The basic interface of extendible Menge Elements.
Definition: Element.h:67
const GoalSet * getGoalSet() const
Returns a const pointer to this agent's goal set.
Definition: Goal.h:222
GoalSet * getGoalSet()
Returns a pointer to this agent's goal set.
Definition: Goal.h:209
Base exception class for menge operations.
Definition: MengeException.h:58
static const size_t MAX_CAPACITY
The maximum capacity any goal can hold.
Definition: Goal.h:274
The definition of a readers-writer lock.
void setCapacity(size_t capacity)
Sets the goal's capacity.
Definition: Goal.h:243
Base class for fatal exceptions.
Definition: MengeException.h:99
The namespace contains the Behavior Finite State Machine (BFSM) definition.
float getWeight() const
Retrieves the goal's weight.
Definition: Goal.h:236
Collection of convenient pre-compiler information for fsm definitions.
GoalFatalException(const std::string &s)
Constructor with message.
Definition: Goal.h:102
Goal()
Basic constructor.
Definition: Goal.h:116
float _weight
The relative weight of this goal.
Definition: Goal.h:287
Exception thrown when the goal has an error which cannot be recovered from.
Definition: Goal.h:90
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 namespace that contains the basic simulation mechanisms.
size_t getID() const
Gets the id of the goal.
Definition: Goal.h:264
size_t _population
The current "population" of this goal.
Definition: Goal.h:310
size_t _id
The id of this goal in its goal set.
Definition: Goal.h:297
Exception class for BFSM goals.
Definition: Goal.h:70
virtual ~Goal()
Destructor.
Definition: Goal.h:122