source: experiments/frams/foraminifera/data/scripts/foraminifera.expdef @ 564

Last change on this file since 564 was 561, checked in by Maciej Komosinski, 8 years ago

7% chamber growth instead of 5%; tighter spiral in morphology

File size: 27.0 KB
Line 
1expdef:
2name:Reproduction of benthic foraminifera
3info:~
4Basic information about this simulation:
5www.framsticks.com/foraminifera
6
7Technical information:
8Genes and parameter values which control reproduction are stored in data->genes and data->lifeparams fields.
9
10genes:
11genes which are not encoded in Ff genotype:
12min_repro_energy - Minimum energy necessary for reproduction
13hibernation - Defines foram behavior in the case of no nutrients
14
15lifeparams:
16Physiological parameters of foraminifera:
17max_energy_level - maximum energy level reached so far
18gen - generation: 0 haploid, 1 diploid
19species - species: 0 not hibernating 1 hibernating
20hibernated - 0/1 foram is/isn't hibernated
21reproduce - 0/1 foram isn't/is ready for reproduction
22~
23code:~
24
25global chambers;
26global colors;
27global retColors;
28global curColor;
29global max_chamber_volume;
30global movePerStep;
31global nutrientenergywaiting;
32global o;
33global reprocounter;
34global changePeriod;
35global phase;
36global nutrientSqrCm;
37global species_genes;
38
39@include "foraminifera.inc"
40
41// -------------------------------- experiment begin --------------------------------
42
43function onExpDefLoad()
44{
45        // define genotype and creature groups
46        GenePools.clear();
47        Populations.clear();
48        GenePools[0].name = "Unused";
49
50        var pop = Populations[0];
51        pop.name = "Forams";
52        pop.en_assim = 0;
53        pop.nnsim = 0;
54        pop.enableperf = 1;
55        pop.death = 1;
56        pop.energy = 1;
57        pop.selfmask = 0;
58        pop.othermask = 0;
59        //pop.selfmask = 0x20002; pop.othermask = 0x10002;
60        pop.perfperiod = 25;
61        pop.bodysim = 0;
62
63        pop = Populations.addGroup("Nutrients");
64        pop.nnsim = 0;
65        pop.enableperf = 0;
66        pop.death = 1;
67        pop.energy = 1;
68        pop.selfmask = 0;
69        pop.othermask = 0;
70        //pop.othermask = 0x10002;
71        pop.bodysim = 0;
72
73        pop = Populations.addGroup("ReticulopodiaNutrients");
74        pop.nnsim = 0;
75        pop.enableperf = 0;
76        pop.death = 0;
77        pop.energy = 0;
78        pop.selfmask = 0;
79        pop.othermask = 0;
80        pop.bodysim = 0;
81
82        //world
83        SignalView.mode = 1;
84        World.wrldwat = 200;
85        World.wrldsiz = micronsToFrams(100000);
86        World.wrldbnd = 1;
87
88        movePerStep = getMovePerStep();
89
90        //ExpProperties.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions
91
92        //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files   
93        ExpProperties.logPref = "";
94
95        species_genes = [];
96
97        //morphology
98        init_chambers();
99        curColor = retColors[0];
100        ExpProperties.zone1_range = micronsToFrams(1000);
101        ExpProperties.zone2_range = micronsToFrams(3000);
102        ExpProperties.chamber_proculus_haplo = micronsToFrams(50);
103        ExpProperties.chamber_difference_haplo = 0.0;
104        ExpProperties.chamber_proculus_diplo = micronsToFrams(20);
105        ExpProperties.chamber_difference_diplo = micronsToFrams(8);
106
107        max_chamber_volume = [Vector.new(), Vector.new()];
108        for (var j = 0; j < 2; j++)
109        {
110                for (var i = 0; i < chambers[0].size; i++)
111                {
112                        max_chamber_volume[j].add(((volumeInMicrons(getProperty(j, "chamber_proculus")) + volumeInMicrons(getProperty(j, "chamber_proculus") + (i) * getProperty(j, "chamber_difference")))*(i+1))/2); 
113                }                                 
114        }
115
116        //nutrients
117        ExpProperties.nutrientradius = micronsToFrams(10);
118        ExpProperties.energy_nut = 200 * energyFromVolume(ExpProperties.nutrientradius,1);
119        nutrientSqrCm = 10;
120        ExpProperties.nutrient_pop = Math.pow(framsToMicrons(World.wrldsiz)*0.0001,2)/nutrientSqrCm;
121
122        ExpState.totaltestedcr = 0;
123        ExpState.nutrient = "";
124       
125        //addSpecies({"min_repro_energies" : [4,6]});
126        //addSpecies({"min_repro_energies" : [4,8]});
127       
128        //Simulator.print(create_genotype(0.2, 30, "1.0,1.0,0.0", 0.6)); //sample call
129        //Simulator.print(create_genotype(0.1, 40, "1.0,0.5,0.0", 0.1)); //sample call
130}
131
132@include "standard_placement.inc"
133
134function secToSimSteps(value_in_sec){
135        return value_in_sec/ExpProperties.secPerStep;
136}
137
138function volumeInMicrons(radiusInFrams)
139{
140        return 4.0/3.0*Math.pi*Math.pow(framsToMicrons(radiusInFrams),3);
141}
142
143function energyFromVolume(base, isRadiusInFrams)
144{
145        if (isRadiusInFrams == 1) //radius in frams
146        {
147                return ExpProperties.picoCarbonPerMikro*volumeInMicrons(base);
148        }
149        else //volume in microns
150        {
151                return ExpProperties.picoCarbonPerMikro * base;
152        }
153}
154
155function getMovePerStep()
156{
157        return micronsToFrams((ExpProperties.foramSpeedMmPerMin/60)*1000)*ExpProperties.secPerStep;
158}
159
160function micronsToFrams(micrometers)
161{
162        return micrometers*0.01;
163}
164
165function framsToMicrons(framsworldunits)
166{
167        return framsworldunits/0.01;
168}
169
170function getProperty(gen, prop_id)
171{
172        var ploid = "haplo";
173        if (gen == 1) ploid = "diplo";
174        return ExpProperties.[prop_id + "_" + ploid];
175}
176
177function getGene(cr, gen_id, gen_set)
178{
179        if (cr.data->lifeparams->gen == 0)
180                return cr.data->genes[gen_id];
181        else
182                return cr.data->genes[gen_set][gen_id];
183}
184
185function addForam(species, iter, chambernum, ploid)
186{
187        var geno = createForamMorphology(ploid, ploid, chambernum);
188        curColor = retColors[ploid];
189        var cr = Populations[0].add(geno);
190        cr.name = "Initial creature" + species + "_" + iter;
191        placeCreatureRandomly(cr, 0, 0);
192        cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0);
193        cr.energy = cr.energy0;
194        setGenotype({"opt" : "birth", "cr" : cr, "gen" : ploid, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]});
195        if (ploid == 1)
196        {
197                cr.data->genes = [cr.data->genes, cr.data->genes]; //TODO two different genes sets
198        }
199        moveReticulopodia(cr);
200}
201
202function addInitialForam(species, iter)
203{
204        var ploid = 0;
205        if (Math.rnd01 > 0.5)
206        {
207                ploid = 1;
208        }       
209        //add new foram with random energy bewtween starting energy and reproduction threshold
210        addForam(species, iter, int(Math.rndUni(0,species_genes[species]->min_repro_energies[ploid])),ploid);
211}
212
213//new species can be added as a dictionary with parameter values that are different than default values
214function addSpecies(new_genes)
215{
216        species_genes.add({"min_repro_energies" : [ExpProperties.min_repro_energ_haplo,ExpProperties.min_repro_energ_diplo], "energies0" : [ExpProperties.energies0_haplo, ExpProperties.energies0_diplo], "hibernation" : 0, "morphotype" : 0});
217        for (var i = 0; i < new_genes.size; i++)
218        {
219                var key = new_genes.getKey(i);
220                species_genes[species_genes.size-1][key] = new_genes[key];
221        }
222}
223
224function onExpInit()
225{
226        Populations[0].clear();
227        Populations[1].clear();
228        Populations[2].clear(); //reticulopodia and nutrients
229
230        if (species_genes.size == 0)
231        {
232                addSpecies({}); //default
233        }
234
235        for (var spec = 0; spec < species_genes.size; spec++)
236        {
237                for (var i = 0; i < ExpProperties.foramPop; i++)
238                {
239                        addInitialForam(spec, i);       
240                }
241        }
242        o = Populations[0][0].getMechPart(0).orient.clone();
243        ExpState.totaltestedcr = 0;
244
245        reprocounter = 0;
246        nutrientenergywaiting = 0;
247        changePeriod = 0;
248        phase = "low";
249}
250
251function onExpLoad()
252{
253        for (var pop in Populations)
254                pop.clear();
255
256        Loader.addClass(sim_params.*);
257        Loader.setBreakLabel(Loader.BeforeUnknown, "onExpLoad_Unknown");
258        Loader.run();
259
260        Simulator.print("Loaded " + Populations[0].size + " Forams and " + Populations[1].size + " nutrient objects");
261}
262
263function onExpLoad_Unknown()
264{
265        if (Loader.objectName == "org") // saved by the old expdef
266        {
267                var g = Genotype.newFromString("");
268                Loader.currentObject = g;
269                Interface.makeFrom(g).setAllDefault();
270                Loader.loadObject();
271                var cr = Populations[0].add(g);
272                if (cr != null)
273                {
274                        //cr.rotate(0,0,Math.rnd01*Math.twopi);
275                        if ((typeof(g.data->genes) == "Vector") && (g.data->genes.size >= 3))
276                        {
277                                // [x,y,energy]
278                                cr.move(g.data->genes[0] - cr.center_x, g.data->genes[1] - cr.center_y, 0);
279                                cr.energy = g.data->genes[2];
280                        }
281                        else
282                        {
283                                cr.move(Math.rnd01 * World.wrldsiz - cr.center_x, Math.rnd01 * World.wrldsiz - cr.center_y, 0);
284                        }
285                }
286        }
287        else if (Loader.objectName == "Creature")
288        {
289                Loader.currentObject = CreatureSnapshot.new();
290                Loader.loadObject();
291                Populations[0].add(Loader.currentObject);
292        }
293}
294
295function onExpSave()
296{
297        File.writeComment("saved by '%s.expdef'" % Simulator.expdef);
298
299        var tmpvec = [], i;
300
301        for(var cr in Populations[1])
302                tmpvec.add([cr.center_x, cr.center_y, cr.energy]);
303
304        ExpState.nutrient = tmpvec;
305        File.writeObject(sim_params.*);
306        ExpState.nutrient = null; //vectors are only created for saving and then discarded
307
308        for (var cr in Populations[0])
309                File.writeObject(cr);
310}
311
312// -------------------------------- experiment end --------------------------------
313
314// -------------------------------- foram begin -----------------------------------
315
316function setForamMeta(cr)
317{
318        //percent of current energy
319        cr.idleen = (ExpProperties.e_meta * cr.energy)*ExpProperties.secPerStep;
320}
321
322function lastChamberNum(cr)
323{
324        return cr.numparts-1;
325}
326
327function getZoneRange(cr, zone_num)
328{
329        return ExpProperties.["zone"+zone_num+"_range"];
330}
331
332function onForamsBorn(cr)
333{
334        setForamMeta(cr);
335        if (ExpProperties.visualize == 1)
336        {
337                var ret = Populations[2].add("//0\nm:Vstyle=reticulopodia\np:sh=1,sx=0.001,sy=0.001,sz=0.001\np:sh=3,sx=0.01,sy="+getZoneRange(cr,1)+",sz="+getZoneRange(cr,1)+",ry=1.57079633,vr="+curColor+"\nj:0, 1, sh=1");
338                cr.data->reticulopodiacreature = ret;
339                ret.getMechPart(0).orient.set(cr.getMechPart(0).orient);
340                ret.moveAbs(cr.center_x-getZoneRange(cr,1), cr.center_y-getZoneRange(cr,1), cr.center_z-getZoneRange(cr,1));
341        }
342}
343
344function placeRandomlyNotColliding(cr)
345{
346        var retry = 100; //try 100 times
347        while (retry--)
348        {
349                placeCreatureRandomly(cr, 0, 0);
350                if (!cr.boundingBoxCollisions(0))
351                        return cr;
352        }
353
354        Populations[0].delete(cr);
355}
356
357function visualization(cr)
358{
359        var has_ret = 0;
360
361        if (cr.data->reticulopodiacreature != null)
362        {
363                if (Populations[2].findUID(cr.data->reticulopodiacreature.uid) != null)
364                {
365                        has_ret = 1;
366                }
367        }
368
369        return has_ret;
370}
371
372function foramGrow(cr, chamber_num)
373{
374        if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size)
375        {
376                curColor = retColors[cr.data->lifeparams->gen];
377                var geno = createForamMorphology(cr.data->lifeparams->gen, cr.data->lifeparams->gen, chamber_num+1);
378                var cr2 = Populations[0].add(geno);
379
380                cr2.energy0 = cr.energy;
381                cr2.energy = cr2.energy0;
382
383                setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : "growth", "energy0" : cr.energy0});
384                cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
385                setForamMeta(cr2);
386
387                if (visualization(cr))
388                {
389                        Populations[2].delete(cr.data->reticulopodiacreature);
390                }
391                Populations[0].delete(cr);
392        }
393}
394
395function stepToNearest(cr)
396{
397        var p = cr.getMechPart(0);
398        var n = cr.signals.receiveSet("nutrient", getZoneRange(cr,2));
399
400        //if signals are received find the source of the nearest
401        if (n.size > 0)
402        {
403                var i;
404                var mp;
405                var distvec = XYZ.new(0, 0, 0);
406                var dist;
407                var mindist = 100000000000.0;
408                var mindistvec = null;
409                var eating = 0;
410
411                for (i = 0; i < n.size; i++)
412                {
413                        mp = n[i].value.getMechPart(0);
414                        distvec.set(mp.pos);
415                        distvec.sub(p.pos);
416                        dist = distvec.length;
417                        if (dist < getZoneRange(cr,1))
418                        {
419                                if (n[i].value != null)
420                                {
421                                        energyTransfer(cr, n[i].value);
422                                        eating = 1;
423                                }
424                        }
425                        else if (eating == 0 && cr.data->lifeparams->hibernated == 0 && dist < mindist)
426                        {
427                                mindist = dist;
428                                mindistvec = distvec.clone();
429                        }
430                }
431
432                if (!eating && cr.data->lifeparams->hibernated == 0)
433                {
434                        mindistvec.normalize();
435                        mindistvec.scale(-1*movePerStep);
436                        cr.localDrive = mindistvec;
437                        moveEnergyDec(cr);
438                }
439
440                return 1;
441        }
442       
443        else
444        {
445                return 0;
446        }
447}
448
449function moveEnergyDec(cr)
450{
451        if (cr.data->lifeparams->hibernated == 0)
452        {
453                //percent of maximal energy
454                cr.energy -= (ExpProperties.energy_move * cr.data->lifeparams->max_energy_level)*ExpProperties.secPerStep;
455        }
456}
457
458function fence(pos, zone)
459{
460        return Math.min(Math.max(0,pos),World.wrldsiz);
461}
462
463function foramMove(cr)
464{
465        //TODO moving inside sediment?
466
467        //adjustment in z axis
468        var change_direction = 0;
469        var new_x = fence(cr.pos_x, getZoneRange(cr, 1));
470        var new_y = fence(cr.pos_y,getZoneRange(cr, 1));
471
472        if ((new_x != cr.pos_x) || (new_y != cr.pos_y) || (cr.data->lifeparams->dir_counter >= int(secToSimSteps(ExpProperties.dir_change_sec))))
473        {
474                change_direction = 1;
475        }
476
477        cr.moveAbs(new_x, new_y, 0);
478
479        //are there any nutrients in zone 1 or 2?
480        {
481                var moved = stepToNearest(cr); //TODO weighted sum of distance and energy
482                if (moved==1)
483                {
484                        moveReticulopodia(cr);
485                        return;
486                }
487        }
488
489        //no nutrients in zone 2
490        if (getGene(cr, "hibernation",0) == 1)
491        {
492                reverseHib(cr);
493                cr.localDrive = XYZ.new(0,0,0);
494        }
495        //random move
496        else if (change_direction == 1)
497        {
498                cr.data->lifeparams->dir = randomDir();
499                cr.data->lifeparams->dir_counter = 0;
500                cr.localDrive = cr.data->lifeparams->dir;
501                moveEnergyDec(cr);
502        }
503        else
504        {
505                cr.localDrive = cr.data->lifeparams->dir;
506        }
507        moveReticulopodia(cr);
508}
509
510function moveReticulopodia(cr)
511{
512        if (visualization(cr))
513        {
514                cr.data->reticulopodiacreature.moveAbs(cr.center_x-getZoneRange(cr,1), cr.center_y-getZoneRange(cr,1), cr.center_z-getZoneRange(cr,1));
515                cr.data->reticulopodiacreature.localDrive = cr.localDrive;
516        }
517}
518
519function randomDir()
520{
521        var dir = (Math.rndUni(-ExpProperties.zone2_range, ExpProperties.zone2_range), Math.rndUni(-ExpProperties.zone2_range, ExpProperties.zone2_range), 0); 
522        dir.normalize();
523        dir.scale(-1*movePerStep);
524        return dir;
525}
526
527function energyTransfer(cr1, cr2)
528{
529        cr1.localDrive = XYZ.new(0,0,0);
530        var e =  ExpProperties.feedtrans*cr1.energy*ExpProperties.secPerStep; //TODO efficiency dependent on age
531        //Simulator.print("transferring "+e +"("+e*ExpProperties.ingestion+")"+" to "+cr1.name +" ("+ cr1.energy+") " +" from "+cr2.uid+" ("+cr2.energy+") "+ e/ExpProperties.secPerStep+ " per sec");
532        var transferred = cr2.transferEnergyTo(cr1, e);
533        cr1.energy -= transferred*(1-ExpProperties.ingestion);
534        if (cr1.data->lifeparams->hibernated == 1)
535        {
536                reverseHib(cr1);
537        }
538}
539
540function reverseHib(cr)
541{
542        if (cr.data->lifeparams->hibernated == 1)
543        {
544                setForamMeta(cr); //unhibernate
545        }
546        else
547        {
548                cr.idleen = (ExpProperties.energy_hib * cr.energy)*ExpProperties.secPerStep; //hibernate
549        }
550        cr.data->lifeparams->hibernated = 1 - cr.data->lifeparams->hibernated;
551}
552
553function createLogVector(cr, value)
554{
555        var vec = Vector.new();
556        for (var i = 0; i < species_genes.size; i++)
557        {
558                for (var j = 0; j < 2; j++)
559                {
560                        vec.add(0);
561                }
562                if (cr.data->lifeparams->species == i)
563                {
564                        vec[i*2+cr.data->lifeparams->gen] = value;             
565                }
566        }
567        return vec;
568}
569
570function onForamsStep(cr)
571{
572        //checking for gametogenesis process
573        if (cr.data->lifeparams->division_time > 0)
574        {
575                cr.data->lifeparams->division_time = Math.max(cr.data->lifeparams->division_time-1,0);
576        }
577        //checking for end of gametogenesis
578        else if (cr.data->lifeparams->division_time == 0)
579        {
580                //waiting for gamets fusion
581        }
582        //checking for chamber growth process
583        else if (cr.data->lifeparams->chamber_growth > 0)
584        {
585                cr.data->lifeparams->chamber_growth = Math.max(cr.data->lifeparams->chamber_growth-1,0);
586                //Simulator.print("chamber growing, time left = " + cr.data->lifeparams->chamber_growth*ExpProperties.secPerStep);
587                cr.energy -= ExpProperties.chamberCostPerSec * cr.energy * ExpProperties.secPerStep;
588
589                //Simulator.print("energy " + cr2.energy + " subtracting " + growth_cost);
590        }
591        //checking for end of chamber growth process
592        else if (cr.data->lifeparams->chamber_growth == 0)
593        {
594                foramGrow(cr, lastChamberNum(cr));
595                cr.data->lifeparams->chamber_growth = -1;
596                //Simulator.print("chamber "+ (lastChamberNum(cr) + 1) +" complete");
597        }
598        else
599        {
600                //update of metabolism rate
601                if (cr.data->lifeparams->hibernated == 0)
602                {
603                        setForamMeta(cr);
604                }
605
606                cr.getMechPart(0).orient.set(o);
607
608                if (deathConditions(cr) == 1)
609                {
610                        if (ExpProperties.logging == 1)
611                        {
612                                log(createLogVector(cr, cr.data->lifeparams->max_energy_level),ExpProperties.logPref+"fossil_log.txt");
613                                log(createLogVector(cr, cr.lifespan),ExpProperties.logPref+"lifespan_log.txt");
614                        }                       
615                        Populations[0].kill(cr);
616                        return;
617                }
618
619                //update direction change counter
620                cr.data->lifeparams->dir_counter += 1;
621
622                foramMove(cr);
623
624                var repro = foramReproduce(cr);
625                if (repro == 1)
626                {
627                        return;
628                }
629
630                cr.data->lifeparams->max_energy_level = Math.max(cr.energy, cr.data->lifeparams->max_energy_level);
631
632                //cheking conditions of chamber growth process start
633                if  (lastChamberNum(cr) != chambers[0].size-1)
634                {
635                        if ((cr.data->lifeparams->max_energy_level >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][lastChamberNum(cr)],0)))   
636                        {
637                                cr.data->lifeparams->chamber_growth = int(secToSimSteps(ExpProperties.chamberGrowthSec));
638                        }       
639                }
640        }       
641}
642
643function deathConditions(cr)
644{
645        if ((cr.energy <= getProperty(cr.data->lifeparams->gen,"e_death_level")*cr.data->lifeparams->max_energy_level) || (Math.rnd01 < ExpProperties.hunted_prob))
646        {
647                return 1;
648        }
649        else
650                return 0;
651}
652
653function onForamsDied(cr)
654{
655        if (visualization(cr))
656        {
657                Populations[2].delete(cr.data->reticulopodiacreature);
658        }
659        //fossilization
660        var geno = GenePools[0].add(cr.genotype);
661        geno.data->genes = cr.data->genes;
662        geno.data->lifeparams = cr.data->lifeparams;
663        if (ExpProperties.logging == 1) Simulator.print("\"" + cr.name + "\" died...");
664        ExpState.totaltestedcr++;
665}
666
667// --------------------------------foram end -------------------------------------
668
669// -------------------------------- nutrient begin --------------------------------
670
671function createNutrientGenotype(nutrientradius)
672{
673        return "//0\nm:Vstyle=nutrient\np:sh=3,sx="+nutrientradius+",sy="+nutrientradius+",sz="+nutrientradius+",ry=1.57,vr=0.0,1.0,0.0";
674}
675
676function onNutrientsStep(cr)
677{
678        cr.moveAbs(cr.pos_x % World.wrldsiz, cr.pos_y % World.wrldsiz, 0.5);
679}
680
681function addNutrient()
682{
683        var cr = Populations[1].add(createNutrientGenotype(ExpProperties.nutrientradius));
684
685        cr.name = "Nutrients";
686        cr.idleen = 0;
687        cr.energy0 = ExpProperties.energy_nut;
688        cr.energy = cr.energy0;
689        cr.signals.add("nutrient");
690
691        cr.signals[0].value = cr;
692
693        placeCreatureRandomly(cr, 0, 0);
694        if (ExpProperties.visualize == 1)
695        {
696                var nutsize = ExpProperties.nutrientradius*10;
697                var nut = Populations[2].add("//0\nm:Vstyle=nutrient_visual\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0");
698                cr.data->reticulopodiacreature = nut;
699                nut.moveAbs(cr.pos_x-1.5*nutsize, cr.pos_y-1.5*nutsize, 0.5);
700        }
701}
702
703function onNutrientsDied(cr)
704{
705        if (visualization(cr))
706        {
707                Populations[2].delete(cr.data->reticulopodiacreature);
708        }
709}
710
711function nutrientGrowth()
712{
713        if (ExpProperties.foodPeriodChange > 0)
714        {
715                        changePeriod += 1;
716                        if (phase=="low" && changePeriod >= secToSimSteps(23328000)) //9 months
717                        {
718                                ExpProperties.foodperiod = ExpProperties.foodperiod/ExpProperties.foodPeriodChange;
719                                phase = "high";
720                                changePeriod = 0;
721                        }
722               
723                        else if (phase == "high" && changePeriod >= secToSimSteps(7776000)) //3 months
724                        {
725                                ExpProperties.foodperiod = ExpProperties.foodperiod*ExpProperties.foodPeriodChange;
726                                phase = "low";
727                                changePeriod = 0;
728                        }
729        }
730        nutrientenergywaiting = nutrientenergywaiting + 1;
731        if (nutrientenergywaiting >= secToSimSteps(ExpProperties.foodperiod))
732        {
733                for (var i = 0; i < ExpProperties.nutrient_pop; i++)
734                {   
735                        addNutrient();
736                }
737
738                nutrientenergywaiting = 0.0;
739                Simulator.checkpoint();
740
741                if (ExpProperties.logging == 1)
742                {
743                        log([ExpProperties.nutrient_pop],ExpProperties.logPref+"nutrients_log.txt");
744                }
745        }
746
747}
748
749// -------------------------------- nutrient end --------------------------------
750
751// -------------------------------- step begin --------------------------------
752
753function onStep()
754{
755
756        nutrientGrowth();
757        if (ExpProperties.logging == 1)
758        {
759                createStatistics();
760        }
761
762        //reproduction --------------------------------------------
763        reprocounter += 1;
764        if (reprocounter > secToSimSteps(ExpProperties.reproTimeSec))
765        {
766                reprocounter = 0;
767                reproduce_parents(0);
768                reproduce_parents(1);
769        }
770
771        //check for extinction -----------------------------------------------
772        if (Populations[0].size == 0)
773        {
774                if (ExpProperties.autorestart)
775                {
776                        Simulator.print("no more creatures, restarting...");
777                        onExpInit();
778                }
779                else
780                {
781                        Simulator.print("no more creatures, stopped.");
782                        Simulator.stop();
783                }
784        }
785        if (ExpProperties.maxSteps > 0)
786        {
787                if (Simulator.stepNumber >= ExpProperties.maxSteps)
788                        Simulator.stop();
789        }
790}
791
792function createStatistics()
793{       
794        var number = [];
795        var e_inc = [];
796        var e_nut = 0.0;
797
798        for (var s = 0; s < species_genes.size; s++)
799        {
800                number.add([0,0]);// [haplo][diplo]
801                e_inc.add([0,0]);
802        }
803
804        for (var i = 0; i < Populations[0].size; i++)
805        {
806                var cr = Populations[0].get(i);
807                var gen = cr.data->lifeparams->gen;
808                var species = cr.data->lifeparams->species;
809
810                number[species][gen] = number[species][gen] + 1;
811                e_inc[species][gen] = e_inc[species][gen] + cr.energy;
812        }
813
814        for (var i = 0; i < Populations[1].size; i++)
815        {
816                var cr = Populations[1].get(i);
817                e_nut += cr.energy;
818        }
819
820        var log_numbers = [];
821        var log_energies = [];
822
823        for (var s = 0; s < species_genes.size; s++)
824        {
825                for (var p = 0; p < 2; p++)
826                {
827                        log_numbers.add(number[s][p]);
828                        log_energies.add(e_inc[s][p]);
829                }
830        }
831       
832        log_numbers.add(Populations[1].size);
833        log_energies.add(e_nut);
834
835        log(log_numbers, ExpProperties.logPref+"forams_log.txt");
836    log(log_energies,  ExpProperties.logPref+"energies_log.txt");
837}
838
839function log(tolog, fname)
840{
841        var f = File.appendDirect(fname, "forams data");
842        f.writeString("" + Simulator.stepNumber);
843        for (var  i = 0; i < tolog.size; i++)
844        {
845                f.writeString(";" + tolog[i]);
846        }
847        f.writeString("\n");
848        f.close();
849}
850
851// -------------------------------- step end --------------------------------
852//TODO default params values in frams instead of microns/seconds
853
854@include "standard_events.inc"
855
856~
857
858property:
859id:visualize
860name:Show reticulopodia and nutrients
861type:d 0 1 0
862group:
863
864property:
865id:maxSteps
866name:Maximum number of steps
867type:d 0 10000000 0
868group:
869
870property:
871id:logging
872name:Log statistics to file
873type:d 0 1 0
874group:
875
876property:
877id:logPref
878name:Log prefix
879type:s
880
881property:
882id:secPerStep
883name:Seconds per simulation step
884help:Number of seconds of foraminifera time per simulation step
885type:f 1 480 300
886flags: 16
887group:
888
889property:
890id:foramSpeedMmPerMin
891name:Speed of foraminfera in mm/min
892type:f 0.01 0.1 0.05
893flags: 16
894group:Foraminifera
895
896property:
897id:dir_change_sec
898name:Number of seconds before direction change
899type:d 300 300000 6000
900group:Foraminifera
901
902property:
903id:foramPop
904name:Initial forams population size
905type:d 1 1000 20
906group:Foraminifera
907
908property:
909id:gametoPeriodSec
910name:Time of gametogenesis
911type:f 300 300000 21600
912group:Reproduction
913
914property:
915id:gametSuccessRate
916name:Ratio of successful gamets
917type:f 0.0001 0.01 0.001
918group:Reproduction
919
920property:
921id:divisionCost
922name:Cost of division in pG
923type:f 15 25 20
924group:Reproduction
925
926property:
927id:min_repro_energ_haplo
928name:Min reproduction energy of haploid
929type:f 0 -1 4
930group:Energy
931
932property:
933id:min_repro_energ_diplo
934name:Min reproduction energy of diploid
935type:f 0 -1 6
936group:Energy
937
938property:
939id:repro_prob
940name:Probability of reproduction
941type:f 0 1 0.8
942group:Reproduction
943
944property:
945id:energies0_haplo
946name:Energy of offspring from diploid forams
947type:f 0 -1 20
948group:Energy
949
950property:
951id:energies0_diplo
952name:Energy of offspring from diploid forams
953type:f 0 -1 1.25
954group:Energy
955
956property:
957id:crossprob
958name:Crossover probability
959type:f 0 1 0
960group:Reproduction
961
962property:
963id:mutationprob
964name:Mutation probability
965type:f 0 1 0
966group:Reproduction
967
968property:
969id:reproTimeSec
970name:Time before reproduction
971type:d 0 10000 720
972group:Reproduction
973
974property:
975id:chamberGrowthSec
976name:Time of the chamber growth in seconds
977type:f 360 1440 720
978group:Foraminifera
979
980property:
981id:chamber_proculus_haplo
982name:Size of proculus
983type:f
984group:Foraminifera
985
986property:
987id:chamber_proculus_diplo
988name:Size of proculus
989type:f
990group:Foraminifera
991
992property:
993id:chamber_difference_haplo
994name:Difference in size between subsequent chambers
995type:f 0 -1 0
996group:Foraminifera
997
998property:
999id:chamber_difference_diplo
1000name:Difference in size between subsequent chambers
1001type:f 0 -1 0.08
1002group:Foraminifera
1003
1004property:
1005id:hunted_prob
1006name:Probability of being hunted
1007type:f 0 1 0
1008group:Foraminifera
1009
1010property:
1011id:zone1_range
1012name:Zone 1 range in frams units
1013type:f 0 200 10
1014group:Foraminifera
1015
1016property:
1017id:zone2_range
1018name:Zone 2 range in frams units
1019type:f 0 3000 30
1020group:Foraminifera
1021
1022property:
1023id:chamberCostPerSec
1024name:Cost of growning chamber per second
1025type:f 0 1 0.000001
1026group:Energy
1027
1028property:
1029id:e_death_level_haplo
1030name:Minimal level of energy to sustain life of haploid
1031type:f 0 1 0.5
1032group:Energy
1033
1034property:
1035id:e_death_level_diplo
1036name:Minimal level of energy to sustain life of diploid
1037type:f 0 1 0.5
1038group:Energy
1039
1040property:
1041id:energy_hib
1042name:Energy used for hibernation during one step
1043type:f 0 1 0.0000001
1044group:Energy
1045
1046property:
1047id:energy_move
1048name:Energy used for movement during one step
1049type:f 0 1 0.0000005
1050group:Energy
1051
1052property:
1053id:e_meta
1054name:Idle metabolism
1055type:f 0 1 0.0000005
1056group:Energy
1057help:Foraminifera consumes this proportion of its energy in one time step
1058
1059property:
1060id:ingestion
1061name:Ingestion rate
1062type:f 0 -1 0.25
1063group:Energy
1064
1065property:
1066id:nutrient_pop
1067name:Nutrient population
1068type:f 0 1000000
1069group:Energy
1070help:How fast energy is created in the world
1071
1072property:
1073id:energy_nut
1074name:Nutrient energy
1075type:f 0 10000000
1076group:Energy
1077
1078property:
1079id:nutrientradius
1080name:Nutrient size
1081type:f 0.001 0.9 0.1
1082group:Energy
1083
1084property:
1085id:picoCarbonPerMikro
1086name:Picograms of carbon in cubic micrometer
1087type:f 0 -1 0.13
1088group:Energy
1089
1090property:
1091id:feedtrans
1092name:Energy transfer per second
1093type:f 0 1 0.001
1094group:Energy
1095
1096property:
1097id:foodperiod
1098name:Time between food occurrences
1099type:f 0 1000000 14400
1100group:Energy
1101
1102property:
1103id:foodPeriodChange
1104name:Set variable feed rate
1105type:f 0 -1 0
1106group:Energy
1107
1108property:
1109id:stress
1110name:Environmental stress
1111type:d 0 1 1
1112group:
1113
1114property:
1115id:repro_trigger
1116name:Reproduction trigger
1117type:d 0 1 1
1118group:Reproduction
1119
1120property:
1121id:creath
1122name:Creation height
1123type:f -1 50 -0.99
1124help:~
1125Vertical position (above the surface) where new Forams are revived.
1126Negative values are only used in the water area:
1127  0   = at the surface
1128-0.5 = half depth
1129-1   = just above the bottom~
1130
1131property:
1132id:autorestart
1133name:Restart after extinction
1134help:Restart automatically this experiment after the last creature has died?
1135type:d 0 1 0
1136
1137state:
1138id:nutrient
1139name:Nutrient locations
1140help:vector of vectors [x,y,energy]
1141type:x
1142flags:32
1143
1144state:
1145id:notes
1146name:Notes
1147type:s 1
1148help:~
1149You can write anything here
1150(it will be saved to the experiment file)~
1151
1152state:
1153id:totaltestedcr
1154name:Evaluated Forams
1155help:Total number of the Forams evaluated in the experiment
1156type:d
1157flags:16
Note: See TracBrowser for help on using the repository browser.