[380] | 1 | expdef:
|
---|
[406] | 2 | name:Reproduction of benthic foraminifera
|
---|
[380] | 3 | info:~
|
---|
| 4 | Genes and parameter values which control reproduction are stored in user1 and user2 fields.
|
---|
| 5 |
|
---|
| 6 | user1:
|
---|
[402] | 7 | genes which are not encoded in Ff genotype:
|
---|
[422] | 8 | min_repro_energy - Minimum energy necessary for reproduction
|
---|
| 9 | hibernation - Defines foram behavior in the case of no nutrients
|
---|
[380] | 10 |
|
---|
| 11 | user2:
|
---|
| 12 | Physiological parameters of foraminifera:
|
---|
[422] | 13 | max_energy_level - maximum energy level reached so far
|
---|
[380] | 14 | gen - generation: 0 haploid, 1 diploid
|
---|
[430] | 15 | species - species: 0 hibernating 1 not hibernating
|
---|
[422] | 16 | hibernated - 0/1 foram isn't/is hibernated
|
---|
| 17 | reproduce - 0/1 foram isn't/is ready for reproduction
|
---|
[380] | 18 | ~
|
---|
| 19 | code:~
|
---|
| 20 |
|
---|
[401] | 21 | /*
|
---|
| 22 | changes 2015-06-24:
|
---|
| 23 | - xxx.get(...) changed to xxx[...]
|
---|
| 24 | - xxx.set(...,...) changed to xxx[...]=...
|
---|
[421] | 25 | - function placeRandomlyNotColliding(cr) explicitly called when adding a new creature, and removed collision checking from onForamsBorn() which is also called when "growing" (since "growing" is implemented as creating a new creature in place of the old one, so onForamsBorn() is also called)
|
---|
[401] | 26 | - use creature's center (not the bbox corner) when growing
|
---|
| 27 | - added "S" receptor to visualize the difference between diplo and haplo generations
|
---|
| 28 | - signal.value is a MechPart (a reference) so it does not have to be updated after changing the object location
|
---|
| 29 | */
|
---|
| 30 |
|
---|
[421] | 31 | global nutrientenergywaiting;
|
---|
[380] | 32 | global reprocounter;
|
---|
[422] | 33 | global colors;
|
---|
| 34 | global chambers;
|
---|
| 35 | global o;
|
---|
| 36 | global max_chamber_energ;
|
---|
[430] | 37 | global dir_change;
|
---|
[380] | 38 |
|
---|
[406] | 39 | @include "foraminifera.inc"
|
---|
[401] | 40 |
|
---|
[380] | 41 | // -------------------------------- experiment begin --------------------------------
|
---|
| 42 |
|
---|
| 43 | function onExpDefLoad()
|
---|
| 44 | {
|
---|
| 45 | // define genotype and creature groups
|
---|
| 46 | GenePools.clear();
|
---|
| 47 | Populations.clear();
|
---|
| 48 | GenePools[0].name = "Unused";
|
---|
| 49 |
|
---|
| 50 | var pop = Populations[0];
|
---|
[421] | 51 | pop.name = "Forams";
|
---|
[380] | 52 | pop.en_assim = 0;
|
---|
[404] | 53 | pop.nnsim = 0;
|
---|
[380] | 54 | pop.enableperf = 1;
|
---|
| 55 | pop.death = 1;
|
---|
| 56 | pop.energy = 1;
|
---|
| 57 | pop.selfmask = 0x10001;
|
---|
[401] | 58 | pop.othermask = 0x20001;
|
---|
| 59 | //pop.selfmask = 0x20002; pop.othermask = 0x10002;
|
---|
[422] | 60 | pop.perfperiod = 25;
|
---|
[380] | 61 |
|
---|
[421] | 62 | pop = Populations.addGroup("Nutrients");
|
---|
[380] | 63 | pop.nnsim = 0;
|
---|
| 64 | pop.enableperf = 0;
|
---|
| 65 | pop.death = 1;
|
---|
| 66 | pop.energy = 1;
|
---|
| 67 | pop.selfmask = 0x20002;
|
---|
[401] | 68 | pop.othermask = 0x10000;
|
---|
[422] | 69 | //pop.othermask = 0x10002;
|
---|
[380] | 70 |
|
---|
[430] | 71 | //ExpParams.showRet = 1; //uncomment to show reticulopodia
|
---|
| 72 |
|
---|
| 73 | pop = Populations.addGroup("Reticulopodia");
|
---|
| 74 | pop.nnsim = 0;
|
---|
| 75 | pop.enableperf = 0;
|
---|
| 76 | pop.death = 0;
|
---|
| 77 | pop.energy = 0;
|
---|
| 78 | pop.selfmask = 0x20002;
|
---|
| 79 | pop.othermask = 0x10000;
|
---|
| 80 |
|
---|
[422] | 81 | //world
|
---|
| 82 | SignalView.mode = 1;
|
---|
[430] | 83 | ExpParams.world_size = scale(40000);
|
---|
| 84 | World.wrldwat = 200;
|
---|
[422] | 85 | World.wrldsiz = ExpParams.world_size;
|
---|
| 86 | World.wrldbnd = 1;
|
---|
| 87 | ExpParams.stress = 1;
|
---|
[421] | 88 | ExpParams.creath = -0.99; //just above the bottom
|
---|
[380] | 89 | ExpParams.autorestart = 0;
|
---|
[422] | 90 |
|
---|
[411] | 91 | //ExpParams.logging = 1; //uncomment to enable logging simulation parameters to log files
|
---|
[401] | 92 |
|
---|
[422] | 93 | //reproduction
|
---|
[430] | 94 | ExpParams.foramPop = 10;
|
---|
[401] | 95 | ExpParams.crossprob = 0.4;
|
---|
| 96 | ExpParams.mutationprob = 0.2;
|
---|
[422] | 97 | ExpParams.repro_time = 20;
|
---|
| 98 | reprocounter = 0;
|
---|
[380] | 99 |
|
---|
[422] | 100 | //morphology
|
---|
[430] | 101 | dir_change = 500;
|
---|
| 102 | ExpParams.zone1_range = scale(5000);
|
---|
| 103 | ExpParams.zone2_range = scale(8000);
|
---|
[422] | 104 | init_chambers();
|
---|
[430] | 105 | ExpParams.chamber_proculus_haplo = scale(50);
|
---|
[422] | 106 | ExpParams.chamber_difference_haplo = 0.0;
|
---|
| 107 | ExpParams.chamber_proculus_diplo = scale(20);
|
---|
| 108 | ExpParams.chamber_difference_diplo = 0.2;
|
---|
| 109 | max_chamber_energ = [Vector.new(), Vector.new()];
|
---|
| 110 | for (var j = 0; j < 2; j++)
|
---|
| 111 | {
|
---|
| 112 | for (var i = 0; i < chambers[0].size; i++)
|
---|
| 113 | {
|
---|
| 114 | max_chamber_energ[j].add(((Math.pow(getProperty(j, "chamber_proculus"),3) + Math.pow(getProperty(j, "chamber_proculus") + (i) * getProperty(j, "chamber_difference"),3))*(i+1))/2);
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | //energetics
|
---|
[430] | 119 | ExpParams.min_repro_energ_haplo = 4;
|
---|
| 120 | ExpParams.min_repro_energ_diplo = 6;
|
---|
| 121 |
|
---|
| 122 | ExpParams.e_meta = 0.0002;
|
---|
| 123 | ExpParams.energy_hib = 0.0001;
|
---|
| 124 | ExpParams.energy_move = 0.00025;
|
---|
| 125 |
|
---|
| 126 | ExpParams.energies0_haplo = max_chamber_energ[0][0] - 0.001*max_chamber_energ[0][0];
|
---|
| 127 | ExpParams.energies0_diplo = max_chamber_energ[1][0] - 0.001*max_chamber_energ[1][0];
|
---|
| 128 | ExpParams.feedtrans = 0.5;
|
---|
| 129 | ExpParams.e_repro_cost_haplo = 0.7;
|
---|
[422] | 130 | ExpParams.e_repro_cost_diplo = 0.3;
|
---|
| 131 |
|
---|
| 132 | //nutrients
|
---|
| 133 | ExpParams.nutrientsize = scale(10);
|
---|
| 134 | ExpParams.energy_nut = 100 * Math.pow(ExpParams.nutrientsize, 3);
|
---|
[430] | 135 | ExpParams.nutrientPop = 1;
|
---|
| 136 | ExpParams.feedrate = 0.1;
|
---|
[422] | 137 | nutrientenergywaiting = ExpParams.energy_nut;
|
---|
[380] | 138 | ExpState.totaltestedcr = 0;
|
---|
[421] | 139 | ExpState.nutrient = "";
|
---|
[380] | 140 | }
|
---|
| 141 |
|
---|
| 142 | @include "standard_placement.inc"
|
---|
| 143 |
|
---|
[422] | 144 | function scale(x)
|
---|
| 145 | {
|
---|
| 146 | return x*0.025;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | function getProperty(gen, prop_id)
|
---|
| 150 | {
|
---|
| 151 | var ploid = "haplo";
|
---|
| 152 | if (gen == 1) ploid = "diplo";
|
---|
| 153 | return ExpParams.[prop_id + "_" + ploid];
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | function addInitialForam(species, i)
|
---|
| 157 | {
|
---|
| 158 | var geno = createForamGenotype(0, species, 0);
|
---|
| 159 | var cr = Populations[0].add(geno);
|
---|
| 160 | cr.name = "Initial creature" + species + "_" + i;
|
---|
| 161 | placeCreatureRandomly(cr, 0, 0);
|
---|
| 162 | cr.energy0 = getProperty(0, "energies0");
|
---|
| 163 | cr.energy = cr.energy0;
|
---|
| 164 | setGenotype({"opt" : 0, "cr" : cr, "species" : species});
|
---|
| 165 | }
|
---|
| 166 |
|
---|
[380] | 167 | function onExpInit()
|
---|
| 168 | {
|
---|
| 169 | Populations[0].clear();
|
---|
| 170 | Populations[1].clear();
|
---|
[430] | 171 | Populations[2].clear();
|
---|
[380] | 172 |
|
---|
[422] | 173 | for (var i = 0; i < ExpParams.foramPop; i++)
|
---|
[380] | 174 | {
|
---|
[422] | 175 | addInitialForam(0, i);
|
---|
| 176 | addInitialForam(1, i);
|
---|
[380] | 177 | }
|
---|
[422] | 178 | o = Populations[0][0].getMechPart(0).orient.clone();
|
---|
[380] | 179 | ExpState.totaltestedcr = 0;
|
---|
[422] | 180 | nutrientenergywaiting = ExpParams.energy_nut;
|
---|
[380] | 181 | }
|
---|
| 182 |
|
---|
| 183 | function onExpLoad()
|
---|
| 184 | {
|
---|
| 185 | for (var pop in Populations)
|
---|
| 186 | pop.clear();
|
---|
| 187 |
|
---|
| 188 | Loader.addClass(sim_params.*);
|
---|
| 189 | Loader.setBreakLabel(Loader.BeforeUnknown, "onExpLoad_Unknown");
|
---|
| 190 | Loader.run();
|
---|
| 191 |
|
---|
[421] | 192 | Simulator.print("Loaded " + Populations[0].size + " Forams and " + Populations[1].size + " nutrient objects");
|
---|
[380] | 193 | }
|
---|
| 194 |
|
---|
| 195 | function onExpLoad_Unknown()
|
---|
| 196 | {
|
---|
| 197 | if (Loader.objectName == "org") // saved by the old expdef
|
---|
| 198 | {
|
---|
| 199 | var g = Genotype.newFromString("");
|
---|
| 200 | Loader.currentObject = g;
|
---|
| 201 | Interface.makeFrom(g).setAllDefault();
|
---|
| 202 | Loader.loadObject();
|
---|
| 203 | var cr = Populations[0].add(g);
|
---|
| 204 | if (cr != null)
|
---|
| 205 | {
|
---|
[401] | 206 | //cr.rotate(0,0,Math.rnd01*Math.twopi);
|
---|
[380] | 207 | if ((typeof(g.user1) == "Vector") && (g.user1.size >= 3))
|
---|
[401] | 208 | {
|
---|
| 209 | // [x,y,energy]
|
---|
[380] | 210 | cr.move(g.user1[0] - cr.center_x, g.user1[1] - cr.center_y, 0);
|
---|
| 211 | cr.energy = g.user1[2];
|
---|
| 212 | }
|
---|
| 213 | else
|
---|
| 214 | {
|
---|
[401] | 215 | cr.move(Math.rnd01 * World.wrldsiz - cr.center_x, Math.rnd01 * World.wrldsiz - cr.center_y, 0);
|
---|
[380] | 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
| 219 | else if (Loader.objectName == "Creature")
|
---|
| 220 | {
|
---|
| 221 | Loader.currentObject = CreatureSnapshot.new();
|
---|
| 222 | Loader.loadObject();
|
---|
| 223 | Populations[0].add(Loader.currentObject);
|
---|
| 224 | }
|
---|
| 225 | }
|
---|
| 226 |
|
---|
| 227 | function onExpSave()
|
---|
| 228 | {
|
---|
| 229 | File.writeComment("saved by '%s.expdef'" % Simulator.expdef);
|
---|
| 230 |
|
---|
[401] | 231 | var tmpvec = [], i;
|
---|
[380] | 232 |
|
---|
[401] | 233 | for(var cr in Populations[1])
|
---|
[380] | 234 | tmpvec.add([cr.center_x, cr.center_y, cr.energy]);
|
---|
| 235 |
|
---|
[421] | 236 | ExpState.nutrient = tmpvec;
|
---|
[380] | 237 | File.writeObject(sim_params.*);
|
---|
[430] | 238 | ExpState.nutrient = null; //vectors are only created for saving and then discardedsetForam
|
---|
[380] | 239 |
|
---|
| 240 | for (var cr in Populations[0])
|
---|
| 241 | File.writeObject(cr);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | // -------------------------------- experiment end --------------------------------
|
---|
| 245 |
|
---|
[421] | 246 | // -------------------------------- foram begin -----------------------------------
|
---|
[380] | 247 |
|
---|
[430] | 248 | function setForamMeta(cr, gen)
|
---|
| 249 | {
|
---|
| 250 | cr.idleen = ExpParams.e_meta * max_chamber_energ[gen][Math.min(lastChamberNum(cr), max_chamber_energ[gen].size-1)];
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | function lastChamberNum(cr)
|
---|
| 254 | {
|
---|
| 255 | return cr.numparts-1;
|
---|
| 256 | }
|
---|
| 257 |
|
---|
[421] | 258 | function onForamsBorn(cr)
|
---|
| 259 | {
|
---|
[430] | 260 | setForamMeta(cr, 1);
|
---|
| 261 | if (ExpParams.showRet == 1)
|
---|
| 262 | {
|
---|
| 263 | var ret = Populations[2].add("//0\np:sh=3,sx=0.01,sy="+ExpParams.zone1_range+",sz="+ExpParams.zone1_range+",ry=1.57");
|
---|
| 264 | cr.user3 = ret;
|
---|
| 265 | }
|
---|
[380] | 266 | }
|
---|
| 267 |
|
---|
[401] | 268 | function placeRandomlyNotColliding(cr)
|
---|
| 269 | {
|
---|
| 270 | var retry = 100; //try 100 times
|
---|
| 271 | while (retry--)
|
---|
| 272 | {
|
---|
| 273 | placeCreatureRandomly(cr, 0, 0);
|
---|
| 274 | if (!cr.boundingBoxCollisions(0))
|
---|
| 275 | return cr;
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | Populations[0].delete(cr);
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[422] | 281 | function foramGrow(cr, chamber_num)
|
---|
[380] | 282 | {
|
---|
[430] | 283 | var geno = createForamGenotype(cr.user2["gen"], cr.user2["species"], chamber_num+1);
|
---|
[422] | 284 | var cr2 = Populations[0].add(geno);
|
---|
| 285 |
|
---|
| 286 | cr2.energy0 = cr.energy;
|
---|
| 287 | cr2.energy = cr2.energy0;
|
---|
| 288 |
|
---|
| 289 | setGenotype({"cr" : cr2, "parent_user1" : cr.user1, "parent_user2" : cr.user2, "opt" : 2});
|
---|
| 290 | cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z);
|
---|
[430] | 291 | setForamMeta(cr2, cr2.user2["gen"]);
|
---|
[422] | 292 |
|
---|
[430] | 293 | if (ExpParams.showRet == 1)
|
---|
| 294 | {
|
---|
| 295 | Populations[2].delete(cr.user3);
|
---|
| 296 | }
|
---|
[422] | 297 | Populations[0].delete(cr);
|
---|
[380] | 298 | }
|
---|
| 299 |
|
---|
[422] | 300 | function stepToNearest(cr, range)
|
---|
[380] | 301 | {
|
---|
| 302 | var p = cr.getMechPart(0);
|
---|
[422] | 303 | var n = cr.signals.receiveSet("nutrient", ExpParams.zone2_range);
|
---|
[380] | 304 |
|
---|
[401] | 305 | //if signals are received find the source of the nearest
|
---|
[380] | 306 | if (n.size > 0)
|
---|
| 307 | {
|
---|
| 308 | var i;
|
---|
| 309 | var mp;
|
---|
| 310 | var distvec = XYZ.new(0, 0, 0);
|
---|
| 311 | var dist;
|
---|
| 312 | var mindist = 100000000000;
|
---|
| 313 | var mindistvec = null;
|
---|
[430] | 314 | var eating = 0;
|
---|
[380] | 315 |
|
---|
[401] | 316 | for (i = 0; i < n.size; i++)
|
---|
[380] | 317 | {
|
---|
[430] | 318 | mp = n[i].value.getMechPart(0);
|
---|
[401] | 319 | distvec.set(mp.pos);
|
---|
| 320 | distvec.sub(p.pos);
|
---|
| 321 | dist = distvec.length;
|
---|
[430] | 322 | if (dist < ExpParams.zone1_range)
|
---|
[380] | 323 | {
|
---|
[430] | 324 | if (n[i].value != null)
|
---|
| 325 | {
|
---|
| 326 | energyTransfer(cr, n[i].value);
|
---|
| 327 | eating = 1;
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 | else if (eating == 0 && cr.user2["hibernated"] == 0 && dist < mindist)
|
---|
| 331 | {
|
---|
[401] | 332 | mindist = dist;
|
---|
| 333 | mindistvec = distvec.clone();
|
---|
[380] | 334 | }
|
---|
| 335 | }
|
---|
| 336 |
|
---|
[430] | 337 | if (!eating && cr.user2["hibernated"] == 0)
|
---|
| 338 | {
|
---|
| 339 | mindistvec.normalize();
|
---|
| 340 | mindistvec.scale(-0.08);
|
---|
| 341 | cr.localDrive = mindistvec;
|
---|
| 342 | moveEnergyDec(cr);
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[422] | 345 | return 1;
|
---|
[380] | 346 | }
|
---|
[422] | 347 |
|
---|
| 348 | else
|
---|
| 349 | return 0;
|
---|
| 350 | }
|
---|
[401] | 351 |
|
---|
[422] | 352 | function moveEnergyDec(cr)
|
---|
| 353 | {
|
---|
[430] | 354 | if (cr.user2["hibernated"] == 0)
|
---|
[422] | 355 | {
|
---|
[430] | 356 | cr.energy_m += ExpParams.energy_move * max_chamber_energ[cr.user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)];
|
---|
[422] | 357 | }
|
---|
[421] | 358 | }
|
---|
[380] | 359 |
|
---|
[422] | 360 | function foramMove(cr)
|
---|
[421] | 361 | {
|
---|
[422] | 362 | //TODO moving inside sediment?
|
---|
[421] | 363 |
|
---|
[422] | 364 | //adjustment in z axis
|
---|
[430] | 365 | cr.moveAbs(cr.pos_x, cr.pos_y, 0);
|
---|
[421] | 366 |
|
---|
[430] | 367 | //are there any nutrients in zone 1 or 2?
|
---|
[401] | 368 | {
|
---|
[422] | 369 | var moved = stepToNearest(ExpParams.zone2_range); //TODO weighted sum of distance and energy
|
---|
| 370 | if (moved==1)
|
---|
[430] | 371 | {
|
---|
[422] | 372 | return;
|
---|
| 373 | }
|
---|
[401] | 374 | }
|
---|
| 375 |
|
---|
[422] | 376 | //no nutrients in zone 2
|
---|
| 377 | var hibernation = 0;
|
---|
| 378 | if (cr.user2["gen"] == 0) hibernation = cr.user1["hibernation"];
|
---|
| 379 | else hibernation = cr.user1[0]["hibernation"];
|
---|
| 380 | //hibernation
|
---|
| 381 | if (hibernation == 1)
|
---|
[401] | 382 | {
|
---|
[430] | 383 | reverseHib(cr);
|
---|
[422] | 384 | cr.localDrive = XYZ.new(0,0,0);
|
---|
[380] | 385 | }
|
---|
[422] | 386 | //random move
|
---|
[430] | 387 | else if (cr.lifespan%dir_change == 0)
|
---|
[380] | 388 | {
|
---|
[430] | 389 | var dir = (Math.rndUni(-ExpParams.zone2_range, ExpParams.zone2_range), Math.rndUni(-ExpParams.zone2_range, ExpParams.zone2_range), 0);//(0.1 * Math.rnd01, 0.1 * Math.rnd01, 0);
|
---|
| 390 | dir.normalize();
|
---|
| 391 | dir.scale(-0.08);
|
---|
| 392 | cr.localDrive = dir;
|
---|
[422] | 393 | moveEnergyDec(cr);
|
---|
| 394 | }
|
---|
| 395 | }
|
---|
[401] | 396 |
|
---|
[430] | 397 | function energyTransfer(cr1, cr2)
|
---|
[422] | 398 | {
|
---|
[430] | 399 | cr1.localDrive = XYZ.new(0,0,0);
|
---|
| 400 | var e = cr2.getPart(0).ing * ExpParams.feedtrans; //TODO efficiency dependent on age
|
---|
| 401 | e = Math.min(cr2.energy, e) + 0.0000001;
|
---|
| 402 | //Simulator.print("transferring "+e+" to "+cr1.name+" from "+cr2.name+" ("+cr2.energy+")");
|
---|
| 403 | cr2.energy_m = cr2.energy_m + e;
|
---|
| 404 | cr1.energy_p = cr1.energy_p + e;
|
---|
| 405 | if (cr1.user2["hibernated"] == 1)
|
---|
[422] | 406 | {
|
---|
[430] | 407 | reverseHib(cr1);
|
---|
[422] | 408 | }
|
---|
| 409 | }
|
---|
[401] | 410 |
|
---|
[430] | 411 | function reverseHib(cr)
|
---|
| 412 | {
|
---|
| 413 | if (cr.user2["hibernated"] == 1)
|
---|
| 414 | {
|
---|
| 415 | setForamMeta(cr, cr.user2["gen"]); //unhibernate
|
---|
| 416 | }
|
---|
| 417 | else
|
---|
| 418 | {
|
---|
| 419 | cr.idleen = ExpParams.energy_hib * max_chamber_energ[cr.user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)]; //hibernate
|
---|
| 420 | }
|
---|
| 421 | cr.user2["hibernated"] = 1 - cr.user2["hibernated"];
|
---|
| 422 | }
|
---|
| 423 |
|
---|
[422] | 424 | function onForamsStep(cr)
|
---|
| 425 | {
|
---|
| 426 | cr.getMechPart(0).orient.set(o);
|
---|
[430] | 427 | if (ExpParams.showRet == 1)
|
---|
| 428 | cr.user3.moveAbs(cr.center_x-ExpParams.zone1_range, cr.center_y-ExpParams.zone1_range, cr.center_z-ExpParams.zone1_range-getProperty(cr.user2["gen"], "chamber_proculus"));
|
---|
[422] | 429 |
|
---|
| 430 | if (deathConditions(cr) == 1)
|
---|
| 431 | {
|
---|
| 432 | Populations[0].kill(cr);
|
---|
| 433 | return;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | foramMove(cr);
|
---|
| 437 |
|
---|
[430] | 438 | var repro = foramReproduce(cr);
|
---|
| 439 | if (repro == 1)
|
---|
| 440 | {
|
---|
| 441 | return;
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[422] | 444 | cr.user2["max_energy_level"] = Math.max(cr.energy, cr.user2["max_energy_level"]);
|
---|
[430] | 445 | if (lastChamberNum(cr) <= chambers[0].size-1)
|
---|
[422] | 446 | {
|
---|
[430] | 447 | if ((cr.user2["max_energy_level"] >= max_chamber_energ[cr.user2["gen"]][lastChamberNum(cr)]))
|
---|
[401] | 448 | {
|
---|
[430] | 449 | foramGrow(cr, lastChamberNum(cr));
|
---|
[422] | 450 | }
|
---|
[430] | 451 | }
|
---|
[380] | 452 | }
|
---|
| 453 |
|
---|
[422] | 454 | function deathConditions(cr)
|
---|
| 455 | {
|
---|
| 456 | if ((cr.energy <= ExpParams.e_death_level) || (Math.rnd01 < ExpParams.hunted_prob))
|
---|
| 457 | return 1;
|
---|
| 458 | else
|
---|
| 459 | return 0;
|
---|
| 460 | }
|
---|
| 461 |
|
---|
[421] | 462 | function onForamsDied(cr)
|
---|
[380] | 463 | {
|
---|
[430] | 464 | if (ExpParams.showRet == 1)
|
---|
| 465 | {
|
---|
| 466 | Populations[2].delete(cr.user3);
|
---|
| 467 | }
|
---|
[380] | 468 | //fossilization
|
---|
| 469 | var geno = GenePools[0].add(cr.genotype);
|
---|
| 470 | geno.user1 = cr.user1;
|
---|
| 471 | geno.user2 = cr.user2;
|
---|
[418] | 472 | if (ExpParams.logging == 1) Simulator.print("\"" + cr.name + "\" died...");
|
---|
[380] | 473 | ExpState.totaltestedcr++;
|
---|
| 474 | }
|
---|
| 475 |
|
---|
[421] | 476 | // --------------------------------foram end -------------------------------------
|
---|
[380] | 477 |
|
---|
[421] | 478 | // -------------------------------- nutrient begin --------------------------------
|
---|
[380] | 479 |
|
---|
[422] | 480 | function createNutrientGenotype(nutrientsize, zone1_range)
|
---|
| 481 | {
|
---|
[430] | 482 | return "//0\np:sh=3,sx="+(nutrientsize+25)+",sy="+nutrientsize+",sz="+nutrientsize+",ry=1.5,vr=0.0,1.0,0.0";
|
---|
[422] | 483 | }
|
---|
| 484 |
|
---|
[421] | 485 | function onNutrientsStep(cr)
|
---|
[380] | 486 | {
|
---|
[422] | 487 | cr.moveAbs(cr.pos_x % ExpParams.world_size, cr.pos_y % ExpParams.world_size, -ExpParams.zone1_range+0.5);
|
---|
[380] | 488 | }
|
---|
| 489 |
|
---|
[421] | 490 | function addNutrient()
|
---|
[380] | 491 | {
|
---|
[422] | 492 | var cr = Populations[1].add(createNutrientGenotype(ExpParams.nutrientsize, ExpParams.zone1_range));
|
---|
[380] | 493 |
|
---|
[421] | 494 | cr.name = "Nutrients";
|
---|
[380] | 495 | cr.idleen = 0;
|
---|
[422] | 496 | cr.energy0 = ExpParams.energy_nut;
|
---|
[416] | 497 | cr.energy = cr.energy0;
|
---|
[421] | 498 | cr.signals.add("nutrient");
|
---|
[380] | 499 |
|
---|
[430] | 500 | cr.signals[0].value = cr;
|
---|
[380] | 501 |
|
---|
[422] | 502 | placeCreatureRandomly(cr, 0, 0);
|
---|
[380] | 503 | }
|
---|
| 504 |
|
---|
[422] | 505 | function nutrientGrowth()
|
---|
[380] | 506 | {
|
---|
[422] | 507 | nutrientenergywaiting = nutrientenergywaiting + ExpParams.feedrate;
|
---|
| 508 | if (nutrientenergywaiting > ExpParams.energy_nut)
|
---|
[380] | 509 | {
|
---|
[422] | 510 | for (var i = 0; i < ExpParams.nutrientPop; i++)
|
---|
| 511 | {
|
---|
| 512 | addNutrient();
|
---|
| 513 | }
|
---|
| 514 |
|
---|
| 515 | nutrientenergywaiting = 0.0;
|
---|
| 516 | Simulator.checkpoint();
|
---|
[380] | 517 | }
|
---|
| 518 | }
|
---|
| 519 |
|
---|
[421] | 520 | // -------------------------------- nutrient end --------------------------------
|
---|
[380] | 521 |
|
---|
[422] | 522 | // -------------------------------- step begin --------------------------------
|
---|
[380] | 523 |
|
---|
[422] | 524 | function onStep()
|
---|
| 525 | {
|
---|
| 526 | if (ExpParams.logging == 1)
|
---|
| 527 | {
|
---|
| 528 | createStatistics();
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | nutrientGrowth();
|
---|
| 532 |
|
---|
| 533 | //reproduction --------------------------------------------
|
---|
| 534 | reprocounter += 1;
|
---|
| 535 | if (reprocounter > ExpParams.repro_time)
|
---|
| 536 | {
|
---|
| 537 | reprocounter = 0;
|
---|
| 538 | reproduce_parents(0);
|
---|
| 539 | reproduce_parents(1);
|
---|
| 540 | }
|
---|
| 541 |
|
---|
| 542 | //check for extinction -----------------------------------------------
|
---|
| 543 | if (Populations[0].size == 0)
|
---|
| 544 | {
|
---|
| 545 | if (ExpParams.autorestart)
|
---|
| 546 | {
|
---|
| 547 | Simulator.print("no more creatures, restarting...");
|
---|
| 548 | onExpInit();
|
---|
| 549 | }
|
---|
| 550 | else
|
---|
| 551 | {
|
---|
| 552 | Simulator.print("no more creatures, stopped.");
|
---|
| 553 | Simulator.stop();
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
[430] | 556 | if (Simulator.stepNumber == 150000)
|
---|
| 557 | Simulator.stop();
|
---|
[422] | 558 | }
|
---|
| 559 |
|
---|
| 560 | function createStatistics()
|
---|
| 561 | {
|
---|
[430] | 562 | var number = [[0, 0],[0,0]]; // [species][gen]
|
---|
| 563 | var e_inc = [[0, 0],[0,0]];
|
---|
[422] | 564 | var e_nut = 0.0;
|
---|
| 565 |
|
---|
| 566 | for (var i = 0; i < Populations[0].size; i++)
|
---|
| 567 | {
|
---|
| 568 | var cr = Populations[0].get(i);
|
---|
| 569 | var gen = cr.user2["gen"];
|
---|
| 570 | var species = cr.user2["species"];
|
---|
[430] | 571 |
|
---|
| 572 | number[species][gen] = number[species][gen] + 1;
|
---|
| 573 | e_inc[species][gen] = e_inc[species][gen] + cr.energy;
|
---|
[422] | 574 | }
|
---|
| 575 |
|
---|
| 576 | for (var i = 0; i < Populations[1].size; i++)
|
---|
| 577 | {
|
---|
| 578 | var cr = Populations[1].get(i);
|
---|
| 579 | e_nut += cr.energy;
|
---|
| 580 | }
|
---|
| 581 |
|
---|
[430] | 582 | var log_numbers = [number[0][0], number[0][1], number[1][0], number[1][1], Populations[1].size];
|
---|
| 583 | var log_energies = [e_inc[0][0], e_inc[0][1], e_inc[1][0], e_inc[1][1], e_nut];
|
---|
[422] | 584 |
|
---|
[430] | 585 | log(log_numbers, "forams_log.txt");
|
---|
| 586 | log(log_energies, "energies_log.txt");
|
---|
[422] | 587 | }
|
---|
| 588 |
|
---|
[380] | 589 | function log(tolog, fname)
|
---|
| 590 | {
|
---|
[430] | 591 | var f = File.appendDirect(fname, "forams data");
|
---|
[380] | 592 | f.writeString("" + Simulator.stepNumber);
|
---|
[401] | 593 | for (var i = 0; i < tolog.size; i++)
|
---|
[380] | 594 | {
|
---|
| 595 | f.writeString(";" + tolog[i]);
|
---|
| 596 | }
|
---|
| 597 | f.writeString("\n");
|
---|
| 598 | f.close();
|
---|
| 599 | }
|
---|
| 600 |
|
---|
[422] | 601 | // -------------------------------- step end --------------------------------
|
---|
[380] | 602 |
|
---|
[401] | 603 | @include "standard_events.inc"
|
---|
[380] | 604 |
|
---|
[401] | 605 | ~
|
---|
[380] | 606 |
|
---|
[401] | 607 | prop:
|
---|
[430] | 608 | id:showRet
|
---|
| 609 | name:Show reticulopodia
|
---|
| 610 | type:d 0 1 0
|
---|
| 611 | group:Foraminifera
|
---|
| 612 |
|
---|
| 613 | prop:
|
---|
[422] | 614 | id:e_repro_cost_haplo
|
---|
[423] | 615 | name:Cost of reproduction
|
---|
[422] | 616 | type:f 0.1 0.9 0.5
|
---|
[421] | 617 | group:Foraminifera
|
---|
[380] | 618 |
|
---|
[401] | 619 | prop:
|
---|
[422] | 620 | id:e_repro_cost_diplo
|
---|
[423] | 621 | name:Cost of reproduction
|
---|
[422] | 622 | type:f 0.1 0.9 0.3
|
---|
| 623 | group:Foraminifera
|
---|
[380] | 624 |
|
---|
[401] | 625 | prop:
|
---|
[422] | 626 | id:chamber_proculus_haplo
|
---|
[423] | 627 | name:Size of proculus
|
---|
[422] | 628 | type:f
|
---|
[421] | 629 | group:Foraminifera
|
---|
[380] | 630 |
|
---|
[401] | 631 | prop:
|
---|
[422] | 632 | id:chamber_proculus_diplo
|
---|
[423] | 633 | name:Size of proculus
|
---|
[422] | 634 | type:f
|
---|
[380] | 635 | group:Foraminifera
|
---|
| 636 |
|
---|
| 637 | prop:
|
---|
[422] | 638 | id:chamber_difference_haplo
|
---|
[423] | 639 | name:Difference in size between subsequent chambers
|
---|
[422] | 640 | type:f
|
---|
[380] | 641 | group:Foraminifera
|
---|
| 642 |
|
---|
| 643 | prop:
|
---|
[422] | 644 | id:chamber_difference_diplo
|
---|
[423] | 645 | name:Difference in size between subsequent chambers
|
---|
[422] | 646 | type:f
|
---|
[380] | 647 | group:Foraminifera
|
---|
| 648 |
|
---|
| 649 | prop:
|
---|
[422] | 650 | id:hunted_prob
|
---|
| 651 | name:Probability of being hunted
|
---|
| 652 | type:f 0 1 0
|
---|
| 653 | group:Forminifera
|
---|
[380] | 654 |
|
---|
| 655 | prop:
|
---|
[422] | 656 | id:zone1_range
|
---|
| 657 | name:Zone 1 range
|
---|
| 658 | type:f 0 200
|
---|
| 659 | group:Foraminifera
|
---|
[380] | 660 |
|
---|
| 661 | prop:
|
---|
[422] | 662 | id:zone2_range
|
---|
| 663 | name:Zone 2 range
|
---|
| 664 | type:f 0 3000
|
---|
[421] | 665 | group:Foraminifera
|
---|
[380] | 666 |
|
---|
| 667 | prop:
|
---|
[422] | 668 | id:colors
|
---|
| 669 | name:Haploid and diploid colors
|
---|
| 670 | type:x
|
---|
[380] | 671 | group:Foraminifera
|
---|
| 672 |
|
---|
| 673 | prop:
|
---|
[422] | 674 | id:min_repro_energ_haplo
|
---|
| 675 | name:Min reproduction energy of forams
|
---|
| 676 | type:f
|
---|
[380] | 677 | group:Foraminifera
|
---|
| 678 |
|
---|
| 679 | prop:
|
---|
[422] | 680 | id:min_repro_energ_diplo
|
---|
| 681 | name:Min reproduction energy of forams
|
---|
| 682 | type:f
|
---|
| 683 | group:Foraminifera
|
---|
| 684 |
|
---|
| 685 | prop:
|
---|
[380] | 686 | id:repro_prob
|
---|
[401] | 687 | name:Probability of reproduction
|
---|
[422] | 688 | type:f 0 1 0.8
|
---|
[421] | 689 | group:Foraminifera
|
---|
[380] | 690 |
|
---|
| 691 | prop:
|
---|
[422] | 692 | id:energies0_haplo
|
---|
| 693 | name:Energy of offspring from diploid forams
|
---|
| 694 | type:f
|
---|
| 695 | group:Foraminifera
|
---|
| 696 |
|
---|
| 697 | prop:
|
---|
| 698 | id:energies0_diplo
|
---|
| 699 | name:Energy of offspring from diploid forams
|
---|
| 700 | type:f
|
---|
| 701 | group:Foraminifera
|
---|
| 702 |
|
---|
| 703 | prop:
|
---|
| 704 | id:energy_hib
|
---|
| 705 | name:Energy used for hibernation during one step
|
---|
| 706 | type:f 0 1 0.001
|
---|
| 707 | group:Foraminifera
|
---|
| 708 |
|
---|
| 709 | prop:
|
---|
| 710 | id:energy_move
|
---|
| 711 | name:Energy used for movement during one step
|
---|
| 712 | type:f 0 20 0.001
|
---|
| 713 | group:Foraminifera
|
---|
| 714 |
|
---|
| 715 | prop:
|
---|
| 716 | id:min_vol
|
---|
| 717 | name:Minimal volume for reproduction
|
---|
| 718 | type:f 100 900 100
|
---|
| 719 | group:Foraminifera
|
---|
| 720 |
|
---|
| 721 | prop:
|
---|
| 722 | id:max_size
|
---|
| 723 | name:Maximal size
|
---|
| 724 | type:d 1 10 5
|
---|
| 725 | group:Foraminifera
|
---|
| 726 |
|
---|
| 727 | prop:
|
---|
| 728 | id:foramPop
|
---|
| 729 | name:Initial forams population size
|
---|
| 730 | type:d 1 1000 100
|
---|
| 731 | group:Foraminifera
|
---|
| 732 |
|
---|
| 733 | prop:
|
---|
[380] | 734 | id:crossprob
|
---|
[401] | 735 | name:Crossover probability
|
---|
| 736 | type:f 0 1 0
|
---|
[421] | 737 | group:Foraminifera
|
---|
[380] | 738 |
|
---|
| 739 | prop:
|
---|
[401] | 740 | id:mutationprob
|
---|
| 741 | name:Mutation probability
|
---|
| 742 | type:f 0 1 0
|
---|
[421] | 743 | group:Foraminifera
|
---|
[401] | 744 |
|
---|
| 745 | prop:
|
---|
[422] | 746 | id:e_death_level
|
---|
[423] | 747 | name:Minimal level of energy to sustain life
|
---|
| 748 | type:f 0 20 0
|
---|
[380] | 749 | group:Foraminifera
|
---|
| 750 |
|
---|
| 751 | prop:
|
---|
| 752 | id:e_meta
|
---|
| 753 | name:Idle metabolism
|
---|
| 754 | type:f 0 1
|
---|
| 755 | group:Energy
|
---|
| 756 | help:Each stick consumes this amount of energy in one time step
|
---|
| 757 |
|
---|
| 758 | prop:
|
---|
| 759 | id:feedrate
|
---|
| 760 | name:Feeding rate
|
---|
| 761 | type:f 0 100
|
---|
| 762 | group:Energy
|
---|
| 763 | help:How fast energy is created in the world
|
---|
| 764 |
|
---|
| 765 | prop:
|
---|
[422] | 766 | id:energy_nut
|
---|
[428] | 767 | name:Nutrient energy
|
---|
[422] | 768 | type:f 0 1000
|
---|
[380] | 769 | group:Energy
|
---|
| 770 |
|
---|
| 771 | prop:
|
---|
| 772 | id:feedtrans
|
---|
| 773 | name:Ingestion multiplier
|
---|
[422] | 774 | type:f 0 100
|
---|
[380] | 775 | group:Energy
|
---|
[422] | 776 |
|
---|
| 777 | prop:
|
---|
| 778 | id:nutrientsize
|
---|
[428] | 779 | name:Nutrient size
|
---|
[423] | 780 | type:f 0.1 0.9 0.1
|
---|
[422] | 781 | group:Energy
|
---|
| 782 |
|
---|
| 783 | prop:
|
---|
[421] | 784 | id:nutrientPop
|
---|
[428] | 785 | name:Nutrient population size
|
---|
[421] | 786 | group:Energy
|
---|
| 787 | type:d 1 1000 10
|
---|
| 788 |
|
---|
[422] | 789 | prop:
|
---|
| 790 | id:world_size
|
---|
| 791 | name:World size
|
---|
[430] | 792 | type:d 10 10000 20
|
---|
[422] | 793 | group:World
|
---|
| 794 |
|
---|
| 795 | prop:
|
---|
| 796 | id:stress
|
---|
| 797 | name:Environmental stress
|
---|
| 798 | type:d 0 1 1
|
---|
| 799 | group:World
|
---|
| 800 |
|
---|
| 801 | prop:
|
---|
| 802 | id:repro_trigger
|
---|
| 803 | name:Reproduction trigger
|
---|
| 804 | type:d 0 1 1
|
---|
| 805 | group:World
|
---|
| 806 |
|
---|
| 807 | prop:
|
---|
| 808 | id:repro_time
|
---|
| 809 | name:Time before reproduction
|
---|
| 810 | type:d 0 1000
|
---|
| 811 |
|
---|
| 812 | prop:
|
---|
| 813 | id:creath
|
---|
| 814 | name:Creation height
|
---|
| 815 | type:f -1 50
|
---|
| 816 | help:~
|
---|
| 817 | Vertical position (above the surface) where new Forams are revived.
|
---|
| 818 | Negative values are only used in the water area:
|
---|
| 819 | 0 = at the surface
|
---|
| 820 | -0.5 = half depth
|
---|
| 821 | -1 = just above the bottom~
|
---|
| 822 |
|
---|
[421] | 823 | state:
|
---|
| 824 | id:nutrient
|
---|
[428] | 825 | name:Nutrient locations
|
---|
[421] | 826 | help:vector of vectors [x,y,energy]
|
---|
| 827 | type:x
|
---|
| 828 | flags:32
|
---|
| 829 |
|
---|
| 830 | prop:
|
---|
[380] | 831 | id:autorestart
|
---|
| 832 | name:Restart after extinction
|
---|
| 833 | help:Restart automatically this experiment after the last creature has died?
|
---|
| 834 | type:d 0 1
|
---|
| 835 |
|
---|
| 836 | state:
|
---|
| 837 | id:notes
|
---|
| 838 | name:Notes
|
---|
| 839 | type:s 1
|
---|
| 840 | help:~
|
---|
| 841 | You can write anything here
|
---|
| 842 | (it will be saved to the experiment file)~
|
---|
| 843 |
|
---|
| 844 | state:
|
---|
| 845 | id:totaltestedcr
|
---|
[421] | 846 | name:Evaluated Forams
|
---|
| 847 | help:Total number of the Forams evaluated in the experiment
|
---|
[380] | 848 | type:d
|
---|
| 849 | flags:16
|
---|
| 850 |
|
---|
[404] | 851 | prop:
|
---|
[421] | 852 | id:logging
|
---|
| 853 | name:Log statistics to file
|
---|
| 854 | type:d 0 1 0
|
---|