1 | expdef:
|
---|
2 | name:Reproduction of benthic foraminifera
|
---|
3 | info:~
|
---|
4 | Basic information about this simulation:
|
---|
5 | www.framsticks.com/foraminifera
|
---|
6 |
|
---|
7 | Technical information:
|
---|
8 | Genes and parameter values which control reproduction are stored in user1 and user2 fields.
|
---|
9 |
|
---|
10 | user1:
|
---|
11 | genes which are not encoded in Ff genotype:
|
---|
12 | min_repro_energy - Minimum energy necessary for reproduction
|
---|
13 | hibernation - Defines foram behavior in the case of no nutrients
|
---|
14 |
|
---|
15 | user2:
|
---|
16 | Physiological parameters of foraminifera:
|
---|
17 | max_energy_level - maximum energy level reached so far
|
---|
18 | gen - generation: 0 haploid, 1 diploid
|
---|
19 | species - species: 0 not hibernating 1 hibernating
|
---|
20 | hibernated - 0/1 foram is/isn't hibernated
|
---|
21 | reproduce - 0/1 foram isn't/is ready for reproduction
|
---|
22 | ~
|
---|
23 | code:~
|
---|
24 |
|
---|
25 |
|
---|
26 | global nutrientenergywaiting;
|
---|
27 | global reprocounter;
|
---|
28 | global colors;
|
---|
29 | global chambers;
|
---|
30 | global o;
|
---|
31 | global max_chamber_energ;
|
---|
32 | global dir_change;
|
---|
33 |
|
---|
34 | @include "foraminifera.inc"
|
---|
35 |
|
---|
36 | // -------------------------------- experiment begin --------------------------------
|
---|
37 |
|
---|
38 | function onExpDefLoad()
|
---|
39 | {
|
---|
40 | // define genotype and creature groups
|
---|
41 | GenePools.clear();
|
---|
42 | Populations.clear();
|
---|
43 | GenePools[0].name = "Unused";
|
---|
44 |
|
---|
45 | var pop = Populations[0];
|
---|
46 | pop.name = "Forams";
|
---|
47 | pop.en_assim = 0;
|
---|
48 | pop.nnsim = 0;
|
---|
49 | pop.enableperf = 1;
|
---|
50 | pop.death = 1;
|
---|
51 | pop.energy = 1;
|
---|
52 | pop.selfmask = 0x10001;
|
---|
53 | pop.othermask = 0x20001;
|
---|
54 | //pop.selfmask = 0x20002; pop.othermask = 0x10002;
|
---|
55 | pop.perfperiod = 25;
|
---|
56 |
|
---|
57 | pop = Populations.addGroup("Nutrients");
|
---|
58 | pop.nnsim = 0;
|
---|
59 | pop.enableperf = 0;
|
---|
60 | pop.death = 1;
|
---|
61 | pop.energy = 1;
|
---|
62 | pop.selfmask = 0x20002;
|
---|
63 | pop.othermask = 0x10000;
|
---|
64 | //pop.othermask = 0x10002;
|
---|
65 |
|
---|
66 | pop = Populations.addGroup("ReticulopodiaNutrients");
|
---|
67 | pop.nnsim = 0;
|
---|
68 | pop.enableperf = 0;
|
---|
69 | pop.death = 0;
|
---|
70 | pop.energy = 0;
|
---|
71 | pop.selfmask = 0x20002;
|
---|
72 | pop.othermask = 0x10000;
|
---|
73 |
|
---|
74 | //world
|
---|
75 | SignalView.mode = 1;
|
---|
76 | World.wrldwat = 200;
|
---|
77 | World.wrldsiz = micronsToFrams(40000);
|
---|
78 | World.wrldbnd = 1;
|
---|
79 | ExpParams.stress = 1;
|
---|
80 | ExpParams.creath = -0.99; //just above the bottom
|
---|
81 | ExpParams.autorestart = 0;
|
---|
82 |
|
---|
83 | //ExpParams.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions
|
---|
84 |
|
---|
85 | //ExpParams.logging = 1; //uncomment to enable logging simulation parameters to log files
|
---|
86 |
|
---|
87 | //reproduction
|
---|
88 | ExpParams.foramPop = 10;
|
---|
89 | ExpParams.crossprob = 0.4;
|
---|
90 | ExpParams.mutationprob = 0.2;
|
---|
91 | ExpParams.repro_time = 20;
|
---|
92 | reprocounter = 0;
|
---|
93 |
|
---|
94 | //morphology
|
---|
95 | dir_change = 500;
|
---|
96 | ExpParams.zone1_range = micronsToFrams(3000);
|
---|
97 | ExpParams.zone2_range = micronsToFrams(6000);
|
---|
98 | init_chambers();
|
---|
99 | ExpParams.chamber_proculus_haplo = micronsToFrams(50);
|
---|
100 | ExpParams.chamber_difference_haplo = 0.0;
|
---|
101 | ExpParams.chamber_proculus_diplo = micronsToFrams(20);
|
---|
102 | ExpParams.chamber_difference_diplo = 0.2;
|
---|
103 | max_chamber_energ = [Vector.new(), Vector.new()];
|
---|
104 | for (var j = 0; j < 2; j++)
|
---|
105 | {
|
---|
106 | for (var i = 0; i < chambers[0].size; i++)
|
---|
107 | {
|
---|
108 | max_chamber_energ[j].add(((Math.pow(getProperty(j, "chamber_proculus"),3) + Math.pow(getProperty(j, "chamber_proculus") + (i) * getProperty(j, "chamber_difference"),3))*(i+1))/2);
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | //energetics
|
---|
113 | ExpParams.min_repro_energ_haplo = 4;
|
---|
114 | ExpParams.min_repro_energ_diplo = 6;
|
---|
115 |
|
---|
116 | ExpParams.e_meta = 0.0002;
|
---|
117 | ExpParams.energy_hib = 0.0001;
|
---|
118 | ExpParams.energy_move = 0.00025;
|
---|
119 |
|
---|
120 | ExpParams.energies0_haplo = max_chamber_energ[0][0] - 0.001*max_chamber_energ[0][0];
|
---|
121 | ExpParams.energies0_diplo = max_chamber_energ[1][0] - 0.001*max_chamber_energ[1][0];
|
---|
122 | ExpParams.feedtrans = 0.5;
|
---|
123 | ExpParams.e_repro_cost_haplo = 0.7;
|
---|
124 | ExpParams.e_repro_cost_diplo = 0.3;
|
---|
125 |
|
---|
126 | //nutrients
|
---|
127 | ExpParams.nutrientsize = micronsToFrams(10);
|
---|
128 | ExpParams.energy_nut = 100 * Math.pow(ExpParams.nutrientsize, 3);
|
---|
129 | ExpParams.nutrientPop = 1;
|
---|
130 | ExpParams.feedrate = 0.1;
|
---|
131 | nutrientenergywaiting = ExpParams.energy_nut;
|
---|
132 | ExpState.totaltestedcr = 0;
|
---|
133 | ExpState.nutrient = "";
|
---|
134 | }
|
---|
135 |
|
---|
136 | @include "standard_placement.inc"
|
---|
137 |
|
---|
138 | function micronsToFrams(micrometers)
|
---|
139 | {
|
---|
140 | return micrometers*0.025;
|
---|
141 | }
|
---|
142 |
|
---|
143 | function framsToMicrons(framsworldunits)
|
---|
144 | {
|
---|
145 | return framsworldunits/0.025;
|
---|
146 | }
|
---|
147 |
|
---|
148 | function getProperty(gen, prop_id)
|
---|
149 | {
|
---|
150 | var ploid = "haplo";
|
---|
151 | if (gen == 1) ploid = "diplo";
|
---|
152 | return ExpParams.[prop_id + "_" + ploid];
|
---|
153 | }
|
---|
154 |
|
---|
155 | function addInitialForam(species, i)
|
---|
156 | {
|
---|
157 | var geno = createForamGenotype(0, species, 0);
|
---|
158 | var cr = Populations[0].add(geno);
|
---|
159 | cr.name = "Initial creature" + species + "_" + i;
|
---|
160 | placeCreatureRandomly(cr, 0, 0);
|
---|
161 | cr.energy0 = getProperty(0, "energies0");
|
---|
162 | cr.energy = cr.energy0;
|
---|
163 | setGenotype({"opt" : 0, "cr" : cr, "species" : species});
|
---|
164 | }
|
---|
165 |
|
---|
166 | function onExpInit()
|
---|
167 | {
|
---|
168 | Populations[0].clear();
|
---|
169 | Populations[1].clear();
|
---|
170 | Populations[2].clear(); //reticulopodia and nutrients
|
---|
171 |
|
---|
172 | for (var i = 0; i < ExpParams.foramPop; i++)
|
---|
173 | {
|
---|
174 | addInitialForam(0, i);
|
---|
175 | addInitialForam(1, i);
|
---|
176 | }
|
---|
177 | o = Populations[0][0].getMechPart(0).orient.clone();
|
---|
178 | ExpState.totaltestedcr = 0;
|
---|
179 | nutrientenergywaiting = ExpParams.energy_nut;
|
---|
180 | }
|
---|
181 |
|
---|
182 | function onExpLoad()
|
---|
183 | {
|
---|
184 | for (var pop in Populations)
|
---|
185 | pop.clear();
|
---|
186 |
|
---|
187 | Loader.addClass(sim_params.*);
|
---|
188 | Loader.setBreakLabel(Loader.BeforeUnknown, "onExpLoad_Unknown");
|
---|
189 | Loader.run();
|
---|
190 |
|
---|
191 | Simulator.print("Loaded " + Populations[0].size + " Forams and " + Populations[1].size + " nutrient objects");
|
---|
192 | }
|
---|
193 |
|
---|
194 | function onExpLoad_Unknown()
|
---|
195 | {
|
---|
196 | if (Loader.objectName == "org") // saved by the old expdef
|
---|
197 | {
|
---|
198 | var g = Genotype.newFromString("");
|
---|
199 | Loader.currentObject = g;
|
---|
200 | Interface.makeFrom(g).setAllDefault();
|
---|
201 | Loader.loadObject();
|
---|
202 | var cr = Populations[0].add(g);
|
---|
203 | if (cr != null)
|
---|
204 | {
|
---|
205 | //cr.rotate(0,0,Math.rnd01*Math.twopi);
|
---|
206 | if ((typeof(g.user1) == "Vector") && (g.user1.size >= 3))
|
---|
207 | {
|
---|
208 | // [x,y,energy]
|
---|
209 | cr.move(g.user1[0] - cr.center_x, g.user1[1] - cr.center_y, 0);
|
---|
210 | cr.energy = g.user1[2];
|
---|
211 | }
|
---|
212 | else
|
---|
213 | {
|
---|
214 | cr.move(Math.rnd01 * World.wrldsiz - cr.center_x, Math.rnd01 * World.wrldsiz - cr.center_y, 0);
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 | else if (Loader.objectName == "Creature")
|
---|
219 | {
|
---|
220 | Loader.currentObject = CreatureSnapshot.new();
|
---|
221 | Loader.loadObject();
|
---|
222 | Populations[0].add(Loader.currentObject);
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | function onExpSave()
|
---|
227 | {
|
---|
228 | File.writeComment("saved by '%s.expdef'" % Simulator.expdef);
|
---|
229 |
|
---|
230 | var tmpvec = [], i;
|
---|
231 |
|
---|
232 | for(var cr in Populations[1])
|
---|
233 | tmpvec.add([cr.center_x, cr.center_y, cr.energy]);
|
---|
234 |
|
---|
235 | ExpState.nutrient = tmpvec;
|
---|
236 | File.writeObject(sim_params.*);
|
---|
237 | ExpState.nutrient = null; //vectors are only created for saving and then discarded
|
---|
238 |
|
---|
239 | for (var cr in Populations[0])
|
---|
240 | File.writeObject(cr);
|
---|
241 | }
|
---|
242 |
|
---|
243 | // -------------------------------- experiment end --------------------------------
|
---|
244 |
|
---|
245 | // -------------------------------- foram begin -----------------------------------
|
---|
246 |
|
---|
247 | function setForamMeta(cr, gen)
|
---|
248 | {
|
---|
249 | cr.idleen = ExpParams.e_meta * max_chamber_energ[gen][Math.min(lastChamberNum(cr), max_chamber_energ[gen].size-1)];
|
---|
250 | }
|
---|
251 |
|
---|
252 | function lastChamberNum(cr)
|
---|
253 | {
|
---|
254 | return cr.numparts-1;
|
---|
255 | }
|
---|
256 |
|
---|
257 | function onForamsBorn(cr)
|
---|
258 | {
|
---|
259 | setForamMeta(cr, 1);
|
---|
260 | if (ExpParams.visualize == 1)
|
---|
261 | {
|
---|
262 | var ret = Populations[2].add("//0\np:sh=3,sx=0.01,sy="+ExpParams.zone1_range+",sz="+ExpParams.zone1_range+",ry=1.57,vr=1.0,1.0,1.0");
|
---|
263 | cr.user3 = ret;
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | function placeRandomlyNotColliding(cr)
|
---|
268 | {
|
---|
269 | var retry = 100; //try 100 times
|
---|
270 | while (retry--)
|
---|
271 | {
|
---|
272 | placeCreatureRandomly(cr, 0, 0);
|
---|
273 | if (!cr.boundingBoxCollisions(0))
|
---|
274 | return cr;
|
---|
275 | }
|
---|
276 |
|
---|
277 | Populations[0].delete(cr);
|
---|
278 | }
|
---|
279 |
|
---|
280 | function visualization(cr)
|
---|
281 | {
|
---|
282 | var has_ret = 0;
|
---|
283 |
|
---|
284 | if (cr.user3 != null)
|
---|
285 | {
|
---|
286 | if (Populations[2].findUID(cr.user3.uid) != null)
|
---|
287 | {
|
---|
288 | has_ret = 1;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | return has_ret;
|
---|
293 | }
|
---|
294 |
|
---|
295 | function foramGrow(cr, chamber_num)
|
---|
296 | {
|
---|
297 | var geno = createForamGenotype(cr.user2["gen"], cr.user2["species"], chamber_num+1);
|
---|
298 | var cr2 = Populations[0].add(geno);
|
---|
299 |
|
---|
300 | cr2.energy0 = cr.energy;
|
---|
301 | cr2.energy = cr2.energy0;
|
---|
302 |
|
---|
303 | setGenotype({"cr" : cr2, "parent_user1" : cr.user1, "parent_user2" : cr.user2, "opt" : 2});
|
---|
304 | cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
|
---|
305 | setForamMeta(cr2, cr2.user2["gen"]);
|
---|
306 |
|
---|
307 | if (visualization(cr))
|
---|
308 | {
|
---|
309 | Populations[2].delete(cr.user3);
|
---|
310 | }
|
---|
311 | Populations[0].delete(cr);
|
---|
312 | }
|
---|
313 |
|
---|
314 | function stepToNearest(cr)
|
---|
315 | {
|
---|
316 | var p = cr.getMechPart(0);
|
---|
317 | var n = cr.signals.receiveSet("nutrient", ExpParams.zone2_range);
|
---|
318 |
|
---|
319 | //if signals are received find the source of the nearest
|
---|
320 | if (n.size > 0)
|
---|
321 | {
|
---|
322 | var i;
|
---|
323 | var mp;
|
---|
324 | var distvec = XYZ.new(0, 0, 0);
|
---|
325 | var dist;
|
---|
326 | var mindist = 100000000000;
|
---|
327 | var mindistvec = null;
|
---|
328 | var eating = 0;
|
---|
329 |
|
---|
330 | for (i = 0; i < n.size; i++)
|
---|
331 | {
|
---|
332 | mp = n[i].value.getMechPart(0);
|
---|
333 | distvec.set(mp.pos);
|
---|
334 | distvec.sub(p.pos);
|
---|
335 | dist = distvec.length;
|
---|
336 | if (dist < ExpParams.zone1_range)
|
---|
337 | {
|
---|
338 | if (n[i].value != null)
|
---|
339 | {
|
---|
340 | energyTransfer(cr, n[i].value);
|
---|
341 | eating = 1;
|
---|
342 | }
|
---|
343 | }
|
---|
344 | else if (eating == 0 && cr.user2["hibernated"] == 0 && dist < mindist)
|
---|
345 | {
|
---|
346 | mindist = dist;
|
---|
347 | mindistvec = distvec.clone();
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | if (!eating && cr.user2["hibernated"] == 0)
|
---|
352 | {
|
---|
353 | mindistvec.normalize();
|
---|
354 | mindistvec.scale(-0.08);
|
---|
355 | cr.localDrive = mindistvec;
|
---|
356 | moveEnergyDec(cr);
|
---|
357 | }
|
---|
358 |
|
---|
359 | return 1;
|
---|
360 | }
|
---|
361 |
|
---|
362 | else
|
---|
363 | return 0;
|
---|
364 | }
|
---|
365 |
|
---|
366 | function moveEnergyDec(cr)
|
---|
367 | {
|
---|
368 | if (cr.user2["hibernated"] == 0)
|
---|
369 | {
|
---|
370 | cr.energy_m += ExpParams.energy_move * max_chamber_energ[cr.user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)];
|
---|
371 | }
|
---|
372 | }
|
---|
373 |
|
---|
374 | function foramMove(cr)
|
---|
375 | {
|
---|
376 | //TODO moving inside sediment?
|
---|
377 |
|
---|
378 | //adjustment in z axis
|
---|
379 | cr.moveAbs(cr.pos_x, cr.pos_y, 0);
|
---|
380 |
|
---|
381 | //are there any nutrients in zone 1 or 2?
|
---|
382 | {
|
---|
383 | var moved = stepToNearest(cr); //TODO weighted sum of distance and energy
|
---|
384 | if (moved==1)
|
---|
385 | {
|
---|
386 | return;
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | //no nutrients in zone 2
|
---|
391 | var hibernation = 0;
|
---|
392 | if (cr.user2["gen"] == 0) hibernation = cr.user1["hibernation"];
|
---|
393 | else hibernation = cr.user1[0]["hibernation"];
|
---|
394 | //hibernation
|
---|
395 | if (hibernation == 1)
|
---|
396 | {
|
---|
397 | reverseHib(cr);
|
---|
398 | cr.localDrive = XYZ.new(0,0,0);
|
---|
399 | }
|
---|
400 | //random move
|
---|
401 | else if (cr.lifespan%dir_change == 0)
|
---|
402 | {
|
---|
403 | var dir = (Math.rndUni(-ExpParams.zone2_range, ExpParams.zone2_range), Math.rndUni(-ExpParams.zone2_range, ExpParams.zone2_range), 0);
|
---|
404 | dir.normalize();
|
---|
405 | dir.scale(-0.08);
|
---|
406 | cr.localDrive = dir;
|
---|
407 | moveEnergyDec(cr);
|
---|
408 | }
|
---|
409 | }
|
---|
410 |
|
---|
411 | function energyTransfer(cr1, cr2)
|
---|
412 | {
|
---|
413 | cr1.localDrive = XYZ.new(0,0,0);
|
---|
414 | var e = cr2.getPart(0).ing * ExpParams.feedtrans; //TODO efficiency dependent on age
|
---|
415 | e = Math.min(cr2.energy, e) + 0.0000001;
|
---|
416 | //Simulator.print("transferring "+e+" to "+cr1.name+" from "+cr2.name+" ("+cr2.energy+")");
|
---|
417 | cr2.energy_m = cr2.energy_m + e;
|
---|
418 | cr1.energy_p = cr1.energy_p + e;
|
---|
419 | if (cr1.user2["hibernated"] == 1)
|
---|
420 | {
|
---|
421 | reverseHib(cr1);
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | function reverseHib(cr)
|
---|
426 | {
|
---|
427 | if (cr.user2["hibernated"] == 1)
|
---|
428 | {
|
---|
429 | setForamMeta(cr, cr.user2["gen"]); //unhibernate
|
---|
430 | }
|
---|
431 | else
|
---|
432 | {
|
---|
433 | cr.idleen = ExpParams.energy_hib * max_chamber_energ[cr.user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)]; //hibernate
|
---|
434 | }
|
---|
435 | cr.user2["hibernated"] = 1 - cr.user2["hibernated"];
|
---|
436 | }
|
---|
437 |
|
---|
438 | function onForamsStep(cr)
|
---|
439 | {
|
---|
440 | cr.getMechPart(0).orient.set(o);
|
---|
441 | if (visualization(cr))
|
---|
442 | {
|
---|
443 | cr.user3.moveAbs(cr.center_x-ExpParams.zone1_range, cr.center_y-ExpParams.zone1_range, cr.center_z-ExpParams.zone1_range-getProperty(cr.user2["gen"], "chamber_proculus"));
|
---|
444 | }
|
---|
445 |
|
---|
446 | if (deathConditions(cr) == 1)
|
---|
447 | {
|
---|
448 | Populations[0].kill(cr);
|
---|
449 | return;
|
---|
450 | }
|
---|
451 |
|
---|
452 | foramMove(cr);
|
---|
453 |
|
---|
454 | var repro = foramReproduce(cr);
|
---|
455 | if (repro == 1)
|
---|
456 | {
|
---|
457 | return;
|
---|
458 | }
|
---|
459 |
|
---|
460 | cr.user2["max_energy_level"] = Math.max(cr.energy, cr.user2["max_energy_level"]);
|
---|
461 | if (lastChamberNum(cr) <= chambers[0].size-1)
|
---|
462 | {
|
---|
463 | if ((cr.user2["max_energy_level"] >= max_chamber_energ[cr.user2["gen"]][lastChamberNum(cr)]))
|
---|
464 | {
|
---|
465 | foramGrow(cr, lastChamberNum(cr));
|
---|
466 | }
|
---|
467 | }
|
---|
468 | }
|
---|
469 |
|
---|
470 | function deathConditions(cr)
|
---|
471 | {
|
---|
472 | if ((cr.energy <= ExpParams.e_death_level) || (Math.rnd01 < ExpParams.hunted_prob))
|
---|
473 | return 1;
|
---|
474 | else
|
---|
475 | return 0;
|
---|
476 | }
|
---|
477 |
|
---|
478 | function onForamsDied(cr)
|
---|
479 | {
|
---|
480 | if (visualization(cr))
|
---|
481 | {
|
---|
482 | Populations[2].delete(cr.user3);
|
---|
483 | }
|
---|
484 | //fossilization
|
---|
485 | var geno = GenePools[0].add(cr.genotype);
|
---|
486 | geno.user1 = cr.user1;
|
---|
487 | geno.user2 = cr.user2;
|
---|
488 | if (ExpParams.logging == 1) Simulator.print("\"" + cr.name + "\" died...");
|
---|
489 | ExpState.totaltestedcr++;
|
---|
490 | }
|
---|
491 |
|
---|
492 | // --------------------------------foram end -------------------------------------
|
---|
493 |
|
---|
494 | // -------------------------------- nutrient begin --------------------------------
|
---|
495 |
|
---|
496 | function createNutrientGenotype(nutrientsize, zone1_range)
|
---|
497 | {
|
---|
498 | return "//0\np:sh=3,sx="+nutrientsize+",sy="+nutrientsize+",sz="+nutrientsize+",ry=1.5,vr=0.0,1.0,0.0";
|
---|
499 | }
|
---|
500 |
|
---|
501 | function onNutrientsStep(cr)
|
---|
502 | {
|
---|
503 | cr.moveAbs(cr.pos_x % World.wrldsiz, cr.pos_y % World.wrldsiz, 0.5);
|
---|
504 | }
|
---|
505 |
|
---|
506 | function addNutrient()
|
---|
507 | {
|
---|
508 | var cr = Populations[1].add(createNutrientGenotype(ExpParams.nutrientsize, ExpParams.zone1_range));
|
---|
509 |
|
---|
510 | cr.name = "Nutrients";
|
---|
511 | cr.idleen = 0;
|
---|
512 | cr.energy0 = ExpParams.energy_nut;
|
---|
513 | cr.energy = cr.energy0;
|
---|
514 | cr.signals.add("nutrient");
|
---|
515 |
|
---|
516 | cr.signals[0].value = cr;
|
---|
517 |
|
---|
518 | placeCreatureRandomly(cr, 0, 0);
|
---|
519 | if (ExpParams.visualize == 1)
|
---|
520 | {
|
---|
521 | var nutsize = ExpParams.nutrientsize*10;
|
---|
522 | var nut = Populations[2].add("//0\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0");
|
---|
523 | cr.user3 = nut;
|
---|
524 | nut.moveAbs(cr.pos_x-1.5*nutsize, cr.pos_y-1.5*nutsize, 0.5);
|
---|
525 | }
|
---|
526 | }
|
---|
527 |
|
---|
528 | function onNutrientsDied(cr)
|
---|
529 | {
|
---|
530 | if (visualization(cr))
|
---|
531 | {
|
---|
532 | Populations[2].delete(cr.user3);
|
---|
533 | }
|
---|
534 | }
|
---|
535 |
|
---|
536 | function nutrientGrowth()
|
---|
537 | {
|
---|
538 | nutrientenergywaiting = nutrientenergywaiting + ExpParams.feedrate;
|
---|
539 | if (nutrientenergywaiting > ExpParams.energy_nut)
|
---|
540 | {
|
---|
541 | for (var i = 0; i < ExpParams.nutrientPop; i++)
|
---|
542 | {
|
---|
543 | addNutrient();
|
---|
544 | }
|
---|
545 |
|
---|
546 | nutrientenergywaiting = 0.0;
|
---|
547 | Simulator.checkpoint();
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | // -------------------------------- nutrient end --------------------------------
|
---|
552 |
|
---|
553 | // -------------------------------- step begin --------------------------------
|
---|
554 |
|
---|
555 | function onStep()
|
---|
556 | {
|
---|
557 |
|
---|
558 | nutrientGrowth();
|
---|
559 | if (ExpParams.logging == 1)
|
---|
560 | {
|
---|
561 | createStatistics();
|
---|
562 | }
|
---|
563 |
|
---|
564 | //reproduction --------------------------------------------
|
---|
565 | reprocounter += 1;
|
---|
566 | if (reprocounter > ExpParams.repro_time)
|
---|
567 | {
|
---|
568 | reprocounter = 0;
|
---|
569 | reproduce_parents(0);
|
---|
570 | reproduce_parents(1);
|
---|
571 | }
|
---|
572 |
|
---|
573 | //check for extinction -----------------------------------------------
|
---|
574 | if (Populations[0].size == 0)
|
---|
575 | {
|
---|
576 | if (ExpParams.autorestart)
|
---|
577 | {
|
---|
578 | Simulator.print("no more creatures, restarting...");
|
---|
579 | onExpInit();
|
---|
580 | }
|
---|
581 | else
|
---|
582 | {
|
---|
583 | Simulator.print("no more creatures, stopped.");
|
---|
584 | Simulator.stop();
|
---|
585 | }
|
---|
586 | }
|
---|
587 | if (ExpParams.maxSteps > 0)
|
---|
588 | {
|
---|
589 | if (Simulator.stepNumber >= ExpParams.maxSteps)
|
---|
590 | Simulator.stop();
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|
594 | function createStatistics()
|
---|
595 | {
|
---|
596 | var number = [[0, 0],[0,0]]; // [species][gen]
|
---|
597 | var e_inc = [[0, 0],[0,0]];
|
---|
598 | var e_nut = 0.0;
|
---|
599 |
|
---|
600 | for (var i = 0; i < Populations[0].size; i++)
|
---|
601 | {
|
---|
602 | var cr = Populations[0].get(i);
|
---|
603 | var gen = cr.user2["gen"];
|
---|
604 | var species = cr.user2["species"];
|
---|
605 |
|
---|
606 | number[species][gen] = number[species][gen] + 1;
|
---|
607 | e_inc[species][gen] = e_inc[species][gen] + cr.energy;
|
---|
608 | }
|
---|
609 |
|
---|
610 | for (var i = 0; i < Populations[1].size; i++)
|
---|
611 | {
|
---|
612 | var cr = Populations[1].get(i);
|
---|
613 | e_nut += cr.energy;
|
---|
614 | }
|
---|
615 |
|
---|
616 | var log_numbers = [number[1][0], number[1][1], number[0][0], number[0][1], Populations[1].size];
|
---|
617 | var log_energies = [e_inc[1][0], e_inc[1][1], e_inc[0][0], e_inc[0][1], e_nut];
|
---|
618 |
|
---|
619 | log(log_numbers, "forams_log.txt");
|
---|
620 | log(log_energies, "energies_log.txt");
|
---|
621 | }
|
---|
622 |
|
---|
623 | function log(tolog, fname)
|
---|
624 | {
|
---|
625 | var f = File.appendDirect(fname, "forams data");
|
---|
626 | f.writeString("" + Simulator.stepNumber);
|
---|
627 | for (var i = 0; i < tolog.size; i++)
|
---|
628 | {
|
---|
629 | f.writeString(";" + tolog[i]);
|
---|
630 | }
|
---|
631 | f.writeString("\n");
|
---|
632 | f.close();
|
---|
633 | }
|
---|
634 |
|
---|
635 | // -------------------------------- step end --------------------------------
|
---|
636 |
|
---|
637 | @include "standard_events.inc"
|
---|
638 |
|
---|
639 | ~
|
---|
640 |
|
---|
641 | prop:
|
---|
642 | id:visualize
|
---|
643 | name:Show reticulopodia and nutrients
|
---|
644 | type:d 0 1 0
|
---|
645 | group:Foraminifera
|
---|
646 |
|
---|
647 | prop:
|
---|
648 | id:maxSteps
|
---|
649 | name:Stop after the given number of simulation steps
|
---|
650 | type:d 0 1000000 0
|
---|
651 |
|
---|
652 | prop:
|
---|
653 | id:e_repro_cost_haplo
|
---|
654 | name:Cost of reproduction
|
---|
655 | type:f 0.1 0.9 0.5
|
---|
656 | group:Foraminifera
|
---|
657 |
|
---|
658 | prop:
|
---|
659 | id:e_repro_cost_diplo
|
---|
660 | name:Cost of reproduction
|
---|
661 | type:f 0.1 0.9 0.3
|
---|
662 | group:Foraminifera
|
---|
663 |
|
---|
664 | prop:
|
---|
665 | id:chamber_proculus_haplo
|
---|
666 | name:Size of proculus
|
---|
667 | type:f
|
---|
668 | group:Foraminifera
|
---|
669 |
|
---|
670 | prop:
|
---|
671 | id:chamber_proculus_diplo
|
---|
672 | name:Size of proculus
|
---|
673 | type:f
|
---|
674 | group:Foraminifera
|
---|
675 |
|
---|
676 | prop:
|
---|
677 | id:chamber_difference_haplo
|
---|
678 | name:Difference in size between subsequent chambers
|
---|
679 | type:f
|
---|
680 | group:Foraminifera
|
---|
681 |
|
---|
682 | prop:
|
---|
683 | id:chamber_difference_diplo
|
---|
684 | name:Difference in size between subsequent chambers
|
---|
685 | type:f
|
---|
686 | group:Foraminifera
|
---|
687 |
|
---|
688 | prop:
|
---|
689 | id:hunted_prob
|
---|
690 | name:Probability of being hunted
|
---|
691 | type:f 0 1 0
|
---|
692 | group:Forminifera
|
---|
693 |
|
---|
694 | prop:
|
---|
695 | id:zone1_range
|
---|
696 | name:Zone 1 range
|
---|
697 | type:f 0 200
|
---|
698 | group:Foraminifera
|
---|
699 |
|
---|
700 | prop:
|
---|
701 | id:zone2_range
|
---|
702 | name:Zone 2 range
|
---|
703 | type:f 0 3000
|
---|
704 | group:Foraminifera
|
---|
705 |
|
---|
706 | prop:
|
---|
707 | id:colors
|
---|
708 | name:Haploid and diploid colors
|
---|
709 | type:x
|
---|
710 | group:Foraminifera
|
---|
711 |
|
---|
712 | prop:
|
---|
713 | id:min_repro_energ_haplo
|
---|
714 | name:Min reproduction energy of forams
|
---|
715 | type:f
|
---|
716 | group:Foraminifera
|
---|
717 |
|
---|
718 | prop:
|
---|
719 | id:min_repro_energ_diplo
|
---|
720 | name:Min reproduction energy of forams
|
---|
721 | type:f
|
---|
722 | group:Foraminifera
|
---|
723 |
|
---|
724 | prop:
|
---|
725 | id:repro_prob
|
---|
726 | name:Probability of reproduction
|
---|
727 | type:f 0 1 0.8
|
---|
728 | group:Foraminifera
|
---|
729 |
|
---|
730 | prop:
|
---|
731 | id:energies0_haplo
|
---|
732 | name:Energy of offspring from diploid forams
|
---|
733 | type:f
|
---|
734 | group:Foraminifera
|
---|
735 |
|
---|
736 | prop:
|
---|
737 | id:energies0_diplo
|
---|
738 | name:Energy of offspring from diploid forams
|
---|
739 | type:f
|
---|
740 | group:Foraminifera
|
---|
741 |
|
---|
742 | prop:
|
---|
743 | id:energy_hib
|
---|
744 | name:Energy used for hibernation during one step
|
---|
745 | type:f 0 1 0.001
|
---|
746 | group:Foraminifera
|
---|
747 |
|
---|
748 | prop:
|
---|
749 | id:energy_move
|
---|
750 | name:Energy used for movement during one step
|
---|
751 | type:f 0 20 0.001
|
---|
752 | group:Foraminifera
|
---|
753 |
|
---|
754 | prop:
|
---|
755 | id:min_vol
|
---|
756 | name:Minimal volume for reproduction
|
---|
757 | type:f 100 900 100
|
---|
758 | group:Foraminifera
|
---|
759 |
|
---|
760 | prop:
|
---|
761 | id:max_size
|
---|
762 | name:Maximal size
|
---|
763 | type:d 1 10 5
|
---|
764 | group:Foraminifera
|
---|
765 |
|
---|
766 | prop:
|
---|
767 | id:foramPop
|
---|
768 | name:Initial forams population size
|
---|
769 | type:d 1 1000 100
|
---|
770 | group:Foraminifera
|
---|
771 |
|
---|
772 | prop:
|
---|
773 | id:crossprob
|
---|
774 | name:Crossover probability
|
---|
775 | type:f 0 1 0
|
---|
776 | group:Foraminifera
|
---|
777 |
|
---|
778 | prop:
|
---|
779 | id:mutationprob
|
---|
780 | name:Mutation probability
|
---|
781 | type:f 0 1 0
|
---|
782 | group:Foraminifera
|
---|
783 |
|
---|
784 | prop:
|
---|
785 | id:e_death_level
|
---|
786 | name:Minimal level of energy to sustain life
|
---|
787 | type:f 0 20 0
|
---|
788 | group:Foraminifera
|
---|
789 |
|
---|
790 | prop:
|
---|
791 | id:e_meta
|
---|
792 | name:Idle metabolism
|
---|
793 | type:f 0 1
|
---|
794 | group:Energy
|
---|
795 | help:Each stick consumes this amount of energy in one time step
|
---|
796 |
|
---|
797 | prop:
|
---|
798 | id:feedrate
|
---|
799 | name:Feeding rate
|
---|
800 | type:f 0 100
|
---|
801 | group:Energy
|
---|
802 | help:How fast energy is created in the world
|
---|
803 |
|
---|
804 | prop:
|
---|
805 | id:energy_nut
|
---|
806 | name:Nutrient energy
|
---|
807 | type:f 0 1000
|
---|
808 | group:Energy
|
---|
809 |
|
---|
810 | prop:
|
---|
811 | id:feedtrans
|
---|
812 | name:Ingestion multiplier
|
---|
813 | type:f 0 100
|
---|
814 | group:Energy
|
---|
815 |
|
---|
816 | prop:
|
---|
817 | id:nutrientsize
|
---|
818 | name:Nutrient size
|
---|
819 | type:f 0.1 0.9 0.1
|
---|
820 | group:Energy
|
---|
821 |
|
---|
822 | prop:
|
---|
823 | id:nutrientPop
|
---|
824 | name:Nutrient population size
|
---|
825 | group:Energy
|
---|
826 | type:d 1 1000 10
|
---|
827 |
|
---|
828 | prop:
|
---|
829 | id:stress
|
---|
830 | name:Environmental stress
|
---|
831 | type:d 0 1 1
|
---|
832 | group:World
|
---|
833 |
|
---|
834 | prop:
|
---|
835 | id:repro_trigger
|
---|
836 | name:Reproduction trigger
|
---|
837 | type:d 0 1 1
|
---|
838 | group:World
|
---|
839 |
|
---|
840 | prop:
|
---|
841 | id:repro_time
|
---|
842 | name:Time before reproduction
|
---|
843 | type:d 0 1000
|
---|
844 |
|
---|
845 | prop:
|
---|
846 | id:creath
|
---|
847 | name:Creation height
|
---|
848 | type:f -1 50
|
---|
849 | help:~
|
---|
850 | Vertical position (above the surface) where new Forams are revived.
|
---|
851 | Negative values are only used in the water area:
|
---|
852 | 0 = at the surface
|
---|
853 | -0.5 = half depth
|
---|
854 | -1 = just above the bottom~
|
---|
855 |
|
---|
856 | state:
|
---|
857 | id:nutrient
|
---|
858 | name:Nutrient locations
|
---|
859 | help:vector of vectors [x,y,energy]
|
---|
860 | type:x
|
---|
861 | flags:32
|
---|
862 |
|
---|
863 | prop:
|
---|
864 | id:autorestart
|
---|
865 | name:Restart after extinction
|
---|
866 | help:Restart automatically this experiment after the last creature has died?
|
---|
867 | type:d 0 1
|
---|
868 |
|
---|
869 | state:
|
---|
870 | id:notes
|
---|
871 | name:Notes
|
---|
872 | type:s 1
|
---|
873 | help:~
|
---|
874 | You can write anything here
|
---|
875 | (it will be saved to the experiment file)~
|
---|
876 |
|
---|
877 | state:
|
---|
878 | id:totaltestedcr
|
---|
879 | name:Evaluated Forams
|
---|
880 | help:Total number of the Forams evaluated in the experiment
|
---|
881 | type:d
|
---|
882 | flags:16
|
---|
883 |
|
---|
884 | prop:
|
---|
885 | id:logging
|
---|
886 | name:Log statistics to file
|
---|
887 | type:d 0 1 0
|
---|