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

Last change on this file since 510 was 510, checked in by oriona, 6 years ago

Energy transfer changed for using tranferEnergyTo function. Dilpoid offspring number calculation changed.

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