1 | //size versus energy
|
---|
2 | //real proportions
|
---|
3 |
|
---|
4 | // -------------------------------- step begin --------------------------------
|
---|
5 |
|
---|
6 | function reproduce_haploid(repro_list)
|
---|
7 | {
|
---|
8 | var len = repro_list.size;
|
---|
9 | if (len % 2 != 0) len = repro_list.size - 1;
|
---|
10 |
|
---|
11 | for (var i = 0; i < len - 2 ; i = i + 2)
|
---|
12 | {
|
---|
13 | var parent = Populations[0].get(repro_list[i]);
|
---|
14 | var parent2 = Populations[0].get(repro_list[i + 1]);
|
---|
15 |
|
---|
16 | var number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd;
|
---|
17 |
|
---|
18 | for (var j = 0; j < number; j++)
|
---|
19 | {
|
---|
20 | createOffspring(ExpParams.gend, ExpParams.ofnumd, [parent.user1, parent2.user1], {"Va" : ExpParams.ofnumd, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.ofnumd}); //TODO genes from both generations in user1
|
---|
21 | }
|
---|
22 | }
|
---|
23 | killParents(repro_list);
|
---|
24 | }
|
---|
25 |
|
---|
26 | function reproduce_diploid(repro_list)
|
---|
27 | {
|
---|
28 | for (var i = 0; i < repro_list.size; i++)
|
---|
29 | {
|
---|
30 | var parent = Populations[0].get(repro_list[i]);
|
---|
31 |
|
---|
32 | if (parent.user2["gen"] != 1)
|
---|
33 | {
|
---|
34 | Simulator.print("gen: " + parent.user2["gen"]);
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (parent.user2["gen"] == 1)
|
---|
38 | {
|
---|
39 | var number = parent.user2["Va"] / ExpParams.ofnumh;
|
---|
40 | for (var j = 0; j < number / 2; j++)
|
---|
41 | {
|
---|
42 | var crossed = 0;
|
---|
43 | //crossover
|
---|
44 | if (Math.rnd01 < ExpParams.crossprob)
|
---|
45 | {
|
---|
46 | crossover(parent, "vamin");
|
---|
47 | crossed = 1;
|
---|
48 | }
|
---|
49 |
|
---|
50 | for (var k = 0; k < 2; k++)
|
---|
51 | {
|
---|
52 | createOffspring(ExpParams.genh, ExpParams.ofnumh, {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}, {"Va" : ExpParams.ofnumh, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.ofnumh});
|
---|
53 | }
|
---|
54 |
|
---|
55 | //reverse of crossover for fossilization
|
---|
56 | if (crossed == 1)
|
---|
57 | {
|
---|
58 | crossover(parent, "vamin");
|
---|
59 | crossed = 0;
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | killParents(repro_list);
|
---|
65 | }
|
---|
66 |
|
---|
67 | function crossover(parent, gene)
|
---|
68 | {
|
---|
69 | var tmp = parent.user1[0][gene];
|
---|
70 | parent.user1[0][gene] = parent.user1[1][gene];
|
---|
71 | parent.user1[1][gene] = tmp;
|
---|
72 | }
|
---|
73 |
|
---|
74 | function killParents(repro_list)
|
---|
75 | {
|
---|
76 | for (var j = 0; j < repro_list.size; j++)
|
---|
77 | {
|
---|
78 | Populations[0].kill(repro_list[j]);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | function createOffspring(geno, energy, new_user1, new_user2)
|
---|
83 | {
|
---|
84 | var cr = Populations[0].add(geno);
|
---|
85 | cr.energ0 = energy;
|
---|
86 | cr.energy = cr.energ0;
|
---|
87 | setGenotype(cr, new_user1, new_user2);
|
---|
88 | placeRandomlyNotColliding(cr);
|
---|
89 | }
|
---|
90 |
|
---|
91 | function onStep()
|
---|
92 | {
|
---|
93 | var haploids = 0;
|
---|
94 | var diploids = 0;
|
---|
95 | var e_inc_h = 0.0;
|
---|
96 | var e_inc_d = 0.0;
|
---|
97 | var e_nut = 0.0;
|
---|
98 | var size_h = 0.0;
|
---|
99 | var size_d = 0.0;
|
---|
100 | var vmin_h = 0.0;
|
---|
101 | var vmin_d = 0.0;
|
---|
102 |
|
---|
103 | for (var i = 0; i < Populations[0].size; i++)
|
---|
104 | {
|
---|
105 | var cr = Populations[0].get(i);
|
---|
106 | if (cr.user2["gen"] == 0)
|
---|
107 | {
|
---|
108 | haploids += 1;
|
---|
109 | e_inc_h += cr.energy;
|
---|
110 | size_h += ExpParams.rads[0]; //TODO change of size dependent on gene
|
---|
111 | vmin_h += cr.user1["vamin"];
|
---|
112 | }
|
---|
113 | else if (cr.user2["gen"] == 1)
|
---|
114 | {
|
---|
115 | diploids += 1;
|
---|
116 | e_inc_d += cr.energy;
|
---|
117 | size_d += ExpParams.rads[1]; //TODO change of size dependent on gene
|
---|
118 | vmin_d += cr.user1[0]["vamin"];
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | for (var i = 0; i < Populations[1].size; i++)
|
---|
123 | {
|
---|
124 | var cr = Populations[1].get(i);
|
---|
125 | e_nut += cr.energy;
|
---|
126 | }
|
---|
127 |
|
---|
128 | if (haploids < 2 && diploids == 0)
|
---|
129 | {
|
---|
130 | Simulator.print("no more creatures, stopped.");
|
---|
131 | Simulator.stop();
|
---|
132 | }
|
---|
133 |
|
---|
134 | var l1 = [haploids, diploids, Populations[1].size];
|
---|
135 | var l2 = [e_inc_h, e_inc_d, e_nut];
|
---|
136 | var dp = diploids;
|
---|
137 | var hp = haploids;
|
---|
138 | if (dp == 0) dp = 0.000001;
|
---|
139 | if (hp == 0) hp = 0.000001;
|
---|
140 | var l3 = [size_h / hp, vmin_h / hp, size_d / dp, vmin_d / dp];
|
---|
141 |
|
---|
142 | if (ExpParams.logging == 1)
|
---|
143 | {
|
---|
144 | log(l1, "log.txt");
|
---|
145 | log(l2, "log2.txt");
|
---|
146 | log(l3, "log3.txt");
|
---|
147 | }
|
---|
148 | //food growth ---------------------------------------------
|
---|
149 | foodenergywaiting = foodenergywaiting + ExpParams.feedrate;
|
---|
150 | if (foodenergywaiting > ExpParams.feede0)
|
---|
151 | {
|
---|
152 | for (var i = 0; i < ExpParams.foodPop; i++)
|
---|
153 | {
|
---|
154 | addfood();
|
---|
155 | }
|
---|
156 |
|
---|
157 | foodenergywaiting = 0.0;
|
---|
158 | Simulator.checkpoint();
|
---|
159 | }
|
---|
160 |
|
---|
161 | //reproduction --------------------------------------------
|
---|
162 | reprocounter += 1;
|
---|
163 | if (reprocounter > ExpParams.repro_time)
|
---|
164 | {
|
---|
165 | reprocounter = 0;
|
---|
166 | var to_repro_h = [];
|
---|
167 | var to_repro_d = [];
|
---|
168 | for (var i = 0; i < Populations[0].size; i++)
|
---|
169 | {
|
---|
170 | var cr = Populations[0].get(i);
|
---|
171 | if (cr.signals.size > 0)
|
---|
172 | {
|
---|
173 | if (cr.user2["gen"] == 0)
|
---|
174 | {
|
---|
175 | to_repro_h.add(i);
|
---|
176 | }
|
---|
177 | if (cr.user2["gen"] == 1)
|
---|
178 | {
|
---|
179 | to_repro_d.add(i);
|
---|
180 | }
|
---|
181 | }
|
---|
182 | }
|
---|
183 | if (to_repro_h.size > 1)
|
---|
184 | {
|
---|
185 | reproduce_haploid(to_repro_h);
|
---|
186 | }
|
---|
187 | if (to_repro_d.size > 0)
|
---|
188 | {
|
---|
189 | reproduce_diploid(to_repro_d);
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | //check for death -----------------------------------------------
|
---|
194 | if (Populations[0].size == 0)
|
---|
195 | {
|
---|
196 | if (ExpParams.autorestart)
|
---|
197 | {
|
---|
198 | Simulator.print("no more creatures, restarting...");
|
---|
199 | onExpInit();
|
---|
200 | }
|
---|
201 | else
|
---|
202 | {
|
---|
203 | Simulator.print("no more creatures, stopped.");
|
---|
204 | Simulator.stop();
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | // -------------------------------- step end --------------------------------
|
---|