BioinstSim  2
 All Classes Functions Variables
crminrobotagent_optimised.h
1 #ifndef CRMINROBOTAGENTOPTIMISED_H
2 #define CRMINROBOTAGENTOPTIMISED_H
3 
4 /******************************************************************************/
5 /******************************************************************************/
6 #include <assert.h>
7 #include <limits.h>
8 #include <math.h>
9 #include <list>
10 #include "arguments.h"
11 #include "featurevector.h"
12 #include "random.h"
13 #include "robotagent_optimised.h"
14 #include "celldatacontainers.h"
15 
16 /******************************************************************************/
17 /******************************************************************************/
18 
19 #define CELLLOWERBOUND 1e-3 //todo: set as percentage instead of absolute value
20 // note: could result in euler-huen diff at 0, for high error thresholds. In that case, lower this value
21 
22 #define CONJUGATION_OVERFLOW_LIMIT 1.0e-15 //todo: set as percentage instead of absolute value
23 
24 /******************************************************************************/
25 /******************************************************************************/
26 
27 using namespace std;
28 
29 /******************************************************************************/
30 /******************************************************************************/
31 
33 
34 /******************************************************************************/
35 /******************************************************************************/
36 
38 
39 /******************************************************************************/
40 /******************************************************************************/
41 
42 struct structTcell; struct structAPC;
43 enum ConjugationIntegrationPhase : unsigned {CONJ_K0, CONJ_K1, CONJ};
44 enum TcellIntegrationPhase : unsigned {K0, K1};
45 
46 /******************************************************************************/
47 /******************************************************************************/
48 
50 {
51 public:
52  CRMinRobotAgentOptimised(CRobotAgentOptimised* ptr_robotAgent, CArguments* m_crmArguments);
53 
54  virtual ~CRMinRobotAgentOptimised();
55 
56  virtual double GetCurrE(unsigned int thtype);
57  virtual double GetCurrR(unsigned int thtype);
58 
59  virtual void SetCurrE(unsigned int thtype, double f_currE);
60  virtual void SetCurrR(unsigned int thtype, double f_currR);
61 
62  virtual double GetAPC(unsigned int apctype);
63 
64 // virtual inline double FreeThCells(double* E, double* R, double** C, unsigned int thtype);
65 // virtual inline double AvailableBindingSites(double** C, unsigned int apctype);
66 
67  virtual void FreeTcellsAndAvailableAPCSites(TcellIntegrationPhase TK, ConjugationIntegrationPhase CONJK);
68 
69  virtual void ConjugatesQSS(bool bResetConjugates, TcellIntegrationPhase TK); //double* E, double* R, double** C);
70  virtual void Derivative(TcellIntegrationPhase TK); //double* E, double* R, double** C, double* deltaE, double* deltaR);
71 
72  virtual void ConjugatesQSS_ExcessTcells(bool bClearDeadConjugates, TcellIntegrationPhase TK); //double* E, double* R, double** C);
73  virtual void Derivative_ExcessTcells(TcellIntegrationPhase TK); //double* E, double* R, double** C, double* deltaE, double* deltaR);
74  virtual void ComputeNewDerivative(TcellIntegrationPhase TK);
75 
76  virtual inline double GetFVtoApcScaling() {return m_fFVtoApcscaling;}
77 
78  virtual inline double GetConvergenceError() {return m_dconvergence_error;}
79  virtual inline double GetConvergenceError_Perc() {return m_dpercconvergence_error;}
80 
81  virtual void PrintCRMDetails(unsigned int id);
82  virtual void PrintAPCList(unsigned int id);
83  virtual void PrintTcellResponseToAPCList(unsigned int id);
84  virtual void PrintTcellList(unsigned int id);
85  virtual void PrintConjugatestoAPCList(unsigned int id, ConjugationIntegrationPhase CONJK);
86  virtual void PrintConjugatestoTcellList(unsigned int id, ConjugationIntegrationPhase CONJK);
87 
88  virtual void TcellNumericalIntegration_RK2();
89  virtual void SimulationStepUpdatePosition();
90  virtual void DiffuseTcells();
91 
92  void ScaleDownConjugates(ConjugationIntegrationPhase CONJK);
93 
94 // double* m_pfSumEffectorsWeightedbyAffinity;
95 // double* m_pfSumRegulatorsWeightedbyAffinity;
96 
97  inline list<structAPC>* GetListAPCs() {return &listAPCs;}
98  inline list<structTcell>* GetListTcells() {return &listTcells;}
99 
100  static double NegExpDistAffinity(unsigned int v1, unsigned int v2, double k);
101  static unsigned int GetNumberOfSetBits(unsigned int x);
102 
103 protected:
104 
105  CRobotAgentOptimised* robotAgent;
106 
107  virtual void UpdateState();
108 
109  virtual void UpdateAPCList(); //Sense()
110  virtual void UpdateTcellList(unsigned int hammingdistance); //unsigned hammingdistance
111  virtual void UpdateConjugatesToAPCList();
112  virtual void UpdateConjugatesToTcellList();
113  virtual void MarkConjugatesOfDeadTcell(list<structTcell>::iterator* ptrit_tcells);
114 
115  virtual inline double GetWeight() {return m_fWeight;}
116 
117 
118  double step_h; double conjstep_h; // internal step count of the CRM instance
119  double currE; // : Density of effector cells at the start
120  double currR; // : Density of regulatory cells at the start
121  double kon; // : Conjugation rate
122  double koff; // : Dissociation rate
123  double kpe; // : Proliferation rate for effector cells
124  double kde; // : Death rate for effector cells
125  double kpr; // : Proliferation rate for regulatory cells
126  double kdr; // Death rate for regulatory cells
127  double se; // Rate of generation of new effector cells
128  double sr; // Rate of generation of new regulatory cells
129  unsigned int sites; // Number of binding sites on each APC
130 
131  // For communication of cells between robots
132  double m_fTryExchangeProbability; // Probability of trying to exchange cells with other robots
133  //double m_fExchangeRange;
134 
135 
136 // double* m_pfEffectors;
137 // double* m_pfRegulators;
138 // double* m_pfEffectors_prev;
139 // double* m_pfRegulators_prev;
140 
141 // double* m_pfAPCs;
142 
143 
144 // // predicted number of cells at time t+step with Euler method
145 // double* m_pfEffectors_Eu;
146 // double* m_pfRegulators_Eu;
147 // // predicted number of cells at time t+step with Huen method
148 // double* m_pfEffectors_Hu;
149 // double* m_pfRegulators_Hu;
150 // // the slopes at time = t and time = t+step
151 // double* m_pfDeltaEffectors_k0;
152 // double* m_pfDeltaRegulators_k0;
153 // double* m_pfDeltaEffectors_k1;
154 // double* m_pfDeltaRegulators_k1;
155 
156 // // for the computation of conjugates in QSS
157 // double** m_pfDeltaConjugates_k0;
158 // double** m_pfDeltaConjugates_k1;
159 // double** m_pfConj_tmp_Eu;
160 // double** m_pfConj_tmp_Hu;
161 
162  list<structTcell> listTcells;
163  list<structAPC> listAPCs;
164  virtual inline void IncIt(list<structTcell>::iterator *it_tcell, list<structTcell>* list)
165  { (*it_tcell) == list->end() ? (*it_tcell):++(*it_tcell); }
166  virtual inline void IncIt(list<structAPC>::iterator *it_apc, list<structAPC>* list)
167  { (*it_apc) == list->end() ? (*it_apc):++(*it_apc); }
168 
169  unsigned int m_unNumberOfReceptors;
170 
171 // double** m_pfConjugates;
172 // double** m_pfConjugates_tmp;
173 // double** m_pfConjugates_Eu; // the number of conjugates for cells at time t+step, predicted with Eulers method
174 
175 // double** m_pfEffectorConjugates;
176 // double** m_pfRegulatorConjugates;
177 // double* m_pfEffectorConjugatesPerAPC;
178 // double* m_pfRegulatorConjugatesPerAPC;
179 
180 // double** m_pfAffinities;
181 
182  double m_fcross_affinity; /* the level of cross affinity*/
183 
184 
185  double m_fWeight;
186  double m_fFVtoApcscaling;
187 
188  bool m_bConvergenceFlag;
189  double m_dconvergence_error;
190  double m_dpercconvergence_error;
191 
192 };
193 
194 
195 /******************************************************************************/
196 /******************************************************************************/
197 
198 #endif // CRMINROBOTAGENTOPTIMISED_H