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

Last change on this file since 525 was 525, checked in by oriona, 7 years ago

Adjustment of reticulopodia position for initial forams added.

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