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