BioinstSim  2
 All Classes Functions Variables
crminrobotagent.h
1 #ifndef CRMINROBOTAGENT_H
2 #define CRMINROBOTAGENT_H
3 
4 /******************************************************************************/
5 /******************************************************************************/
6 #include <assert.h>
7 #include <limits.h>
8 #include <math.h>
9 #include "arguments.h"
10 #include "featurevector.h"
11 #include "random.h"
12 #include "robotagent.h"
13 
14 /******************************************************************************/
15 /******************************************************************************/
16 
17 #define CELLLOWERBOUND 1e-3 //todo: set as percentage instead of absolute value
18 // note: could result in euler-huen diff at 0, for high error thresholds. In that case, lower this value
19 
20 #define CONJUGATION_OVERFLOW_LIMIT 1.0e-15 //todo: set as percentage instead of absolute value
21 
22 /******************************************************************************/
23 /******************************************************************************/
24 
25 class CRMinRobotAgent;
26 
27 /******************************************************************************/
28 /******************************************************************************/
29 
30 class CRobotAgent;
31 
32 /******************************************************************************/
33 /******************************************************************************/
34 
36 {
37 public:
38  CRMinRobotAgent(CRobotAgent* ptr_robotAgent, CArguments* m_crmArguments);
39 
40  virtual ~CRMinRobotAgent();
41 
42  virtual double GetCurrE(unsigned thtype);
43  virtual double GetCurrR(unsigned thtype);
44 
45  virtual void SetCurrE(unsigned thtype, double f_currE);
46  virtual void SetCurrR(unsigned thtype, double f_currR);
47 
48  virtual double GetAPC(unsigned apctype);
49 
50  virtual double FreeThCells(double* E, double* R, double** C, unsigned int thtype);
51  virtual double AvailableBindingSites(double** C, unsigned int apctype);
52 
53  virtual double Factorial(double val);
54  virtual double Combination(double N, double R);
55  virtual double Hyp(double N, double No, double M, double L);
56 
57  virtual void ConjugatesQSS(double* E, double* R, double** C);
58  virtual void Derivative(double* E, double* R, double** C, double* deltaE, double* deltaR);
59 
60  virtual double GetFVtoApcScaling();
61 
62  virtual bool GetConvergenceFlag();
63 
64  virtual double GetConvergenceError();
65  virtual double GetConvergenceError_Perc();
66 
67  virtual void PrintCRMDetails(unsigned id);
68 
69  virtual void SimulationStepUpdatePosition();
70 
71  void ScaleDownConjugates(double** f_Conjugates);
72 
73  double* m_pfSumEffectorsWeightedbyAffinity;
74  double* m_pfSumRegulatorsWeightedbyAffinity;
75 
76 
77  static unsigned int GetNumberOfSetBits(unsigned int x);
78 
79 protected:
80 
81  CRobotAgent* robotAgent;
82 
83  static double NormalizedAffinity(unsigned int v1, unsigned int v2);
84  static double NegExpDistAffinity(unsigned int v1, unsigned int v2, double k);
85 
86  virtual void UpdateState();
87 
88  virtual void Sense();
89 
90  //virtual bool TryToConnectToRandomAgentWithWeights(EAgentType e_type, double f_range);
91  //virtual CAgent* GetRandomAgentWithinRangeWithWeights(TAgentListList* pt_agents_list_list, double f_range, EAgentType e_type);
92  //virtual double CountWeightsInAgentListList(TAgentListList* ptlist_agent_list_list, double f_range, EAgentType e_type);
93 
94  virtual double GetWeight();
95 
96 
97  double step_h; double conjstep_h; // internal step count of the CRM instance
98  double currE; // : Density of effector cells
99  double currR; // : Density of regulatory cells
100  double kon; // : Conjugation rate
101  double koff; // : Dissociation rate
102  double kpe; // : Proliferation rate for effector cells
103  double kde; // : Death rate for effector cells
104  double kpr; // : Proliferation rate for regulatory cells
105  double kdr; // Death rate for regulatory cells
106  double se; // Rate of generation of new effector cells
107  double sr; // Rate of generation of new regulatory cells
108  unsigned int sites; // Number of binding sites on each APC
109 
110  // For communication of cells between robots
111  double m_fTryExchangeProbability; // Probability of trying to exchange cells with other robots
112  //double m_fExchangeRange;
113 
114  double* m_pfEffectors;
115  double* m_pfRegulators;
116  double* m_pfEffectors_prev;
117  double* m_pfRegulators_prev;
118 
119  double* m_pfAPCs;
120 
121 
122  // predicted number of cells at time t+step with Euler method
123  double* m_pfEffectors_Eu;
124  double* m_pfRegulators_Eu;
125  // predicted number of cells at time t+step with Huen method
126  double* m_pfEffectors_Hu;
127  double* m_pfRegulators_Hu;
128  // the slopes at time = t and time = t+step
129  double* m_pfDeltaEffectors_k0;
130  double* m_pfDeltaRegulators_k0;
131  double* m_pfDeltaEffectors_k1;
132  double* m_pfDeltaRegulators_k1;
133 
134  // for the computation of conjugates in QSS
135  double** m_pfDeltaConjugates_k0;
136  double** m_pfDeltaConjugates_k1;
137  double** m_pfConj_tmp_Eu;
138  double** m_pfConj_tmp_Hu;
139 
140 
141  unsigned int m_unNumberOfReceptors;
142 
143  double** m_pfConjugates;
144  double** m_pfConjugates_tmp;
145  double** m_pfConjugates_Eu; // the number of conjugates for cells at time t+step, predicted with Eulers method
146 
147  double** m_pfEffectorConjugates;
148  double** m_pfRegulatorConjugates;
149  double* m_pfEffectorConjugatesPerAPC;
150  double* m_pfRegulatorConjugatesPerAPC;
151 
152  double** m_pfAffinities;
153 
154  double* m_pfEff_h;
155  double* m_pfReg_h;
156 
157  double m_fAttackProbability;
158 
159  double m_fcross_affinity; /* the level of cross affinity*/
160 
161  //int* m_pbAttack; // 0: No state 1: Attack 2: Tolerate
162 
163  double m_fWeight;
164 
165  double m_fFVtoApcscaling;
166 
167  bool m_bConvergenceFlag;
168  double m_dconvergence_error;
169  double m_dpercconvergence_error;
170 
171 };
172 
173 /******************************************************************************/
174 /******************************************************************************/
175 
176 #endif // CRMINROBOTAGENT_H