-
Notifications
You must be signed in to change notification settings - Fork 17
/
Programs.cpp
211 lines (141 loc) · 4.58 KB
/
Programs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/////////////////////////////////////////////////////////////////////////////////////////
//
// gro is protected by the UW OPEN SOURCE LICENSE, which is summarized here.
// Please see the file LICENSE.txt for the complete license.
//
// THE SOFTWARE (AS DEFINED BELOW) AND HARDWARE DESIGNS (AS DEFINED BELOW) IS PROVIDED
// UNDER THE TERMS OF THIS OPEN SOURCE LICENSE (“LICENSE”). THE SOFTWARE IS PROTECTED
// BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THIS SOFTWARE OTHER THAN AS
// AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
//
// BY EXERCISING ANY RIGHTS TO THE SOFTWARE AND/OR HARDWARE PROVIDED HERE, YOU ACCEPT AND
// AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE
// CONSIDERED A CONTRACT, THE UNIVERSITY OF WASHINGTON (“UW”) GRANTS YOU THE RIGHTS
// CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
//
// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
//
//
#include "Programs.h"
#include "EColi.h"
#define Q cell->get_q()
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// OPEN LOOP GFP
//
#define RNA Q[0]
#define PROTEIN Q[1]
void GFP_Program::init ( World * world ) {
EColi * c = new EColi ( world, 0, 0, 0.78, 2*WIDTH );
c->set ( 0, R0 );
c->set ( 1, P0 );
c->set_rep ( GFP, P0 );
world->add_cell ( c );
printf ( "initializing GFP program\n" );
}
void GFP_Program::update ( World *, Cell * cell ) {
PRODUCE ( RNA, 0.01 );
CONSUME ( RNA, 0.002*RNA );
PRODUCE ( PROTEIN, 2.0*RNA );
CONSUME ( PROTEIN, 0.0002*PROTEIN );
cell->set_rep ( GFP, PROTEIN );
}
void GFP_Program::destroy ( World * ) {
}
#undef RNA
#undef PROTEIN
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// BISTABLE SWITCH
//
#define X1 cell->get_q()[2]
#define X2 cell->get_q()[3]
#define GREEN cell->get_q()[0]
#define RED cell->get_q()[1]
#define RATE1 0.004+0.5/(0.03*X2*X2+1)
#define RATE2 0.004+0.5/(0.03*X1*X1+1)
#define DEG1 0.0001
#define DEG2 0.0002
void Bistable_Program::init ( World * world ) {
EColi * c = new EColi ( world, 0, 0, 0.78, 2*WIDTH );
world->add_cell ( c );
}
void Bistable_Program::update ( World *, Cell * cell ) {
PRODUCE ( X1, RATE1 );
PRODUCE ( GREEN, RATE1 );
PRODUCE ( X2, RATE2 );
PRODUCE ( RED, RATE2 );
CONSUME ( X1, DEG1*X1 );
CONSUME ( GREEN, DEG2*GREEN );
CONSUME ( X2, DEG1*X2 );
CONSUME ( RED, DEG2*RED );
cell->set_rep ( GFP, 2*GREEN );
cell->set_rep ( RFP, 2*RED );
}
void Bistable_Program::destroy ( World * ) {
}
#undef X1
#undef X2
#undef RED
#undef GREEN
#undef RATE1
#undef RATE2
#undef DEG1
#undef DEG2
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// BISTABLE SWITCH
//
#define PROTEIN cell->get_q()[0]
#define RNA cell->get_q()[1]
void Sensor_Program::init ( World * world ) {
EColi * c = new EColi ( world, 0, 0, 0.78, 2*WIDTH );
world->add_cell ( c );
Signal * ahl = new Signal ( cpv ( -400, -400 ), cpv ( 400, 400 ), 150, 150, 4, 0 );
ahl->set ( 100.0f, 100.0f, 1000.0f );
world->add_signal ( ahl );
}
void Sensor_Program::update ( World * world, Cell * cell ) {
float a = world->get_signal_value ( cell, 0 );
PRODUCE ( RNA, 0.005+0.1*a );
CONSUME ( RNA, 0.002*RNA );
PRODUCE ( PROTEIN, 0.04*RNA );
CONSUME ( PROTEIN, 0.0001*PROTEIN );
cell->set_rep ( GFP, PROTEIN );
}
void Sensor_Program::destroy ( World * ) {
}
#undef RNA
#undef PROTEIN
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// LEADER ELECTION
//
void LeaderElection::init ( World * world ) {
EColi * c = new EColi ( world, 0, 0, 0.78, 2*WIDTH );
world->add_cell ( c );
Signal * ahl = new Signal ( cpv ( -400, -400 ), cpv ( 400, 400 ), 150, 150, 4, 0 );
world->add_signal ( ahl );
}
void LeaderElection::update ( World * world, Cell * cell ) {
float a = world->get_signal_value ( cell, 0 );
int Q0 = cell->get(0), Q1 = cell->get(1);
if ( Q0 == 0 && Q1 == 0 ) { // Undecided
if ( a > 0.05 )
cell->set(0,100);
else if ( frand() < 0.004 )
cell->set(1,100);
} else if ( Q0 > 0 && Q1 == 0 ) { // Follower
cell->set(0,100);
world->emit_signal(cell,0,0.25);
} else if ( Q0 == 0 && Q1 > 0 ) { // Leader
cell->set(1,100);
world->emit_signal(cell,0,0.5);
} else if ( Q0 > 0 && Q1 > 0 ) {
printf ( "oops\n" );
}
cell->set_rep ( GFP, Q0>0?500:0 );
cell->set_rep ( RFP, Q1>0?500:0 );
}
void LeaderElection::destroy ( World * ) {
}