Changeset 404 for experiments/frams/foraminifera/data/scripts
- Timestamp:
- 06/30/15 23:02:42 (9 years ago)
- Location:
- experiments/frams/foraminifera/data/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/foraminifera/data/scripts/forams_benthic.expdef
r402 r404 34 34 global foodenergywaiting; 35 35 global reprocounter; 36 global delta_change;37 36 38 37 @include "forams_repro.inc" … … 53 52 pop.name = "Creatures"; 54 53 pop.en_assim = 0; 55 pop.nnsim = 1;54 pop.nnsim = 0; 56 55 pop.enableperf = 1; 57 56 pop.death = 1; … … 70 69 pop.othermask = 0x10000; 71 70 72 73 var size_h = ExpParams.haplo_rad * ExpParams.delta_rate + ExpParams.haplo_rad; 74 var size_d = ExpParams.diplo_rad * ExpParams.delta_rate + ExpParams.diplo_rad; 75 ExpParams.gend = "//0\np:sh=1,sx=" + ExpParams.diplo_rad + ",sy=" + ExpParams.diplo_rad + ",sz=" + ExpParams.diplo_rad + ", rz=3.14159265358979"; 76 ExpParams.genh = "//0\np:sh=1,sx=" + size_h + ",sy=" + size_h + ",sz=" + size_h + ", rz=3.14159265358979"; 71 //radius of the chamber 72 ExpParams.rads = [1.2, 0.6]; 73 //inital genotypes 74 ExpParams.genh = "//0\np:sh=1,sx=" + ExpParams.rads[0] + ",sy=" + ExpParams.rads[0] + ",sz=" + ExpParams.rads[0] + ", rz=3.14159265358979"; 75 ExpParams.gend = "//0\np:sh=1,sx=" + ExpParams.rads[1] + ",sy=" + ExpParams.rads[1] + ",sz=" + ExpParams.rads[1] + ", rz=3.14159265358979"; 76 ExpParams.gend += "\nn:p=0,d=\"S\""; 77 77 ExpParams.e_meta = 0.1; 78 78 ExpParams.feedrate = 0.5; … … 91 91 ExpParams.v_min_d = 300; 92 92 ExpParams.v_min_h = 300; 93 //radius of the chamber94 ExpParams.haplo_rad = 1.2;95 ExpParams.diplo_rad = 0.6;96 93 //minimal age for reproduction 97 94 ExpParams.age_min_d = 100; … … 104 101 ExpParams.repro_thr = 1; 105 102 106 //size change rate107 ExpParams.delta_rate = 0.1;108 103 //grwoth speed in time steps 109 104 ExpParams.growth_step = 50; … … 118 113 World.wrldsiz = ExpParams.wsize; 119 114 World.wrldbnd = 1; 120 121 delta_change = 0.5;122 115 } 123 116 … … 136 129 cr.energ0 = ExpParams.v_min_h - ExpParams.repro_thr; 137 130 cr.energy = cr.energ0; 138 cr.user1 = {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h , "delta_h" : ExpParams.haplo_rad * ExpParams.delta_rate, "delta_d" : ExpParams.diplo_rad * ExpParams.delta_rate};139 cr.user2 = {"Va" : ExpParams.v_min_h - ExpParams.repro_thr, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams. haplo_rad, "vinit" : ExpParams.v_min_h - ExpParams.repro_thr};131 cr.user1 = {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}; 132 cr.user2 = {"Va" : ExpParams.v_min_h - ExpParams.repro_thr, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit" : ExpParams.v_min_h - ExpParams.repro_thr}; 140 133 } 141 134 ExpState.totaltestedcr = 0; … … 230 223 cr.signals.add("repro"); 231 224 cr.signals[0].power = 1; 232 233 225 } 234 226 235 227 function onCreaturesStep(cr) 236 228 { 237 cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis 229 //TODO moving inside sediment? 230 cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis 238 231 var p = cr.getMechPart(0); 239 232 var n = cr.signals.receiveSet("food", ExpParams.food_range); … … 276 269 if (cr.energy > 100) 277 270 { 271 //TODO energy costs dependant on size 278 272 // cr.energy_m = cr.user2["Va"]/cr.user2["vinit"]; 279 273 } … … 281 275 if (cr.lifespan >= ExpParams.max_age) 282 276 { 277 //TODO what is max age value? should there be one? 283 278 Populations[0].kill(cr); 279 return; 284 280 } 285 281 286 282 //foram growth 287 else if (cr.lifespan == cr.user2["growth_step"]) 288 { 289 var pos = [cr.center_x, cr.center_y, cr.center_z]; 290 var energy = cr.energy; 291 var cr2 = null; 292 if (cr.user2["gen"] == 0) 293 { 294 var new_r = ExpParams.haplo_rad * Math.min(Math.max(cr.user2["Va"] / cr.user2["vinit"] * 0.5, 1), 2.5); 295 cr.user2["rsize"] = new_r; 296 cr2 = Populations[0].add("//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979"); 297 cr2.user1 = {"vamin" : cr.user1["vamin"], "amin": cr.user1["amin"], "delta_h" : cr.user1["delta_h"], "delta_d" : cr.user1["delta_d"]}; 298 } 299 else if (cr.user2["gen"] == 1) 300 { 301 var new_r = ExpParams.diplo_rad * Math.min(Math.max(cr.user2["Va"] / cr.user2["vinit"] * 0.5, 1), 2.5); 302 cr.user2["rsize"] = new_r; 303 304 var geno = "//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979"; 305 geno += "\nn:p=0,d=\"S\""; //TODO is this the only difference with haploid code? TODO why initial genotypes are not used as defined in ExpParams? 283 if (cr.lifespan == cr.user2["growth_step"]) 284 { 285 //TODO how size is related to the energy? 286 cr.user2["rsize"] = ExpParams.rads[cr.user2["gen"]] * Math.min(Math.max(float(cr.user2["Va"] / cr.user2["vinit"]) * 0.5, 1.0), 2.5); 287 var geno = "//0\np:sh=1,sx=" + cr.user2["rsize"] + ",sy=" + cr.user2["rsize"] + ",sz=" + cr.user2["rsize"] + ", rz=3.14159265358979"; 288 if (cr.user2["gen"] == 1) 289 { 290 geno += "\nn:p=0,d=\"S\""; //TODO why initial genotypes are not used as defined in ExpParams? 306 291 //TODO maybe it would be nice if they rotated so the "S" would show where they are going (direction/intention) 307 cr2 = Populations[0].add(geno); 308 309 310 cr2.user1 = [ {"vamin" : cr.user1[0]["vamin"], "amin": cr.user1[0]["amin"], "delta_h" : cr.user1[0].get("delta_h"), "delta_d" : cr.user1[0]["delta_d"] }, {"vamin" : cr.user1[1]["vamin"], "amin": cr.user1[1]["amin"], "delta_h" : cr.user1[1]["delta_h"], "delta_d" : cr.user1[1]["delta_d"] }]; 311 } 312 cr2.energy = energy; 313 cr2.user2 = {"Va" : cr.user2["Va"], "gen" : cr.user2["gen"], "growth_step" : cr.user2["growth_step"], "rsize" : cr.user2["rsize"], "vinit": cr.user2["vinit"]}; 292 } 293 var cr2 = Populations[0].add(geno); 294 cr2.energy = cr.energy; 295 setGenotype(cr2, cr.user1, cr.user2); 314 296 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z); 315 297 … … 355 337 } 356 338 339 function setGenotype(cr, new_user1, new_user2) 340 { 341 cr.user2 = {"Va" : new_user2["Va"], "gen" : new_user2["gen"], "growth_step" : new_user2["growth_step"], "rsize" : new_user2["rsize"], "vinit": new_user2["vinit"]}; 342 if (cr.user2["gen"] == 0) 343 { 344 cr.user1 = {"vamin" : new_user1["vamin"], "amin": new_user1["amin"] }; 345 } 346 else if (cr.user2["gen"] == 1) 347 { 348 cr.user1 = [ {"vamin" : new_user1[0]["vamin"], "amin": new_user1[0]["amin"] }, {"vamin" : new_user1[1]["vamin"], "amin": new_user1[1]["amin"] }]; 349 } 350 351 } 352 357 353 // -------------------------------- creature end -------------------------------- 358 354 … … 376 372 cr.signals[0].value = cr.getMechPart(0); 377 373 378 var retry = 100; //try 100 times 379 while (retry--) 380 { 381 placeCreatureRandomly(cr, 0, 0); 382 if (!cr.boundingBoxCollisions(0)) 383 return cr; 384 } 385 386 return cr; 374 placeRandomlyNotColliding(cr); 387 375 } 388 376 … … 395 383 Collision.Creature1.energy_m = Collision.Creature1.energy_m + e; 396 384 Collision.Creature2.energy_p = Collision.Creature2.energy_p + e; 397 var ener = float(Collision.Creature2.user2["Va"]); 398 var sum = float(float(ener) + float(e)); 399 Collision.Creature2.user2["Va"] = float(sum); 385 Collision.Creature2.user2["Va"] = float(Collision.Creature2.user2["Va"]) + float(e); 400 386 } 401 387 } … … 434 420 435 421 prop: 436 id:haplo_rad437 name:Haploid radius438 type:f 0.1 3 1.2439 440 prop:441 422 id:growth_step 442 423 name:Growth step 443 type:d 50 10000 1000 444 445 prop: 446 id:delta_rate 447 name:Delta rate 448 type:f 0.0001 0.1 0.001 449 450 prop: 451 id:diplo_rad 452 name:Diploid radius 453 type:f 0.1 3 0.6 454 455 prop: 456 id:foodPop 457 name:Food size 458 type:d 1 1000 10 459 460 prop: 461 id:age_min 462 name:Minimal age for reproduction 463 type:d 100 10000 200 424 type:d 10 10000 1000 425 426 prop: 427 id:rads 428 name: haploid and diploid radius 429 type:x 464 430 465 431 prop: … … 489 455 prop: 490 456 id:repro_thr 491 name: Threshold for reproduction457 name:amount of energy initial creatures need to gather to reproduce 492 458 type:d 1 1000 1 493 459 … … 615 581 flags:16 616 582 583 prop: 584 id:foodPop 585 name:food size 586 type:d 1 1000 10 587 617 588 state: 618 589 id:food -
experiments/frams/foraminifera/data/scripts/forams_repro.inc
r403 r404 4 4 // -------------------------------- step begin -------------------------------- 5 5 6 function reproduce_haploid(repro_list , number)6 function reproduce_haploid(repro_list) 7 7 { 8 8 var len = repro_list.size; … … 14 14 var parent2 = Populations[0].get(repro_list[i + 1]); 15 15 16 number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd; 16 var number = parent.user2["Va"] / ExpParams.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd; 17 17 18 for (var j = 0; j < number; j++) 18 19 { 19 //size 20 var rsize = (parent.user1["delta_d"] + ExpParams.diplo_rad); 21 if (Math.rnd01 < 0.5) 22 { 23 rsize = parent2.user1["delta_d"] + ExpParams.diplo_rad; 24 } 25 26 var deltas = parent.user1["delta_d"]; 27 //mutation 28 if (Math.rnd01 < ExpParams.mutationprob) 29 { 30 var diff = delta_change * deltas; 31 if (Math.rnd01 < 0.5) 32 { 33 deltas -= diff; 34 } 35 else 36 { 37 deltas += diff; 38 } 39 rsize = ExpParams.diplo_rad + deltas; 40 } 41 42 var geno = "//0\np:sh=1,sx=" + rsize + ",sy=" + rsize + ",sz=" + rsize + ", rz=3.14159265358979"; 43 geno += "\nn:p=0,d=\"S\""; //TODO is this the only difference with haploid code? TODO why initial genotypes are not used as defined in ExpParams? 44 var cr = Populations[0].add(geno); 45 cr.energ0 = ExpParams.ofnumd; 46 cr.energy = cr.energ0; 47 var dsize = ExpParams.diplo_rad * ExpParams.delta_rate + ExpParams.diplo_rad; 48 cr.user1 = [ {"vamin" : (rsize / dsize) * ExpParams.v_min_d, "amin": parent.user1["amin"], "delta_h" : parent.user1["delta_h"], "delta_d" : deltas }, {"vamin" : (rsize / dsize) * ExpParams.v_min_d, "amin": parent2.user1["amin"], "delta_h" : parent2.user1["delta_h"], "delta_d" : deltas }]; 49 cr.user2 = { "Va" : cr.energ0, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": rsize, "vinit": cr.energ0}; 50 placeRandomlyNotColliding(cr); 51 } 52 } 53 54 for (var j = 0; j < repro_list.size; j++) 55 { 56 Populations[0].kill(repro_list[j]); 57 } 58 } 59 60 function reproduce_diploid(repro_list, number) 20 createOffspring(ExpParams.gend, ExpParams.ofnumd, [parent.user1, parent2.user1], {"Va" : ExpParams.ofnumd, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.ofnumd}); //TODO genes from both generations in user1 21 } 22 } 23 killParents(repro_list); 24 } 25 26 function reproduce_diploid(repro_list) 61 27 { 62 28 for (var i = 0; i < repro_list.size; i++) … … 64 30 var parent = Populations[0].get(repro_list[i]); 65 31 32 if (parent.user2["gen"] != 1) 33 { 34 Simulator.print("gen: " + parent.user2["gen"]); 35 } 36 66 37 if (parent.user2["gen"] == 1) 67 38 { 68 69 39 var number = parent.user2["Va"] / ExpParams.ofnumh; 70 71 72 40 for (var j = 0; j < number / 2; j++) 73 41 { … … 76 44 if (Math.rnd01 < ExpParams.crossprob) 77 45 { 78 var tmp = parent.user1[0]["vamin"]; 79 parent.user1[0]["vamin"] = parent.user1[1]["vamin"]; 80 parent.user1[1]["vamin"] = tmp; 46 crossover(parent, "vamin"); 81 47 crossed = 1; 82 48 } … … 84 50 for (var k = 0; k < 2; k++) 85 51 { 86 var rsize = parent.user1[k]["delta_h"] + ExpParams.haplo_rad; 87 var vamin = parent.user1[k]["vamin"]; 88 var deltas = parent.user1[k]["delta_h"]; 89 90 91 if (Math.rnd01 < ExpParams.mutationprob) 92 { 93 var diff = delta_change * deltas; 94 if (Math.rnd01 < 0.5) 95 { 96 deltas -= diff; 97 } 98 else 99 { 100 deltas += diff; 101 } 102 rsize = ExpParams.diplo_rad + deltas; 103 } 104 105 var geno = "//0\np:sh=1,sx=" + rsize + ",sy=" + rsize + ",sz=" + rsize + ", rz=3.14159265358979"; 106 var cr = Populations[0].add(geno); 107 cr.energ0 = ExpParams.ofnumh; 108 cr.energy = cr.energ0; 109 //vamin depends on rsize 110 var hsize = ExpParams.haplo_rad * ExpParams.delta_rate + ExpParams.haplo_rad; 111 cr.user1 = {"vamin" : (rsize / hsize) * ExpParams.v_min_h, "amin": ExpParams.age_min_d, "delta_h" : deltas, "delta_d" : parent.user1[0]["delta_d"]}; 112 cr.user2 = { "Va" : cr.energ0, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : rsize, "vinit": cr.energ0}; 113 placeRandomlyNotColliding(cr); 52 createOffspring(ExpParams.genh, ExpParams.ofnumh, {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}, {"Va" : ExpParams.ofnumh, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.ofnumh}); 114 53 } 115 54 … … 117 56 if (crossed == 1) 118 57 { 119 var tmp = parent.user1[0]["vamin"]; 120 parent.user1[0]["vamin"] = parent.user1[1]["vamin"]; 121 parent.user1[1]["vamin"] = tmp; 58 crossover(parent, "vamin"); 122 59 crossed = 0; 123 60 } 124 125 61 } 126 62 } 127 63 } 64 killParents(repro_list); 65 } 66 67 function crossover(parent, gene) 68 { 69 var tmp = parent.user1[0][gene]; 70 parent.user1[0][gene] = parent.user1[1][gene]; 71 parent.user1[1][gene] = tmp; 72 } 73 74 function killParents(repro_list) 75 { 128 76 for (var j = 0; j < repro_list.size; j++) 129 77 { … … 132 80 } 133 81 82 function createOffspring(geno, energy, new_user1, new_user2) 83 { 84 var cr = Populations[0].add(geno); 85 cr.energ0 = energy; 86 cr.energy = cr.energ0; 87 setGenotype(cr, new_user1, new_user2); 88 placeRandomlyNotColliding(cr); 89 } 134 90 135 91 function onStep() … … 152 108 haploids += 1; 153 109 e_inc_h += cr.energy; 154 size_h += cr.user1["delta_h"] + ExpParams.haplo_rad;110 size_h += ExpParams.rads[0]; //TODO change of size dependant on gene 155 111 vmin_h += cr.user1["vamin"]; 156 112 } … … 159 115 diploids += 1; 160 116 e_inc_d += cr.energy; 161 size_d += cr.user1[0]["delta_d"] + ExpParams.diplo_rad;117 size_d += ExpParams.rads[1]; //TODO change of size dependant on gene 162 118 vmin_d += cr.user1[0]["vamin"]; 163 119 } … … 219 175 to_repro_h.add(i); 220 176 } 221 elseif (cr.user2["gen"] == 1)177 if (cr.user2["gen"] == 1) 222 178 { 223 179 to_repro_d.add(i); … … 227 183 if (to_repro_h.size > 1) 228 184 { 229 reproduce_haploid(to_repro_h , ExpParams.ofnumh);185 reproduce_haploid(to_repro_h); 230 186 } 231 187 if (to_repro_d.size > 0) 232 188 { 233 reproduce_diploid(to_repro_d , ExpParams.ofnumd);189 reproduce_diploid(to_repro_d); 234 190 } 235 191 }
Note: See TracChangeset
for help on using the changeset viewer.