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

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

Reticulopdia movement and energy transfer corrected.

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\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(o);
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_m += (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; //TODO efficiency dependent on age
551        e = Math.min(cr2.energy, e*ExpProperties.secPerStep);
552        //Simulator.print("transferring "+e +"("+e*ExpProperties.ingestion+")"+" to "+cr1.name +" ("+ cr1.energy+") " +" from "+cr2.uid+" ("+cr2.energy+") "+ e/ExpProperties.secPerStep+ " per sec");
553        cr2.energy -= (e + 0.0000001);
554        cr1.energy_p += e*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_m += 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\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
919type:f 60.0
920flags: 16
921group:Foraminifera
922
923property:
924id:e_repro_cost_haplo
925name:Cost of reproduction
926type:f 0.1 0.9 0.5
927group:Foraminifera
928
929property:
930id:divisionCost
931name:Cost of division in pG
932type:f
933group:Foraminifera
934
935property:
936id:e_repro_cost_diplo
937name:Cost of reproduction
938type:f 0.1 0.9 0.3
939group:Foraminifera
940
941property:
942id:chamber_growth_time
943name:Time of the chamber growth in seconds
944type:f
945group:Foraminifera
946
947property:
948id:chamberCostPerSec
949name:Cost of growning chamber per second
950type:f
951group:Foraminifera
952
953property:
954id:chamber_proculus_haplo
955name:Size of proculus
956type:f
957group:Foraminifera
958
959property:
960id:chamber_proculus_diplo
961name:Size of proculus
962type:f
963group:Foraminifera
964
965property:
966id:chamber_difference_haplo
967name:Difference in size between subsequent chambers
968type:f
969group:Foraminifera
970
971property:
972id:chamber_difference_diplo
973name:Difference in size between subsequent chambers
974type:f
975group:Foraminifera
976
977property:
978id:hunted_prob
979name:Probability of being hunted
980type:f 0 1 0
981group:Forminifera
982
983property:
984id:zone1_range
985name:Zone 1 range
986type:f 0 200
987group:Foraminifera
988
989property:
990id:zone2_range
991name:Zone 2 range
992type:f 0 3000
993group:Foraminifera
994
995property:
996id:colors
997name:Haploid and diploid colors
998type:x
999group:Foraminifera
1000
1001property:
1002id:min_repro_energ_haplo
1003name:Min reproduction energy of forams
1004type:f
1005group:Foraminifera
1006
1007property:
1008id:min_repro_energ_diplo
1009name:Min reproduction energy of forams
1010type:f
1011group:Foraminifera
1012
1013property:
1014id:repro_prob
1015name:Probability of reproduction
1016type:f 0 1 0.8
1017group:Foraminifera
1018
1019property:
1020id:energies0_haplo
1021name:Energy of offspring from diploid forams
1022type:f
1023group:Foraminifera
1024
1025property:
1026id:energies0_diplo
1027name:Energy of offspring from diploid forams
1028type:f
1029group:Foraminifera
1030
1031property:
1032id:e_death_level_haplo
1033name:Minimal level of energy to sustain life of haploid
1034type:f 0 20 0.2
1035group:Foraminifera
1036
1037property:
1038id:e_death_level_diplo
1039name:Minimal level of energy to sustain life of diploid
1040type:f 0 20 0.2
1041group:Foraminifera
1042
1043property:
1044id:energy_hib
1045name:Energy used for hibernation during one step
1046type:f 0 1 0.001
1047group:Foraminifera
1048
1049property:
1050id:energy_move
1051name:Energy used for movement during one step
1052type:f 0 20 0.001
1053group:Foraminifera
1054
1055property:
1056id:min_vol
1057name:Minimal volume for reproduction
1058type:f 100 900 100
1059group:Foraminifera
1060
1061property:
1062id:max_size
1063name:Maximal size
1064type:d 1 10 5
1065group:Foraminifera
1066
1067property:
1068id:foramPop
1069name:Initial forams population size
1070type:d 1 1000 100
1071group:Foraminifera
1072
1073property:
1074id:crossprob
1075name:Crossover probability
1076type:f 0 1 0
1077group:Foraminifera
1078
1079property:
1080id:mutationprob
1081name:Mutation probability
1082type:f 0 1 0
1083group:Foraminifera
1084
1085property:
1086id:e_meta
1087name:Idle metabolism
1088type:f 0 1
1089group:Energy
1090help:Each stick consumes this amount of energy in one time step
1091
1092property:
1093id:nutrient_pop
1094name:Feeding rate
1095type:f 0 1000000
1096group:Energy
1097help:How fast energy is created in the world
1098
1099property:
1100id:foodPeriodChange
1101name:Set variable feed rate
1102type:f 0
1103group:Energy
1104
1105property:
1106id:ingestion
1107name:Ingestion rate
1108type:f
1109group:Energy
1110
1111property:
1112id:energy_nut
1113name:Nutrient energy
1114type:f 0 10000000
1115group:Energy
1116
1117property:
1118id:feedtrans
1119name:Energy transfer per second
1120type:f 0 100000
1121group:Energy
1122
1123property:
1124id:foodperiod
1125name:Time between food occurrences
1126type:f 0 1000000
1127group:Energy
1128
1129property:
1130id:nutrientradius
1131name:Nutrient size
1132type:f 0.001 0.9 0.1
1133group:Energy
1134
1135property:
1136id:stress
1137name:Environmental stress
1138type:d 0 1 1
1139group:World
1140
1141property:
1142id:repro_trigger
1143name:Reproduction trigger
1144type:d 0 1 1
1145group:World
1146
1147property:
1148id:repro_time
1149name:Time before reproduction
1150type:d 0 10000
1151
1152property:
1153id:creath
1154name:Creation height
1155type:f -1 50
1156help:~
1157Vertical position (above the surface) where new Forams are revived.
1158Negative values are only used in the water area:
1159  0   = at the surface
1160-0.5 = half depth
1161-1   = just above the bottom~
1162
1163state:
1164id:nutrient
1165name:Nutrient locations
1166help:vector of vectors [x,y,energy]
1167type:x
1168flags:32
1169
1170property:
1171id:autorestart
1172name:Restart after extinction
1173help:Restart automatically this experiment after the last creature has died?
1174type:d 0 1
1175
1176state:
1177id:notes
1178name:Notes
1179type:s 1
1180help:~
1181You can write anything here
1182(it will be saved to the experiment file)~
1183
1184state:
1185id:totaltestedcr
1186name:Evaluated Forams
1187help:Total number of the Forams evaluated in the experiment
1188type:d
1189flags:16
1190
1191property:
1192id:logging
1193name:Log statistics to file
1194type:d 0 1 0
Note: See TracBrowser for help on using the repository browser.