BioinstSim  2
 All Classes Functions Variables
agent.h
1 #ifndef AGENT_H_
2 #define AGENT_H_
3 
4 /******************************************************************************/
5 /******************************************************************************/
6 // FAULT DETECTION MODEL TYPE
7 enum faultdetectionmodeltype {CRM, CRM_TCELLSINEXCESS, CTRNN, LINEQ};
8 
9 #define FDMODELTYPE CRM_TCELLSINEXCESS //CRM
10 
11 /******************************************************************************/
12 /******************************************************************************/
13 
14 #define MODELSTARTTIME 450
15 
16 /******************************************************************************/
17 /******************************************************************************/
18 
19 //#define DEBUGFLAG // verbose - prints stmts on cell densities, fvs etc... (currently only implemented for crm optimised model)
20 #define FLOATINGPOINTOPERATIONS
21 /******************************************************************************/
22 /******************************************************************************/
23 
24 //#define DISABLEMODEL_RETAINRNDCALLS
25 
26 /******************************************************************************/
27 /******************************************************************************/
28 
29 //#define TCELLCLONEEXCHANGEANALYSIS
30 
31 /******************************************************************************/
32 /******************************************************************************/
33 
34 class CAgent;
35 
36 #include "common.h"
37 
38 /******************************************************************************/
39 /******************************************************************************/
40 
41 typedef list<CAgent*> TAgentList;
42 typedef list<CAgent*>::iterator TAgentListIterator;
43 typedef list<TAgentList*> TAgentListList;
44 typedef list<TAgentList*>::iterator TAgentListListIterator;
45 
46 typedef vector<CAgent*> TAgentVector;
47 typedef vector<CAgent*>::iterator TAgentVectorIterator;
48 
49 
50 /******************************************************************************/
51 /******************************************************************************/
52 
53 typedef struct {
54  float fRed;
55  float fGreen;
56  float fBlue;
57 } TColor3f;
58 
59 
60 
61 enum EControllerType
62 {
63  RANDOMWALK,
64  REGULARBOUNCE,
65  RANDOMBOUNCE
66 };
67 
68 
69 enum EAgentType
70 {
71  ANY,
72  ROBOT,
73  LIGHT
74 };
75 
76 /******************************************************************************/
77 /******************************************************************************/
78 
79 class CAgent : public CSimObject
80 {
81 public:
82  CAgent(const char* pch_name, unsigned int un_identification, CArguments* pc_arguments);
83  virtual ~CAgent();
84 
85  // Get the current position of the agent:
86  virtual const TVector2d* GetPosition() const;
87 
88  // Set the current position of the agent:
89  virtual void SetPosition(TVector2d* pt_new_position);
90 
91  // Get the current velocity of the agent:
92  virtual const TVector2d* GetVelocity() const;
93 
94  // Get the current velocity of the agent:
95  virtual const TVector2d* GetAcceleration() const;
96 
97  // Get the change in velocity direction of the agent
98  virtual double GetAngularVelocity();
99 
100  // Get the angular acceleration of the agent
101  virtual double GetAngularAcceleration();
102 
103  // Get the current velocity of the agent:
104  virtual void SetVelocity(TVector2d* pt_velocity_position);
105 
106  // Get the magnitude and direction of agent's relative velocity
107  virtual void GetRelativeVelocity(double* mag_relvelocity, double* dir_relvelocity, double feature_range);
108 
109  // Get the magnitude and direction of agent's relative acceleration
110  virtual void GetRelativeAcceleration(double *mag_relacceleration, double *dir_relacceleration, double feature_range);
111 
112 
113  // Get the angle between the two vectors (acos)
114  virtual double GetVectorAngle(TVector2d vector1, TVector2d vector2);
115 
116  // This method is called if the agent moves to a new arena square.
117  // Useful to calculate distances to other agents, update physical
118  // links etc.
119  virtual void SimulationStep(unsigned int n_step_number);
120  virtual void SimulationStepUpdatePosition();
121 
122  virtual void SetMaximumSpeed(double f_max_speed);
123  virtual double GetMaximumSpeed() const;
124 
125  virtual double GetMaximumAngularVelocity() const;
126 
127  static unsigned int g_unGlobalNumberOfAgentsCreated;
128 
129  virtual unsigned int GetColor();
130  virtual void SetColor(unsigned int un_index);
131 
132  virtual double GetSize();
133 
134  virtual EAgentType GetType() = 0;
135 // virtual bool AcceptConnections() = 0;
136 
137  virtual inline unsigned int GetIdentification() {return m_unIdentification;}
138 
139  virtual void SetBehavIdentification(int i_behavidentification);
140  virtual int GetBehavIdentification();
141 
142  bool m_bTempWithInRange;
143  double m_fTempDistance;
144 
145  static double RADIUS;
146 
147  virtual CAgent* GetClosestAgent(double f_range, EAgentType e_type);
148 
149  virtual TVector2d GetCenterOfMassOfSurroundingAgents(double f_range, EAgentType e_type);
150  virtual double GetAverageDistanceToSurroundingAgents(double f_range, EAgentType e_type);
151  virtual TVector2d GetAverageVelocityOfSurroundingAgents(double f_range, EAgentType e_type);
152  virtual TVector2d GetAverageAccelerationOfSurroundingAgents(double f_range, EAgentType e_type);
153  virtual void MarkAgentsWithinRange(TAgentListList* ptlist_agent_list_list, double f_range, EAgentType e_type);
154  virtual CAgent* GetRandomAgentWithinRange(TAgentListList* ptlist_agent_list_list, double f_range, EAgentType e_type);
155  virtual unsigned int CountAgentsInAgentListList(TAgentListList* ptlist_agent_list_list, double f_range, EAgentType e_type);
156  virtual unsigned int CountAgents(double f_range, EAgentType e_type);
157 
158  virtual void SetRandomVelocity();
159  virtual void MoveTowards(TVector2d t_position, double f_max_speed);
160 
161  virtual void SortAllAgentsAccordingToDistance(TAgentVector* pt_result);
162 
163 
164 protected:
165  TVector2d m_tPosition;
166  TVector2d m_tVelocity;
167  TVector2d m_tAcceleration;
168 
169  double m_fMaximumSpeed;
170  double m_fMaximumPhysicalRange_Recruitment;
171 
172  double m_tAngularVelocity; // tracks changes in velocity (direction) of the agent
173  double m_tAngularAcceleration; // tracks changes in velocity (direction) of the agent
174 
175  EControllerType m_eControllerType;
176 
177  bool m_bInteractable;
178 
179  unsigned int m_unIdentification;
180 
181  unsigned int m_iBehavIdentification; // -1: abnormal, +1: normal
182 
183  unsigned int m_unColor;
184 
185  double m_fProportionalDirectionNoise;
186  double m_fProportionalMagnitudeNoise;
187 
188  CArguments* m_pcArguments;
189 };
190 
191 /******************************************************************************/
192 /******************************************************************************/
193 
194 #endif