Changeset 422 for experiments
- Timestamp:
- 08/24/15 19:57:12 (9 years ago)
- Location:
- experiments/frams/foraminifera/data/scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/foraminifera/data/scripts/foraminifera.expdef
r421 r422 6 6 user1: 7 7 genes which are not encoded in Ff genotype: 8 min energy - Minimum storedenergy necessary for reproduction9 minage - minimal age for reproduction 8 min_repro_energy - Minimum energy necessary for reproduction 9 hibernation - Defines foram behavior in the case of no nutrients 10 10 11 11 user2: 12 12 Physiological parameters of foraminifera: 13 Va - amount of the stored energy 13 max_energy_level - maximum energy level reached so far 14 14 gen - generation: 0 haploid, 1 diploid 15 species - species: 0 not hibernating 1 hibernating 16 hibernated - 0/1 foram isn't/is hibernated 17 reproduce - 0/1 foram isn't/is ready for reproduction 15 18 ~ 16 19 code:~ … … 28 31 global nutrientenergywaiting; 29 32 global reprocounter; 33 global colors; 34 global chambers; 35 global o; 36 global max_chamber_energ; 37 30 38 31 39 @include "foraminifera.inc" … … 39 47 Populations.clear(); 40 48 GenePools[0].name = "Unused"; 41 42 SignalView.mode = 1;43 49 44 50 var pop = Populations[0]; … … 52 58 pop.othermask = 0x20001; 53 59 //pop.selfmask = 0x20002; pop.othermask = 0x10002; 54 pop.perfperiod = 25; 60 pop.perfperiod = 25; 55 61 56 62 pop = Populations.addGroup("Nutrients"); … … 61 67 pop.selfmask = 0x20002; 62 68 pop.othermask = 0x10000; 63 64 //radius of the chamber 65 ExpParams.rads = [1.2, 0.6]; 66 //inital genotypes 67 ExpParams.genh = createForamGenotype(ExpParams.rads[0]); 68 ExpParams.gend = createForamGenotype(ExpParams.rads[1])+"\nn:p=0,d=\"S\""; 69 //pop.othermask = 0x10002; 70 71 //world 72 SignalView.mode = 1; 73 ExpParams.world_size = 100; 74 World.wrldwat = ExpParams.world_size; 75 World.wrldsiz = ExpParams.world_size; 76 World.wrldbnd = 1; 77 ExpParams.stress = 1; 69 78 ExpParams.creath = -0.99; //just above the bottom 70 ExpParams.e_meta = 0.1;71 ExpParams.feedrate = 0.5;72 ExpParams.feede0 = 100;73 ExpParams.feedtrans = 3;74 ExpParams.nutrientsize = 0.1;75 ExpParams.nutrientgen = "//0\np:sh=2,sx="+ExpParams.nutrientsize+",sy="+ExpParams.nutrientsize+",sz="+ExpParams.nutrientsize+"\nn:d=T,p=0";76 79 ExpParams.autorestart = 0; 77 ExpParams.popsize = 10; 80 78 81 //ExpParams.logging = 1; //uncomment to enable logging simulation parameters to log files 79 82 80 //number of offspring 81 ExpParams.energy0h = 40; 82 ExpParams.energy0d = 25; 83 //minial volume for reproduction 84 ExpParams.minenerg = [300, 300]; 85 //minimal age for reproduction 86 ExpParams.minage = [100, 100]; 87 //crossover probability 83 //reproduction 84 ExpParams.foramPop = 3; 88 85 ExpParams.crossprob = 0.4; 89 //mutation probability90 86 ExpParams.mutationprob = 0.2; 91 ExpParams.repro_time = 45; 92 93 //grwoth speed in simulation steps 94 ExpParams.growth_step = 50; 95 87 ExpParams.repro_time = 20; 88 reprocounter = 0; 89 90 //morphology 91 init_chambers(); 92 ExpParams.chamber_proculus_haplo = scale(60); 93 ExpParams.chamber_difference_haplo = 0.0; 94 ExpParams.chamber_proculus_diplo = scale(20); 95 ExpParams.chamber_difference_diplo = 0.2; 96 max_chamber_energ = [Vector.new(), Vector.new()]; 97 for (var j = 0; j < 2; j++) 98 { 99 for (var i = 0; i < chambers[0].size; i++) 100 { 101 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); 102 103 } 104 } 105 ExpParams.zone1_range = scale(250); 106 ExpParams.zone2_range = scale(5000); 107 108 //energetics 109 ExpParams.min_repro_energ_haplo = max_chamber_energ[0][2]; 110 ExpParams.min_repro_energ_diplo = max_chamber_energ[1][8]; 111 ExpParams.e_meta = 0.00003 * max_chamber_energ[0][0]; 112 ExpParams.energy_hib = 0.00003 * max_chamber_energ[0][0]; 113 ExpParams.energy_move = 0.0003 * max_chamber_energ[0][0]; 114 ExpParams.energies0_haplo = max_chamber_energ[0][0] - 0.1*max_chamber_energ[0][0]; 115 ExpParams.energies0_diplo = max_chamber_energ[1][0] - 0.1*max_chamber_energ[1][0]; 116 ExpParams.feedtrans = 0.05; 117 ExpParams.e_repro_cost_haplo = 0.5; 118 ExpParams.e_repro_cost_diplo = 0.3; 119 120 //nutrients 121 ExpParams.nutrientsize = scale(10); 122 ExpParams.energy_nut = 100 * Math.pow(ExpParams.nutrientsize, 3); 123 ExpParams.nutrientPop = 10; 124 ExpParams.feedrate = 0.0025; 125 nutrientenergywaiting = ExpParams.energy_nut; 96 126 ExpState.totaltestedcr = 0; 97 127 ExpState.nutrient = ""; 98 nutrientenergywaiting = ExpParams.feede0;99 reprocounter = 0;100 101 ExpParams.worldsize = 50;102 World.wrldwat = 50;103 World.wrldsiz = ExpParams.worldsize;104 World.wrldbnd = 1;105 128 } 106 129 107 130 @include "standard_placement.inc" 131 132 function scale(x) 133 { 134 return x*0.025; 135 } 136 137 function getProperty(gen, prop_id) 138 { 139 var ploid = "haplo"; 140 if (gen == 1) ploid = "diplo"; 141 return ExpParams.[prop_id + "_" + ploid]; 142 } 143 144 function addInitialForam(species, i) 145 { 146 var geno = createForamGenotype(0, species, 0); 147 var cr = Populations[0].add(geno); 148 cr.name = "Initial creature" + species + "_" + i; 149 placeCreatureRandomly(cr, 0, 0); 150 cr.energy0 = getProperty(0, "energies0"); 151 cr.energy = cr.energy0; 152 setGenotype({"opt" : 0, "cr" : cr, "species" : species}); 153 } 108 154 109 155 function onExpInit() … … 112 158 Populations[1].clear(); 113 159 114 for (var i = 0; i < ExpParams.popsize; i++) 115 { 116 var cr = Populations[0].add(ExpParams.genh); 117 cr.name = "Initial creature" + i; 118 placeCreatureRandomly(cr, 0, 0); 119 cr.energy0 = ExpParams.energy0h; 120 cr.energy = cr.energy0; 121 cr.user1 = {"minenergy" : ExpParams.minenerg[0], "minage": ExpParams.minage[0]}; 122 cr.user2 = {"Va" : ExpParams.energy0h, "gen" : 0, "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit" : ExpParams.energy0h}; 123 } 160 for (var i = 0; i < ExpParams.foramPop; i++) 161 { 162 addInitialForam(0, i); 163 addInitialForam(1, i); 164 } 165 o = Populations[0][0].getMechPart(0).orient.clone(); 124 166 ExpState.totaltestedcr = 0; 125 nutrientenergywaiting = ExpParams. feede0;167 nutrientenergywaiting = ExpParams.energy_nut; 126 168 } 127 169 … … 191 233 // -------------------------------- foram begin ----------------------------------- 192 234 193 function createForamGenotype(radius)194 {195 return "//0\np:sh=1,sx=" + radius + ",sy=" + radius + ",sz=" + radius + ", rz=3.14159265358979";196 }197 198 235 function onForamsBorn(cr) 199 236 { … … 214 251 } 215 252 216 function readyToRepro(cr) 217 { 218 cr.signals.add("repro"); 219 cr.signals[0].power = 1; 220 } 221 222 function foramMove(cr) 223 { 224 //TODO moving inside sediment? 225 cr.moveAbs(cr.pos_x, cr.pos_y, 0); //adjustment in z axis 226 253 function foramGrow(cr, chamber_num) 254 { 255 var geno = createForamGenotype(cr.user2["gen"], cr.user2["species"], chamber_num); 256 var cr2 = Populations[0].add(geno); 257 258 cr2.energy0 = cr.energy; 259 cr2.energy = cr2.energy0; 260 261 setGenotype({"cr" : cr2, "parent_user1" : cr.user1, "parent_user2" : cr.user2, "opt" : 2}); 262 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z); 263 264 Populations[0].delete(cr); 265 } 266 267 function stepToNearest(cr, range) 268 { 227 269 var p = cr.getMechPart(0); 228 var n = cr.signals.receiveSet("nutrient", ExpParams. nutrient_range);270 var n = cr.signals.receiveSet("nutrient", ExpParams.zone2_range); 229 271 230 272 //if signals are received find the source of the nearest 231 273 if (n.size > 0) 232 274 { 233 234 275 var i; 235 276 var mp; … … 255 296 mindistvec.scale(-0.08); 256 297 cr.localDrive = mindistvec; 257 } 258 298 return 1; 299 } 300 259 301 else 302 return 0; 303 } 304 305 function moveEnergyDec(cr) 306 { 307 if (cr.user2["hibernated"] == 1) 308 { 309 cr.energy_m += ExpParams.energy_hib; 310 } 311 else 312 { 313 cr.energy_m += ExpParams.energy_move; 314 } 315 } 316 317 function foramMove(cr) 318 { 319 //TODO moving inside sediment? 320 321 //adjustment in z axis 322 cr.moveAbs(cr.pos_x, cr.pos_y, 0.5); 323 324 //are there any nutrients in zone 1? 325 if (cr.boundingBoxCollisions() == 2) 326 { 327 if (cr.user2["hibernated"] == 1) 328 cr.user2["hibernated"] = 0; 329 return; 330 } 331 332 else if (cr.user2["hibernated"] == 1) 333 { 334 moveEnergyDec(cr); 335 return; 336 } 337 338 //are there any nutrients in zone 2? 339 else 340 { 341 var moved = stepToNearest(ExpParams.zone2_range); //TODO weighted sum of distance and energy 342 if (moved==1) 343 { 344 moveEnergyDec(cr); 345 return; 346 } 347 } 348 349 //no nutrients in zone 2 350 351 var hibernation = 0; 352 if (cr.user2["gen"] == 0) hibernation = cr.user1["hibernation"]; 353 else hibernation = cr.user1[0]["hibernation"]; 354 //hibernation 355 if (hibernation == 1) 356 { 357 moveEnergyDec(cr); 358 cr.user2["hibernated"] = 1; 359 cr.localDrive = XYZ.new(0,0,0); 360 } 361 //random move 362 else 260 363 { 261 364 cr.localDrive = (0.1 * Math.rnd01, 0.1 * Math.rnd01, 0); 262 } 263 } 264 265 function foramGrow(cr) 266 { 267 //TODO how size is related to the energy? 268 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); 269 var geno = createForamGenotype(cr.user2["rsize"]); 270 if (cr.user2["gen"] == 1) 365 moveEnergyDec(cr); 366 } 367 } 368 369 function onForamsCollision() 370 { 371 if (Collision.Creature1.user2 != null) 372 { 373 Collision.Creature1.localDrive = XYZ.new(0,0,0); 374 var e = Collision.Part2.ing * ExpParams.feedtrans; //TODO efficiency dependent on age 375 //Simulator.print("transferring "+e+" to "+Collision.Creature1.name+" from "+Collision.Creature2.name+" ("+Collision.Creature2.energy+")"); 376 Collision.Creature2.energy_m = Collision.Creature2.energy_m + e; 377 Collision.Creature1.energy_p = Collision.Creature1.energy_p + e; 378 Collision.Creature1.user2["hibernated"] = 0; 379 } 380 } 381 382 function onForamsStep(cr) 383 { 384 cr.getMechPart(0).orient.set(o); 385 386 if (deathConditions(cr) == 1) 387 { 388 Populations[0].kill(cr); 389 return; 390 } 391 392 foramMove(cr); 393 394 cr.user2["max_energy_level"] = Math.max(cr.energy, cr.user2["max_energy_level"]); 395 if (cr.numparts <= chambers[0].size) 396 { 397 if ((cr.user2["max_energy_level"] >= max_chamber_energ[cr.user2["gen"]][cr.numparts-1])) 271 398 { 272 geno += "\nn:p=0,d=\"S\""; //TODO why initial genotypes are not used as defined in ExpParams? 273 //TODO maybe it would be nice if they rotated so the "S" would show where they are going (direction/intention) 274 } 275 var cr2 = Populations[0].add(geno); 276 cr2.energy0 = cr.energy; 277 cr2.energy = cr2.energy0; 278 setGenotype(cr2, cr.user1, cr.user2); 279 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z); 280 281 Populations[0].delete(cr); 282 } 283 284 function onForamsStep(cr) 285 { 286 foramMove(cr); 287 288 //energy costs depend on size 289 if (cr.energy > 100) 290 { 291 //TODO energy costs dependent on size 292 // cr.energy_m = cr.user2["Va"]/cr.user2["vinit"]; 293 } 294 295 //TODO lifespan should not be used, it is set to 0 with every growth_step 296 if (cr.lifespan >= ExpParams.max_age) 297 { 298 //TODO what is max age value? should there be one 299 //Populations[0].kill(cr); 300 //return; 301 } 302 303 //foram growth 304 if (cr.lifespan == cr.user2["growth_step"]) 305 { 306 foramGrow(cr); 307 } 399 foramGrow(cr, cr.numparts); 400 return; 401 } 402 } 403 404 foramReproduce(cr); 405 } 406 407 function deathConditions(cr) 408 { 409 if ((cr.energy <= ExpParams.e_death_level) || (Math.rnd01 < ExpParams.hunted_prob)) 410 return 1; 308 411 else 309 { 310 var properSize = 0; 311 312 if (cr.user2["gen"] == 0) 313 { 314 properSize = cr.user2["Va"] >= cr.user1["minenergy"]; 315 } 316 else 317 { 318 properSize = cr.user2["Va"] >= cr.user1[0]["minenergy"]; //TODO gene selection 319 } 320 321 //if creature has proper age and cytoplasm amount 322 if ( properSize ) 323 { 324 //reproduce with probability repro_prob 325 if (Math.rnd01 <= ExpParams.repro_prob) 326 { 327 readyToRepro(cr); 328 } 329 } 330 if ( properSize && (cr.signals.receive("repro") > 0)) 331 { 332 readyToRepro(cr); 333 } 334 } 412 return 0; 335 413 } 336 414 … … 345 423 } 346 424 347 function setGenotype(cr, new_user1, new_user2)348 {349 cr.user2 = {"Va" : new_user2["Va"], "gen" : new_user2["gen"], "growth_step" : new_user2["growth_step"], "rsize" : new_user2["rsize"], "vinit": new_user2["vinit"]};350 if (cr.user2["gen"] == 0)351 {352 cr.user1 = {"minenergy" : new_user1["minenergy"], "minage": new_user1["minage"] };353 }354 else if (cr.user2["gen"] == 1)355 {356 cr.user1 = [ {"minenergy" : new_user1[0]["minenergy"], "minage": new_user1[0]["minage"] }, {"minenergy" : new_user1[1]["minenergy"], "minage": new_user1[1]["minage"] }];357 }358 359 }360 361 425 // --------------------------------foram end ------------------------------------- 362 426 363 427 // -------------------------------- nutrient begin -------------------------------- 364 428 429 function createNutrientGenotype(nutrientsize, zone1_range) 430 { 431 return "//0\np:sh=3,sx="+nutrientsize+",sy="+(zone1_range + nutrientsize)+",sz="+(zone1_range+nutrientsize)+",ry=1.5,vr=0.0,1.0,0.0"; 432 } 433 365 434 function onNutrientsStep(cr) 366 435 { 367 cr.moveAbs(cr.pos_x % ExpParams.world size, cr.pos_y % ExpParams.worldsize,0.5);436 cr.moveAbs(cr.pos_x % ExpParams.world_size, cr.pos_y % ExpParams.world_size, -ExpParams.zone1_range+0.5); 368 437 } 369 438 370 439 function addNutrient() 371 440 { 372 var cr = Populations[1].add( ExpParams.nutrientgen);441 var cr = Populations[1].add(createNutrientGenotype(ExpParams.nutrientsize, ExpParams.zone1_range)); 373 442 374 443 cr.name = "Nutrients"; 375 444 cr.idleen = 0; 376 cr.energy0 = ExpParams. feede0;445 cr.energy0 = ExpParams.energy_nut; 377 446 cr.energy = cr.energy0; 378 447 cr.signals.add("nutrient"); … … 380 449 cr.signals[0].value = cr.getMechPart(0); 381 450 382 placeRandomlyNotColliding(cr); 383 } 384 385 function onNutrientsCollision() 386 { 387 if (Collision.Creature2.user2 != null) 388 { 389 var e = Collision.Part2.ing * ExpParams.feedtrans; 390 //Simulator.print("transferring "+e+" from "+Collision.Creature1.name+" to "+Collision.Creature2.name+" ("+Collision.Creature2.energy+")"); 391 Collision.Creature1.energy_m = Collision.Creature1.energy_m + e; 392 Collision.Creature2.energy_p = Collision.Creature2.energy_p + e; 393 Collision.Creature2.user2["Va"] = float(Collision.Creature2.user2["Va"]) + float(e); 451 placeCreatureRandomly(cr, 0, 0); 452 } 453 454 function nutrientGrowth() 455 { 456 nutrientenergywaiting = nutrientenergywaiting + ExpParams.feedrate; 457 if (nutrientenergywaiting > ExpParams.energy_nut) 458 { 459 for (var i = 0; i < ExpParams.nutrientPop; i++) 460 { 461 addNutrient(); 462 } 463 464 nutrientenergywaiting = 0.0; 465 Simulator.checkpoint(); 394 466 } 395 467 } … … 397 469 // -------------------------------- nutrient end -------------------------------- 398 470 471 // -------------------------------- step begin -------------------------------- 472 473 function onStep() 474 { 475 if (ExpParams.logging == 1) 476 { 477 createStatistics(); 478 } 479 480 nutrientGrowth(); 481 482 //reproduction -------------------------------------------- 483 reprocounter += 1; 484 if (reprocounter > ExpParams.repro_time) 485 { 486 reprocounter = 0; 487 reproduce_parents(0); 488 reproduce_parents(1); 489 } 490 491 //check for extinction ----------------------------------------------- 492 if (Populations[0].size == 0) 493 { 494 if (ExpParams.autorestart) 495 { 496 Simulator.print("no more creatures, restarting..."); 497 onExpInit(); 498 } 499 else 500 { 501 Simulator.print("no more creatures, stopped."); 502 Simulator.stop(); 503 } 504 } 505 } 506 507 function createStatistics() 508 { 509 var number_ploidy = [0, 0]; 510 var number_species = [0, 0]; 511 var e_inc = [0.0, 0.0]; 512 var e_nut = 0.0; 513 514 for (var i = 0; i < Populations[0].size; i++) 515 { 516 var cr = Populations[0].get(i); 517 var gen = cr.user2["gen"]; 518 number_ploidy[gen] = number_ploidy[gen] + 1; 519 var species = cr.user2["species"]; 520 number_species[species] = number_species[species] + 1; 521 e_inc[gen] = e_inc[gen] + cr.energy; 522 } 523 524 for (var i = 0; i < Populations[1].size; i++) 525 { 526 var cr = Populations[1].get(i); 527 e_nut += cr.energy; 528 } 529 530 var log_numbers = [number_ploidy[0], number_ploidy[1], Populations[1].size]; 531 var log_species = [number_species[0], number_species[1]]; 532 var log_energy = [e_inc[0], e_inc[1], e_nut]; 533 534 log(log_numbers, "log_sizes.txt"); 535 log(log_species, "log_species.txt"); 536 log(log_energy, "log_energy.txt"); 537 } 399 538 400 539 function log(tolog, fname) … … 410 549 } 411 550 412 413 551 // -------------------------------- step end -------------------------------- 414 552 415 553 @include "standard_events.inc" … … 418 556 419 557 prop: 420 id:max_age 421 name:Maximal age 422 type:d 100 1000 500 423 group:Foraminifera 424 425 prop: 426 id:worldsize 558 id:e_repro_cost_haplo 559 name:cost of reproduction 560 type:f 0.1 0.9 0.5 561 group:Foraminifera 562 563 prop: 564 id:e_repro_cost_diplo 565 name:cost of reproduction 566 type:f 0.1 0.9 0.3 567 group:Foraminifera 568 569 prop: 570 id:chamber_proculus_haplo 571 name:size of proculus 572 type:f 573 group:Foraminifera 574 575 prop: 576 id:chamber_proculus_diplo 577 name:size of proculus 578 type:f 579 group:Foraminifera 580 581 prop: 582 id:chamber_difference_haplo 583 name:difference in size between subsequent chambers 584 type:f 585 group:Foraminifera 586 587 prop: 588 id:chamber_difference_diplo 589 name:difference in size between subsequent chambers 590 type:f 591 group:Foraminifera 592 593 prop: 594 id:hunted_prob 595 name:Probability of being hunted 596 type:f 0 1 0 597 group:Forminifera 598 599 prop: 600 id:zone1_range 601 name:Zone 1 range 602 type:f 0 200 603 group:Foraminifera 604 605 prop: 606 id:zone2_range 607 name:Zone 2 range 608 type:f 0 3000 609 group:Foraminifera 610 611 prop: 612 id:colors 613 name:Haploid and diploid colors 614 type:x 615 group:Foraminifera 616 617 prop: 618 id:min_repro_energ_haplo 619 name:Min reproduction energy of forams 620 type:f 621 group:Foraminifera 622 623 prop: 624 id:min_repro_energ_diplo 625 name:Min reproduction energy of forams 626 type:f 627 group:Foraminifera 628 629 prop: 630 id:repro_prob 631 name:Probability of reproduction 632 type:f 0 1 0.8 633 group:Foraminifera 634 635 prop: 636 id:energies0_haplo 637 name:Energy of offspring from diploid forams 638 type:f 639 group:Foraminifera 640 641 prop: 642 id:energies0_diplo 643 name:Energy of offspring from diploid forams 644 type:f 645 group:Foraminifera 646 647 prop: 648 id:energy_hib 649 name:Energy used for hibernation during one step 650 type:f 0 1 0.001 651 group:Foraminifera 652 653 prop: 654 id:energy_move 655 name:Energy used for movement during one step 656 type:f 0 20 0.001 657 group:Foraminifera 658 659 prop: 660 id:min_vol 661 name:Minimal volume for reproduction 662 type:f 100 900 100 663 group:Foraminifera 664 665 prop: 666 id:max_size 667 name:Maximal size 668 type:d 1 10 5 669 group:Foraminifera 670 671 prop: 672 id:foramPop 673 name:Initial forams population size 674 type:d 1 1000 100 675 group:Foraminifera 676 677 prop: 678 id:crossprob 679 name:Crossover probability 680 type:f 0 1 0 681 group:Foraminifera 682 683 prop: 684 id:mutationprob 685 name:Mutation probability 686 type:f 0 1 0 687 group:Foraminifera 688 689 prop: 690 id:e_death_level 691 name:Level of energy ... death 692 type:f 0 693 group:Foraminifera 694 695 696 prop: 697 id:e_meta 698 name:Idle metabolism 699 type:f 0 1 700 group:Energy 701 help:Each stick consumes this amount of energy in one time step 702 703 prop: 704 id:feedrate 705 name:Feeding rate 706 type:f 0 100 707 group:Energy 708 help:How fast energy is created in the world 709 710 prop: 711 id:energy_nut 712 name:Nutrients's energy 713 type:f 0 1000 714 group:Energy 715 716 prop: 717 id:feedtrans 718 name:Ingestion multiplier 719 type:f 0 100 720 group:Energy 721 722 prop: 723 id:nutrientsize 724 name:Nutrients's size 725 type:f 0.1 726 group:Energy 727 728 prop: 729 id:e_meta 730 name:Idle metabolism 731 type:f 0 1 732 group:Energy 733 help:Each stick consumes this amount of energy in one time step 734 735 prop: 736 id:feedrate 737 name:Feeding rate 738 type:f 0 100 739 group:Energy 740 help:How fast energy is created in the world 741 742 prop: 743 id:feedtrans 744 name:Ingestion multiplier 745 group:Energy 746 type:f 0 100 747 748 prop: 749 id:nutrientsize 750 name:Nutrients's size 751 group:Energy 752 type:f 0.1 753 754 prop: 755 id:nutrientPop 756 name:Nutrients population size 757 group:Energy 758 type:d 1 1000 10 759 760 761 prop: 762 id:world_size 427 763 name:World size 428 764 type:d 10 1000 20 429 430 prop: 431 id:growth_step 432 name:Growth step 433 type:d -1 10000 1000 434 group:Foraminifera 435 help:You can turn off growth by setting this param to -1 436 437 prop: 438 id:rads 439 name:Haploid and diploid radius 440 type:x 441 group:Foraminifera 442 443 prop: 444 id:minage 445 name:Min reproduction age of forams 446 type:x 447 group:Foraminifera 448 449 prop: 450 id:minenerg 451 name:Min reproduction energy of forams 452 type:x 453 group:Foraminifera 454 455 prop: 456 id:nutrient_range 457 name:Range of nutrient smell 458 type:d 0 10000 10000 765 group:World 766 767 prop: 768 id:stress 769 name:Environmental stress 770 type:d 0 1 1 771 group:World 772 773 prop: 774 id:repro_trigger 775 name:Reproduction trigger 776 type:d 0 1 1 777 group:World 778 459 779 460 780 prop: … … 462 782 name:Time before reproduction 463 783 type:d 0 1000 464 465 prop:466 id:popsize467 name:Initial forams population size468 type:d 1 1000 100469 group:Foraminifera470 471 prop:472 id:energy0h473 name:Number of offspring from haploid forams474 type:d475 group:Foraminifera476 477 prop:478 id:energy0d479 name:Number of offspring from diploid forams480 type:d481 group:Foraminifera482 483 prop:484 id:repro_prob485 name:Probability of reproduction486 type:f 0 1 0.9487 group:Foraminifera488 489 prop:490 id:crossprob491 name:Crossover probability492 type:f 0 1 0493 group:Foraminifera494 495 prop:496 id:mutationprob497 name:Mutation probability498 type:f 0 1 0499 group:Foraminifera500 501 prop:502 id:genh503 name:Initial genotype of haploid forams504 type:s 1505 group:Foraminifera506 507 prop:508 id:gend509 name:Initial genotype of diploid forams510 type:s 1511 group:Foraminifera512 784 513 785 prop: … … 522 794 -1 = just above the bottom~ 523 795 524 prop:525 id:e_meta526 name:Idle metabolism527 type:f 0 1528 group:Energy529 help:Each stick consumes this amount of energy in one time step530 531 prop:532 id:feedrate533 name:Feeding rate534 type:f 0 100535 group:Energy536 help:How fast energy is created in the world537 538 prop:539 id:feede0540 name:Nutrients's energy541 group:Energy542 type:f 0 1000543 544 prop:545 id:feedtrans546 name:Ingestion multiplier547 group:Energy548 type:f 0 100549 550 prop:551 id:nutrientgen552 name:Nutrients's genotype553 group:Energy554 type:s 1555 556 prop:557 id:nutrientsize558 name:Nutrients's size559 group:Energy560 type:f 0.1561 562 prop:563 id:nutrientPop564 name:Nutrients population size565 group:Energy566 type:d 1 1000 10567 568 796 state: 569 797 id:nutrient -
experiments/frams/foraminifera/data/scripts/foraminifera.inc
r421 r422 2 2 //real proportions 3 3 4 // -------------------------------- step begin -------------------------------- 5 6 function reproduce_haploid(parent, parent2) 7 { 8 var number = parent.user2["Va"] / ExpParams.energy0d + parent2.user2["Va"] / ExpParams.energy0d; 4 function init_chambers() 5 { 6 colors = ["1.0,1.0,0.0","1.0,0.5,0.0"]; 7 chambers = [ ["//0\np:sh=1,", 8 "p:0.98089325428009, 0.00591040402650833, 0.00389722990803421,", 9 "p:1.90962779521942, -0.256769120693207, -0.16194811463356,", 10 "p:2.63965249061584, -0.727959632873535, -0.609036147594452,", 11 "p:3.17575979232788, -1.34843015670776, -1.14828503131866,", 12 "p:3.55273032188416, -2.22369408607483, -1.3917418718338,", 13 "p:3.64916682243347, -3.11888360977173, -1.01666414737701,", 14 "p:3.50461649894714, -3.84039807319641, -0.377427101135254,", 15 "p:3.15921688079834, -4.50001525878906, 0.261153399944305,", 16 "p:2.51528453826904, -5.16421365737915, 0.59241509437561,"], 17 ["//0\np:sh=1,", 18 "p:1.08020961284637, -0.0597195439040661, -0.0393781512975693,", 19 "p:1.08020961284637, -0.0597195439040661, -0.0393781512975693,", 20 "p:0.615013539791107, 0.778662621974945, 0.535521030426025,", 21 "p:0.488581955432892, 0.826426684856415, -0.381044268608093,", 22 "p:0.732419908046722, -0.0084995785728097, -1.02214300632477,", 23 "p:1.35288727283478, 0.875738024711609, -1.03719782829285,", 24 "p:0.342692613601685, 0.938660383224487, -1.45657968521118,", 25 "p:1.0958571434021, 0.316927701234818, -1.813929438591,", 26 "p:0.903768002986908, 1.11856341362, -2.53161096572876,", 27 "p:0.21014116704464, 0.295340299606323, -2.45328187942505,"] ]; 28 } 29 30 function createForamGenotype(gen, species, chamber_num) 31 { 32 var rad = getProperty(gen, "chamber_proculus"); 33 var geno = chambers[species][0] + "sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen]; 34 35 chamber_num = Math.min(chamber_num, chambers[species].size - 1); 36 37 for (var i = 0; i < chamber_num; i++) 38 { 39 rad = getProperty(gen, "chamber_proculus") + getProperty(gen, "chamber_difference") * (i + 1); 40 geno += "\n" + chambers[species][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen]; 41 } 42 43 for (var i = 0; i < chamber_num; i++) 44 { 45 geno += "\n" + "j:"+ i +", "+ (i+1) +", sh=1"; 46 } 47 if (species == 1) geno += "\nn:p=0,d=\"S\""; 48 49 return geno; 50 } 51 52 function setGenotype(mode) 53 { 54 if (mode["opt"] == 0) //initial 55 { 56 mode["cr"].user1 = {"min_repro_energies" : [getProperty(0, "min_repro_energ"), getProperty(1, "min_repro_energ")], "hibernation" : 1 - mode["species"]}; 57 mode["cr"].user2 = {"max_energy_level" : getProperty(0,"energies0"), "gen" : 0, "hibernated" : 0, "species" : mode["species"], "reproduce" : 0}; 58 } 59 else if (mode["opt"] == 1) //child 60 { 61 mode["cr"].user2 = {"max_energy_level" : getProperty(1 - mode["parent_user2"]["gen"],"energies0"), "gen" : 1 - mode["parent_user2"]["gen"], "hibernated" : 0, "species" : mode["parent_user2"]["species"], "reproduce" : 0}; 62 mode["cr"].user1 = mode["parent_user1"]; 63 } 64 else //grow 65 { 66 mode["cr"].user1 = mode["parent_user1"]; 67 mode["cr"].user2 = mode["parent_user2"]; 68 } 69 } 70 71 function reproduce_haploid(parent, parent2, clone) 72 { 73 var number, energy0, new_user1, gen; 74 if (clone == 1) 75 { 76 energy0 = getProperty(0,"energies0"); 77 number = getProperty(1, "e_repro_cost") * parent.energy / energy0; 78 new_user1 = parent.user1; 79 parent.user2["gen"] = 1 - parent.user2["gen"]; //because of reversal of "gen" in createOffspring function 80 gen = parent.user2["gen"]; 81 } 82 else 83 { 84 energy0 = getProperty(1,"energies0"); 85 number = getProperty(parent.user2["gen"], "e_repro_cost") * parent.energy / energy0 + getProperty(parent.user2["gen"], "e_repro_cost") * parent2.energy / energy0; 86 new_user1 = [parent.user1, parent2.user1]; 87 gen = 1 - parent.user2["gen"]; 88 } 89 90 Simulator.print("number of offspring: " + number); 9 91 10 92 for (var j = 0; j < number; j++) 11 93 { 12 createOffspring( ExpParams.gend, ExpParams.energy0d, [parent.user1, parent2.user1], {"Va" : ExpParams.energy0d, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.energy0d}); //TODO genes from both generations in user194 createOffspring(createForamGenotype(gen, parent.user2["species"], 0), energy0, new_user1, parent.user2); 13 95 } 14 96 } … … 16 98 function reproduce_diploid(parent) 17 99 { 18 var number = parent.user2["Va"] / ExpParams.energy0h; 100 var energy0 = getProperty(0,"energies0"); 101 var number = getProperty(parent.user2["gen"], "e_repro_cost") * parent.energy / energy0; 102 103 Simulator.print("number of offspring: " + number); 104 19 105 for (var j = 0; j < number / 2; j++) 20 106 { … … 23 109 if (Math.rnd01 < ExpParams.crossprob) 24 110 { 25 crossover(parent, "min energy");111 crossover(parent, "min_repro_energies"); 26 112 crossed = 1; 27 113 } … … 29 115 for (var k = 0; k < 2; k++) 30 116 { 31 createOffspring( ExpParams.genh, ExpParams.energy0h, {"minenergy" : ExpParams.minenerg[0], "minage": ExpParams.minage[0]}, {"Va" : ExpParams.energy0h, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.energy0h}); //TODO different vamin and amin for haploids and diploids?117 createOffspring(createForamGenotype(1 - parent.user2["gen"], parent.user2["species"], 0), energy0, parent.user1[0], parent.user2); 32 118 } 33 119 … … 35 121 if (crossed == 1) 36 122 { 37 crossover(parent, "min energy");123 crossover(parent, "min_repro_energies"); 38 124 crossed = 0; 39 125 } … … 42 128 } 43 129 44 function crossover(parent, gene) 45 { 46 var tmp = parent.user1[0][gene]; 47 parent.user1[0][gene] = parent.user1[1][gene]; 48 parent.user1[1][gene] = tmp; 49 } 50 51 52 function createOffspring(geno, energy, new_user1, new_user2) 53 { 54 var cr = Populations[0].add(geno); 55 cr.energy0 = energy; 56 cr.energy = cr.energy0; 57 setGenotype(cr, new_user1, new_user2); 58 placeRandomlyNotColliding(cr); 59 } 60 61 function onStep() 62 { 63 64 if (ExpParams.logging == 1) 65 { 66 createStatistics(); 67 } 68 69 //nutrient growth --------------------------------------------- 70 nutrientenergywaiting = nutrientenergywaiting + ExpParams.feedrate; 71 if (nutrientenergywaiting > ExpParams.feede0) 72 { 73 for (var i = 0; i < ExpParams.nutrientPop; i++) 74 { 75 addNutrient(); 76 } 77 78 nutrientenergywaiting = 0.0; 79 Simulator.checkpoint(); 80 } 81 82 //reproduction -------------------------------------------- 83 reprocounter += 1; 84 if (reprocounter > ExpParams.repro_time) 85 { 86 reprocounter = 0; 130 function reproduce_parents(species) 131 { 87 132 var parent1 = null; 88 133 var parent2 = null; … … 90 135 for (var i = pop.size-1; i >= 0; i--) 91 136 { 92 if (pop[i]. signals.size > 0)137 if (pop[i].user2["reproduce"] == 1 && pop[i].user2["species"] == species) 93 138 { 94 if (pop[i].user2["gen"]==1) 95 { 96 reproduce_diploid(pop[i]); 97 pop.kill(i); 139 if ((pop[i].user2["gen"]==1) || ((pop[i].user2["gen"]==0) && ExpParams.stress == 0)) 140 { 141 continue; 98 142 } 99 143 else if (parent1 == null) … … 107 151 else 108 152 { 109 reproduce_haploid(parent1, parent2); 153 reproduce_haploid(parent1, parent2, 0); 154 print_repro_info(parent1); 155 print_repro_info(parent2); 110 156 pop.kill(parent1); 111 157 pop.kill(parent2); … … 116 162 } 117 163 } 118 } 119 120 //check for death ----------------------------------------------- 121 if (Populations[0].size == 0) 122 { 123 if (ExpParams.autorestart) 124 { 125 Simulator.print("no more creatures, restarting..."); 126 onExpInit(); 127 } 128 else 129 { 130 Simulator.print("no more creatures, stopped."); 131 Simulator.stop(); 132 } 133 } 134 } 135 136 function createStatistics() 137 { 138 var haploids = 0; 139 var diploids = 0; 140 var e_inc_h = 0.0; 141 var e_inc_d = 0.0; 142 var e_nut = 0.0; 143 var size_h = 0.0; 144 var size_d = 0.0; 145 var vmin_h = 0.0; 146 var vmin_d = 0.0; 147 148 for (var i = 0; i < Populations[0].size; i++) 149 { 150 var cr = Populations[0].get(i); 151 if (cr.user2["gen"] == 0) 152 { 153 haploids += 1; 154 e_inc_h += cr.energy; 155 size_h += ExpParams.rads[0]; //TODO change of size dependent on gene 156 vmin_h += cr.user1["minenergy"]; 157 } 158 else if (cr.user2["gen"] == 1) 159 { 160 diploids += 1; 161 e_inc_d += cr.energy; 162 size_d += ExpParams.rads[1]; //TODO change of size dependent on gene 163 vmin_d += cr.user1[0]["minenergy"]; 164 } 165 } 166 167 for (var i = 0; i < Populations[1].size; i++) 168 { 169 var cr = Populations[1].get(i); 170 e_nut += cr.energy; 171 } 172 173 var l1 = [haploids, diploids, Populations[1].size]; 174 var l2 = [e_inc_h, e_inc_d, e_nut]; 175 var dp = diploids; 176 var hp = haploids; 177 if (dp == 0) dp = 0.000001; 178 if (hp == 0) hp = 0.000001; 179 var l3 = [size_h / hp, vmin_h / hp, size_d / dp, vmin_d / dp]; 180 181 log(l1, "log_sizes.txt"); 182 log(l2, "log_energy.txt"); 183 log(l3, "log_sizes_v.txt"); 184 } 185 // -------------------------------- step end -------------------------------- 164 } 165 166 function readyToRepro(cr) 167 { 168 var reproduced = 1; 169 170 171 if (cr.user2["gen"] == 1) 172 { 173 reproduce_diploid(cr); 174 } 175 176 else if (ExpParams.stress == 0) 177 { 178 reproduce_haploid(cr, null, 1); 179 } 180 181 else 182 { 183 if (cr.signals.size == 0) 184 { 185 cr.signals.add("repro"+cr.user2["species"]); 186 cr.signals[0].power = 1; 187 } 188 reproduced = 0; 189 cr.user2["reproduce"] = 1; 190 } 191 192 if (reproduced == 1) 193 { 194 print_repro_info(cr); 195 Populations[0].kill(cr); 196 } 197 198 return reproduced; 199 } 200 201 function print_repro_info(cr) 202 { 203 Simulator.print("Reproduced " + cr.user2["gen"] + " of species " + cr.user2["species"] + " energy: " + cr.energy); 204 } 205 206 function foramReproduce(cr) 207 { 208 var properEnergy = 0; 209 var reproduced = 0; 210 211 if (cr.user2["gen"] == 0) 212 { 213 properEnergy = ( cr.energy >= cr.user1["min_repro_energies"][cr.user2["gen"]] ); 214 } 215 else 216 { 217 properEnergy = ( cr.energy >= cr.user1[0]["min_repro_energies"][cr.user2["gen"]] ); //TODO gene selection 218 } 219 220 //if creature has proper energy 221 if ( properEnergy && cr.signals.size == 0) 222 { 223 //reproduce with probability repro_prob 224 if (Math.rnd01 <= ExpParams.repro_prob) //TODO env trigger 225 { 226 reproduced = readyToRepro(cr); 227 } 228 else if (cr.signals.receive("repro"+cr.user2["species"]) > 0) 229 { 230 reproduced = readyToRepro(cr); 231 } 232 if (reproduced == 1) 233 return; 234 } 235 236 else if (!properEnergy) 237 { 238 cr.signals.clear(); 239 cr.user2["reproduce"] = 0; 240 } 241 } 242 243 function crossover(parent, gene) 244 { 245 var tmp = parent.user1[0][gene]; 246 parent.user1[0][gene] = parent.user1[1][gene]; 247 parent.user1[1][gene] = tmp; 248 } 249 250 function createOffspring(geno, energy, parent_user1, parent_user2) 251 { 252 var cr = Populations[0].add(geno); 253 cr.energy0 = energy; 254 cr.energy = cr.energy0; 255 setGenotype({"cr" : cr, "parent_user1" : parent_user1, "parent_user2" : parent_user2, "opt" : 1}); 256 placeRandomlyNotColliding(cr); 257 } -
experiments/frams/foraminifera/data/scripts/foraminifera.show
r407 r422 2 2 name:Reproduction of benthic foraminifera 3 3 info:~ 4 Foraminifers are shown as green balls. Nutrients are tiny white boxes. 5 Foraminifers move towards nearest nutrients and try to accumulate a sufficient amount of energy to reproduce. 6 Haploid and diploid generations alternate. Diploid foraminifers have orange marks. 4 There are two species of Foraminiera: longitudal and coiled. First chamber of the longitudal species has 5 orange marks. Haploid and diploid generations alternate in both species. All chambers of the haploid generation 6 have the same size. In the diploid generation subsequent chambers are bigger than their predecessors. 7 Nutrients are green disks. Foraminifers move towards nearest nutrients and try to accumulate a sufficient 8 amount of energy to reproduce. 9 7 10 More information at www.framsticks.com/foraminifera 8 11 ~ … … 16 19 GLDisplay.minfps = 10; 17 20 } 18 19 function ShowParams_minimalVolume_set() 21 function ShowParams_nutrientPop_set() 20 22 { 21 switch (ShowParams. minimalVolume)23 switch (ShowParams.nutrientPop) 22 24 { 23 25 case 0: 24 ExpParams.v_min_h = 300; 25 ExpParams.v_min_d = 300; 26 ExpParams.nutrientPop = 5; 26 27 break; 27 28 case 1: 28 ExpParams.v_min_h = 150; 29 ExpParams.v_min_d = 500; 30 break; 31 } 32 } 33 34 function ShowParams_offspingNumber_set() 35 { 36 switch (ShowParams.offspingNumber) 37 { 38 case 0: 39 ExpParams.ofnumh = 300; 40 ExpParams.ofnumd = 300; 41 break; 42 case 1: 43 ExpParams.ofnumh = 150; 44 ExpParams.ofnumd = 500; 45 break; 46 } 47 } 48 49 function ShowParams_populationSize_set() 50 { 51 switch (ShowParams.populationSize) 52 { 53 case 0: 54 ExpParams.psize = 5; 55 break; 56 case 1: 57 ExpParams.psize = 10; 29 ExpParams.nutrientPop = 10; 58 30 break; 59 31 case 2: 60 ExpParams.psize = 15; 61 break; 62 case 3: 63 ExpParams.psize = 20; 32 ExpParams.nutrientPop = 15; 64 33 break; 65 34 } … … 71 40 { 72 41 case 0: 73 ExpParams.feedrate = 0. 5;42 ExpParams.feedrate = 0.001; 74 43 break; 75 44 case 1: 76 ExpParams.feedrate = 0. 7;45 ExpParams.feedrate = 0.0025; 77 46 break; 78 47 case 2: 79 ExpParams.feedrate = 0.9; 48 ExpParams.feedrate = 0.004; 49 break; 50 } 51 } 52 53 function ShowParams_feedTrans_set() 54 { 55 switch (ShowParams.feedTrans) 56 { 57 case 0: 58 ExpParams.feedtrans = 0.01; 59 break; 60 case 1: 61 ExpParams.feedtrans = 0.05; 62 break; 63 case 2: 64 ExpParams.feedtrans = 0.1; 65 break; 66 } 67 } 68 69 function ShowParams_nutrientEnerg_set() 70 { 71 switch (ShowParams.nutrientEnerg) 72 { 73 case 0: 74 ExpParams.energy_nut = 0.5; 75 break; 76 case 1: 77 ExpParams.energy_nut = 1.5; 78 break; 79 case 2: 80 ExpParams.energy_nut = 3.0; 81 break; 82 } 83 } 84 85 function ShowParams_stress_set() 86 { 87 switch (ShowParams.stress) 88 { 89 case 0: 90 ExpParams.stress = 0; 91 break; 92 case 1: 93 ExpParams.stress = 1; 80 94 break; 81 95 } … … 84 98 ~ 85 99 86 87 100 prop: 88 id:minimalVolume 89 name:Min reproduction energy haploid/diploid 90 type:f 0 1 ~300 / 300~150 / 500 91 92 prop: 93 id:populationSize 94 name:Initial population size 95 type:d 0 3 ~5~10~15~20 96 97 prop: 98 id:offspingNumber 99 name:Number of offspring haploi/diploid 100 type:d 0 2 ~20 / 4~10 / 5 101 id:nutrientPop 102 name:Nutrients amount 103 type:d 0 2 1 ~5~10~15 101 104 102 105 prop: 103 106 id:feedRate 104 107 name:Feeding rate 105 type:d 0 2 ~50~70~90 108 type:d 0 2 1 ~1~2~3 109 110 prop: 111 id:feedTrans 112 name:Energy transfer 113 type:d 0 2 1 ~0.01~0.05~0.1 114 115 prop: 116 id:nutrientEnerg 117 name:Nutrient energy 118 type:d 0 2 1 ~0.5~1.5~3 119 120 prop: 121 id:stress 122 name:Stress 123 type:d 0 1 1
Note: See TracChangeset
for help on using the changeset viewer.