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