1 void StochasticRates( double RCT
[], double Volume
, double SCT
[] );
2 void Propensity ( int V
[], int F
[], double SCT
[], double A
[] );
3 void MoleculeChange ( int j
, int NmlcV
[] );
4 double CellMass(double T
);
7 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
8 void Gillespie(int Nevents
, double Volume
, double* T
, int NmlcV
[], int NmlcF
[])
9 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
14 double A
[NREACT
], SCT
[NREACT
], x
;
16 /* Compute the stochastic reaction rates */
18 StochasticRates( RCONST
, Volume
, SCT
);
20 for (event
= 1; event
<= Nevents
; event
++) {
22 /* Uniformly distributed ranfor (m numbers */
23 r1
= (double)rand()/(double)RAND_MAX
;
24 r2
= (double)rand()/(double)RAND_MAX
;
26 /* Avoid log of zero */
27 r2
= (r2
-1.0e-14) ? r2
: 1.0e-14;
29 /* Propensity vector */
31 Propensity ( NmlcV
, NmlcF
, SCT
, A
);
33 /* Cumulative sum of propensities */
34 for (i
=1; i
<NREACT
; i
++)
37 /* Index of next reaction */
39 for ( i
= 0; i
<NREACT
; i
++)
45 /* Update T with time to next reaction */
46 *T
= *T
- log(r2
)/A
[NREACT
-1];
48 /* Update state vector after reaction m */
49 MoleculeChange( m
, NmlcV
);