Changeset 476 for experiments/frams
- Timestamp:
- 03/13/16 02:45:09 (9 years ago)
- Location:
- experiments/frams/foraminifera/data/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/foraminifera/data/scripts/foraminifera.expdef
r475 r476 6 6 7 7 Technical information: 8 Genes and parameter values which control reproduction are stored in user1 and user2fields.9 10 user1:8 Genes and parameter values which control reproduction are stored in data->genes and data->lifeparams fields. 9 10 genes: 11 11 genes which are not encoded in Ff genotype: 12 12 min_repro_energy - Minimum energy necessary for reproduction 13 13 hibernation - Defines foram behavior in the case of no nutrients 14 14 15 user2:15 lifeparams: 16 16 Physiological parameters of foraminifera: 17 17 max_energy_level - maximum energy level reached so far … … 220 220 { 221 221 //cr.rotate(0,0,Math.rnd01*Math.twopi); 222 if ((typeof(g. user1) == "Vector") && (g.user1.size >= 3))222 if ((typeof(g.data->genes) == "Vector") && (g.data->genes.size >= 3)) 223 223 { 224 224 // [x,y,energy] 225 cr.move(g. user1[0] - cr.center_x, g.user1[1] - cr.center_y, 0);226 cr.energy = g. user1[2];225 cr.move(g.data->genes[0] - cr.center_x, g.data->genes[1] - cr.center_y, 0); 226 cr.energy = g.data->genes[2]; 227 227 } 228 228 else … … 278 278 { 279 279 var ret = Populations[2].add("//0\np:sh=3,sx=0.01,sy="+ExpParams.zone1_range+",sz="+ExpParams.zone1_range+",ry=1.57,vr=1.0,1.0,1.0"); 280 cr. user3= ret;280 cr.data->reticulopodiacreature = ret; 281 281 } 282 282 } … … 299 299 var has_ret = 0; 300 300 301 if (cr. user3!= null)302 { 303 if (Populations[2].findUID(cr. user3.uid) != null)301 if (cr.data->reticulopodiacreature != null) 302 { 303 if (Populations[2].findUID(cr.data->reticulopodiacreature.uid) != null) 304 304 { 305 305 has_ret = 1; … … 312 312 function foramGrow(cr, chamber_num) 313 313 { 314 if ((chamber_num+1) < chambers[cr. user2["species"]].size)315 { 316 var geno = createForamGenotype(cr. user2["gen"], cr.user2["species"], chamber_num+1);314 if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size) 315 { 316 var geno = createForamGenotype(cr.data->lifeparams->gen, cr.data->lifeparams->species, chamber_num+1); 317 317 var cr2 = Populations[0].add(geno); 318 318 … … 320 320 cr2.energy = cr2.energy0; 321 321 322 setGenotype({"cr" : cr2, "parent_ user1" : cr.user1, "parent_user2" : cr.user2, "opt" : 2});322 setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2}); 323 323 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z); 324 setForamMeta(cr2, cr2. user2["gen"]);324 setForamMeta(cr2, cr2.data->lifeparams->gen); 325 325 326 326 if (visualization(cr)) 327 327 { 328 Populations[2].delete(cr. user3);328 Populations[2].delete(cr.data->reticulopodiacreature); 329 329 } 330 330 Populations[0].delete(cr); … … 362 362 } 363 363 } 364 else if (eating == 0 && cr. user2["hibernated"]== 0 && dist < mindist)364 else if (eating == 0 && cr.data->lifeparams->hibernated == 0 && dist < mindist) 365 365 { 366 366 mindist = dist; … … 369 369 } 370 370 371 if (!eating && cr. user2["hibernated"]== 0)371 if (!eating && cr.data->lifeparams->hibernated == 0) 372 372 { 373 373 mindistvec.normalize(); … … 388 388 function moveEnergyDec(cr) 389 389 { 390 if (cr. user2["hibernated"]== 0)391 { 392 //cr.energy_m += (ExpParams.energy_move * max_chamber_energ[cr. user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)])*ExpParams.secPerStep;390 if (cr.data->lifeparams->hibernated == 0) 391 { 392 //cr.energy_m += (ExpParams.energy_move * max_chamber_energ[cr.data->lifeparams->gen][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.data->lifeparams->gen].size)-1)])*ExpParams.secPerStep; 393 393 cr.energy_m += (ExpParams.energy_move * cr.energy)*ExpParams.secPerStep; 394 394 } … … 413 413 //no nutrients in zone 2 414 414 var hibernation = 0; 415 if (cr. user2["gen"] == 0) hibernation = cr.user1["hibernation"];416 else hibernation = cr. user1[0]["hibernation"];415 if (cr.data->lifeparams->gen == 0) hibernation = cr.data->genes->hibernation; 416 else hibernation = cr.data->genes[0]->hibernation; 417 417 //hibernation 418 418 if (hibernation == 1) … … 424 424 else if (cr.lifespan%(dir_change/ExpParams.secPerStep) == 0) 425 425 { 426 cr. user2["dir"]= randomDir();427 cr.localDrive = cr. user2["dir"];426 cr.data->lifeparams->dir = randomDir(); 427 cr.localDrive = cr.data->lifeparams->dir; 428 428 moveEnergyDec(cr); 429 429 } 430 430 else 431 431 { 432 cr.localDrive = cr. user2["dir"];432 cr.localDrive = cr.data->lifeparams->dir; 433 433 } 434 434 } … … 450 450 cr2.energy_m = cr2.energy_m + e; 451 451 cr1.energy_p = cr1.energy_p + e; 452 if (cr1. user2["hibernated"]== 1)452 if (cr1.data->lifeparams->hibernated == 1) 453 453 { 454 454 reverseHib(cr1); … … 458 458 function reverseHib(cr) 459 459 { 460 if (cr. user2["hibernated"]== 1)461 { 462 setForamMeta(cr, cr. user2["gen"]); //unhibernate460 if (cr.data->lifeparams->hibernated == 1) 461 { 462 setForamMeta(cr, cr.data->lifeparams->gen); //unhibernate 463 463 } 464 464 else 465 465 { 466 //cr.idleen = (ExpParams.energy_hib * max_chamber_energ[cr. user2["gen"]][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.user2["gen"]].size)-1)])*ExpParams.secPerStep; //hibernate466 //cr.idleen = (ExpParams.energy_hib * max_chamber_energ[cr.data->lifeparams->gen][Math.min(lastChamberNum(cr), (max_chamber_energ[cr.data->lifeparams->gen].size)-1)])*ExpParams.secPerStep; //hibernate 467 467 cr.idleen = (ExpParams.energy_hib * cr.energy)*ExpParams.secPerStep; //hibernate 468 468 } 469 cr. user2["hibernated"] = 1 - cr.user2["hibernated"];469 cr.data->lifeparams->hibernated = 1 - cr.data->lifeparams->hibernated; 470 470 } 471 471 … … 475 475 if (visualization(cr)) 476 476 { 477 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"));477 cr.data->reticulopodiacreature.moveAbs(cr.center_x-ExpParams.zone1_range, cr.center_y-ExpParams.zone1_range, cr.center_z-ExpParams.zone1_range-getProperty(cr.data->lifeparams->gen, "chamber_proculus")); 478 478 } 479 479 … … 492 492 } 493 493 494 cr. user2["max_energy_level"] = Math.max(cr.energy, cr.user2["max_energy_level"]);494 cr.data->lifeparams->max_energy_level = Math.max(cr.energy, cr.data->lifeparams->max_energy_level); 495 495 if (lastChamberNum(cr) <= chambers[0].size-1) 496 496 { 497 if ((cr. user2["max_energy_level"] >= max_chamber_energ[cr.user2["gen"]][lastChamberNum(cr)]))497 if ((cr.data->lifeparams->max_energy_level >= max_chamber_energ[cr.data->lifeparams->gen][lastChamberNum(cr)])) 498 498 { 499 499 foramGrow(cr, lastChamberNum(cr)); … … 504 504 function deathConditions(cr) 505 505 { 506 if ((cr.energy <= getProperty(cr. user2["species"],"e_death_level")) || (Math.rnd01 < ExpParams.hunted_prob))506 if ((cr.energy <= getProperty(cr.data->lifeparams->species,"e_death_level")) || (Math.rnd01 < ExpParams.hunted_prob)) 507 507 return 1; 508 508 else … … 514 514 if (visualization(cr)) 515 515 { 516 Populations[2].delete(cr. user3);516 Populations[2].delete(cr.data->reticulopodiacreature); 517 517 } 518 518 //fossilization 519 519 var geno = GenePools[0].add(cr.genotype); 520 geno. user1 = cr.user1;521 geno. user2 = cr.user2;520 geno.data->genes = cr.data->genes; 521 geno.data->lifeparams = cr.data->lifeparams; 522 522 if (ExpParams.logging == 1) Simulator.print("\"" + cr.name + "\" died..."); 523 523 ExpState.totaltestedcr++; … … 555 555 var nutsize = ExpParams.nutrientsize*10; 556 556 var nut = Populations[2].add("//0\np:sh=2,sx="+nutsize+",sy="+nutsize+",sz="+nutsize+",ry=1.5,vr=0.0,1.0,0.0"); 557 cr. user3= nut;557 cr.data->reticulopodiacreature = nut; 558 558 nut.moveAbs(cr.pos_x-1.5*nutsize, cr.pos_y-1.5*nutsize, 0.5); 559 559 } … … 564 564 if (visualization(cr)) 565 565 { 566 Populations[2].delete(cr. user3);566 Populations[2].delete(cr.data->reticulopodiacreature); 567 567 } 568 568 } … … 635 635 { 636 636 var cr = Populations[0].get(i); 637 var gen = cr. user2["gen"];638 var species = cr. user2["species"];637 var gen = cr.data->lifeparams->gen; 638 var species = cr.data->lifeparams->species; 639 639 640 640 number[species][gen] = number[species][gen] + 1; -
experiments/frams/foraminifera/data/scripts/foraminifera.inc
r474 r476 53 53 function setGenotype(mode) 54 54 { 55 if (mode ["opt"]== 0) //initial56 { 57 mode ["cr"].user1 = {"min_repro_energies" : [max_chamber_energ[0][getProperty(0, "min_repro_energ")], max_chamber_energ[1][getProperty(1, "min_repro_energ")]], "hibernation" : mode["species"]};58 mode ["cr"].user2 = {"max_energy_level" : getProperty(0,"energies0"), "gen" : 0, "hibernated" : 0, "species" : mode["species"], "reproduce" : 0, "dir" : randomDir()};59 } 60 else if (mode ["opt"]== 1) //child61 { 62 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, "dir" : randomDir()};63 mode ["cr"].user1 = mode["parent_user1"];55 if (mode->opt == 0) //initial 56 { 57 mode->cr.data->genes = {"min_repro_energies" : [max_chamber_energ[0][getProperty(0, "min_repro_energ")], max_chamber_energ[1][getProperty(1, "min_repro_energ")]], "hibernation" : mode->species}; 58 mode->cr.data->lifeparams = {"max_energy_level" : getProperty(0,"energies0"), "gen" : 0, "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir()}; 59 } 60 else if (mode->opt == 1) //child 61 { 62 mode->cr.data->lifeparams = {"max_energy_level" : getProperty(1 - mode->parent_lifeparams->gen,"energies0"), "gen" : 1 - mode->parent_lifeparams->gen, "hibernated" : 0, "species" : mode->parent_lifeparams->species, "reproduce" : 0, "dir" : randomDir()}; 63 mode->cr.data->genes = mode->parent_genes; 64 64 } 65 65 else //grow 66 66 { 67 mode ["cr"].user1 = mode["parent_user1"];68 mode ["cr"].user2 = mode["parent_user2"];67 mode->cr.data->genes = mode->parent_genes; 68 mode->cr.data->lifeparams = mode->parent_lifeparams; 69 69 } 70 70 } … … 72 72 function reproduce_haploid(parent, parent2, clone) 73 73 { 74 var number, energy0, new_ user1, gen;74 var number, energy0, new_genes, gen; 75 75 if (clone == 1) 76 76 { 77 77 energy0 = getProperty(0,"energies0"); 78 78 number = (( 1 - getProperty(1, "e_repro_cost")) * parent.energy) / energy0; 79 new_ user1 = parent.user1;80 parent. user2["gen"] = 1 - parent.user2["gen"]; //because of reversal of "gen" in createOffspring function81 gen = parent. user2["gen"];79 new_genes = parent.data->genes; 80 parent.data->lifeparams->gen = 1 - parent.data->lifeparams->gen; //because of reversal of "gen" in createOffspring function 81 gen = parent.data->lifeparams->gen; 82 82 } 83 83 else 84 84 { 85 85 energy0 = getProperty(1,"energies0"); 86 number = (((1 - getProperty(parent. user2["gen"], "e_repro_cost")) * parent.energy) + ((1 -(getProperty(parent.user2["gen"], "e_repro_cost"))) * parent2.energy)) / energy0;87 new_ user1 = [parent.user1, parent2.user1];88 gen = 1 - parent. user2["gen"];86 number = (((1 - getProperty(parent.data->lifeparams->gen, "e_repro_cost")) * parent.energy) + ((1 -(getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent2.energy)) / energy0; 87 new_genes = [parent.data->genes, parent2.data->genes]; 88 gen = 1 - parent.data->lifeparams->gen; 89 89 } 90 90 … … 93 93 for (var j = 0; j < number; j++) 94 94 { 95 createOffspring(createForamGenotype(gen, parent. user2["species"], 0), energy0, new_user1, parent.user2);95 createOffspring(createForamGenotype(gen, parent.data->lifeparams->species, 0), energy0, new_genes, parent.data->lifeparams); 96 96 } 97 97 } … … 100 100 { 101 101 var energy0 = getProperty(0,"energies0"); 102 var number = ((1 - (getProperty(parent. user2["gen"], "e_repro_cost"))) * parent.energy) / energy0;102 var number = ((1 - (getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent.energy) / energy0; 103 103 104 104 Simulator.print("diploid number of offspring: " + number+ " energ0: " + energy0); … … 116 116 for (var k = 0; k < 2; k++) 117 117 { 118 createOffspring(createForamGenotype(1 - parent. user2["gen"], parent.user2["species"], 0), energy0, parent.user1[0], parent.user2);118 createOffspring(createForamGenotype(1 - parent.data->lifeparams->gen, parent.data->lifeparams->species, 0), energy0, parent.data->genes[0], parent.data->lifeparams); 119 119 } 120 120 … … 136 136 for (var i = pop.size-1; i >= 0; i--) 137 137 { 138 if (pop[i]. user2["reproduce"] == 1 && pop[i].user2["species"]== species)138 if (pop[i].data->lifeparams->reproduce == 1 && pop[i].data->lifeparams->species == species) 139 139 { 140 if ((pop[i]. user2["gen"]==1) || ((pop[i].user2["gen"]==0) && ExpParams.stress == 0))140 if ((pop[i].data->lifeparams->gen==1) || ((pop[i].data->lifeparams->gen==0) && ExpParams.stress == 0)) 141 141 { 142 142 continue; … … 169 169 170 170 171 if (cr. user2["gen"]== 1)171 if (cr.data->lifeparams->gen == 1) 172 172 { 173 173 reproduce_diploid(cr); … … 183 183 if (cr.signals.size == 0) 184 184 { 185 cr.signals.add("repro"+cr. user2["species"]);185 cr.signals.add("repro"+cr.data->lifeparams->species); 186 186 cr.signals[0].power = 1; 187 187 } 188 188 reproduced = 0; 189 cr. user2["reproduce"]= 1;189 cr.data->lifeparams->reproduce = 1; 190 190 } 191 191 … … 201 201 function print_repro_info(cr) 202 202 { 203 Simulator.print("Reproduced " + cr. user2["gen"] + " of species " + cr.user2["species"]+ " energy: " + cr.energy);203 Simulator.print("Reproduced " + cr.data->lifeparams->gen + " of species " + cr.data->lifeparams->species + " energy: " + cr.energy); 204 204 } 205 205 … … 211 211 var reproduced = 0; 212 212 213 if (cr. user2["gen"]== 0)214 { 215 properEnergy = ( cr.energy >= cr. user1["min_repro_energies"][cr.user2["gen"]] );213 if (cr.data->lifeparams->gen == 0) 214 { 215 properEnergy = ( cr.energy >= cr.data->genes->min_repro_energies[cr.data->lifeparams->gen] ); 216 216 } 217 217 else 218 218 { 219 properEnergy = ( cr.energy >= cr. user1[0]["min_repro_energies"][cr.user2["gen"]] ); //TODO gene selection219 properEnergy = ( cr.energy >= cr.data->genes[0]->min_repro_energies[cr.data->lifeparams->gen] ); //TODO gene selection 220 220 } 221 221 … … 228 228 reproduced = readyToRepro(cr); 229 229 } 230 else if (cr.signals.receive("repro"+cr. user2["species"]) > 0)230 else if (cr.signals.receive("repro"+cr.data->lifeparams->species) > 0) 231 231 { 232 232 reproduced = readyToRepro(cr); … … 239 239 { 240 240 cr.signals.clear(); 241 cr. user2["reproduce"]= 0;241 cr.data->lifeparams->reproduce = 0; 242 242 } 243 243 … … 247 247 function crossover(parent, gene) 248 248 { 249 var tmp = parent. user1[0][gene];250 parent. user1[0][gene] = parent.user1[1][gene];251 parent. user1[1][gene] = tmp;252 } 253 254 function createOffspring(geno, energy, parent_ user1, parent_user2)249 var tmp = parent.data->genes[0][gene]; 250 parent.data->genes[0][gene] = parent.data->genes[1][gene]; 251 parent.data->genes[1][gene] = tmp; 252 } 253 254 function createOffspring(geno, energy, parent_genes, parent_lifeparams) 255 255 { 256 256 var cr = Populations[0].add(geno); 257 257 cr.energy0 = energy; 258 258 cr.energy = cr.energy0; 259 setGenotype({"cr" : cr, "parent_ user1" : parent_user1, "parent_user2" : parent_user2, "opt" : 1});259 setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1}); 260 260 placeRandomlyNotColliding(cr); 261 261 }
Note: See TracChangeset
for help on using the changeset viewer.