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

Last change on this file since 554 was 554, checked in by oriona, 8 years ago

Refactoring, change of foraminifera direction at world boundary added.

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