Changeset 487 for experiments/frams/foraminifera/data
- Timestamp:
- 03/27/16 00:12:20 (9 years ago)
- Location:
- experiments/frams/foraminifera/data/scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
experiments/frams/foraminifera/data/scripts/foraminifera.expdef
r486 r487 33 33 global changePeriod; 34 34 global phase; 35 global species_genes; 35 36 36 37 @include "foraminifera.inc" … … 52 53 pop.death = 1; 53 54 pop.energy = 1; 54 pop.selfmask = 0 x10001;55 pop.othermask = 0 x20001;55 pop.selfmask = 0; 56 pop.othermask = 0; 56 57 //pop.selfmask = 0x20002; pop.othermask = 0x10002; 57 58 pop.perfperiod = 25; 59 pop.bodysim = 0; 58 60 59 61 pop = Populations.addGroup("Nutrients"); … … 62 64 pop.death = 1; 63 65 pop.energy = 1; 64 pop.selfmask = 0 x20002;65 pop.othermask = 0 x10000;66 pop.selfmask = 0; 67 pop.othermask = 0; 66 68 //pop.othermask = 0x10002; 69 pop.bodysim = 0; 67 70 68 71 pop = Populations.addGroup("ReticulopodiaNutrients"); … … 71 74 pop.death = 0; 72 75 pop.energy = 0; 73 pop.selfmask = 0x20002; 74 pop.othermask = 0x10000; 76 pop.selfmask = 0; 77 pop.othermask = 0; 78 pop.bodysim = 0; 75 79 76 80 //world … … 90 94 //ExpProperties.visualize = 1; //uncomment to visualize reticulopodia and indicate nutrients positions 91 95 92 //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files 96 //ExpProperties.logging = 1; //uncomment to enable logging simulation parameters to log files 93 97 94 98 //reproduction … … 100 104 ExpProperties.divisionCost = 15.6; 101 105 reprocounter = 0; 106 107 species_genes = []; 102 108 103 109 init_chambers(); … … 143 149 changePeriod = 0; 144 150 phase = "high"; 145 ExpProperties.foodperiod = 21600;151 ExpProperties.foodperiod = 3600; 146 152 ExpProperties.foodPeriodChange = 0; 147 153 ExpProperties.nutrientradius = micronsToFrams(10); … … 195 201 } 196 202 203 function getGene(cr, gen_id, gen_set) 204 { 205 if (cr.data->lifeparams->gen == 0) 206 return cr.data->genes[gen_id]; 207 else 208 return cr.data->genes[gen_set][gen_id]; 209 } 210 197 211 function addForam(species, iter, chambernum, ploid) 198 212 { 199 var geno = createForam Genotype(ploid, species, chambernum);213 var geno = createForamMorphology(species_genes[species]->morphotype, ploid, chambernum); 200 214 var cr = Populations[0].add(geno); 201 215 cr.name = "Initial creature" + species + "_" + iter; … … 203 217 cr.energy0 = energyFromVolume(max_chamber_volume[ploid][chambernum],0); 204 218 cr.energy = cr.energy0; 205 setGenotype({"opt" : 0, "cr" : cr, "species" : species });219 setGenotype({"opt" : 0, "cr" : cr, "species" : species, "energy0" : cr.energy0, "genes" : species_genes[species]}); 206 220 if (ploid == 1) 207 221 { … … 219 233 } 220 234 //add new foram with random energy bewtween starting energy and reproduction treshold 221 addForam(species, iter, Math.rndUni(0,getProperty(ploid, "min_repro_energ")),ploid); 235 addForam(species, iter, Math.rndUni(0,species_genes[species]->min_repro_energies[ploid]),ploid); 236 } 237 238 //new species can be added as a dictionary with parameter values that are different than default values 239 function addSpecies(new_genes) 240 { 241 species_genes.add({"min_repro_energies" : [4,6], "energies0" : [20, 1.25], "hibernation" : 0, "morphotype" : 0}); 242 for (var i = 0; i < new_genes.size; i++) 243 { 244 var key = new_genes.getKey(i); 245 species_genes[species_genes.size-1][key] = new_genes[key]; 246 } 222 247 } 223 248 … … 228 253 Populations[2].clear(); //reticulopodia and nutrients 229 254 230 for (var i = 0; i < ExpProperties.foramPop; i++) 231 { 232 addInitialForam(0, i); 233 //addInitialForam(1, i); 255 if (species_genes.size == 0) 256 { 257 addSpecies({}); //default 258 } 259 260 for (var spec = 0; spec < species_genes.size; spec++) 261 { 262 for (var i = 0; i < ExpProperties.foramPop; i++) 263 { 264 addInitialForam(spec, i); 265 } 234 266 } 235 267 o = Populations[0][0].getMechPart(0).orient.clone(); 236 268 ExpState.totaltestedcr = 0; 237 nutrientenergywaiting = ExpProperties.energy_nut;238 269 } 239 270 … … 361 392 if ((chamber_num+1) < chambers[cr.data->lifeparams->species].size) 362 393 { 363 var geno = createForam Genotype(cr.data->lifeparams->gen, cr.data->lifeparams->species, chamber_num+1);394 var geno = createForamMorphology(getGene(cr, "morphotype", 0), cr.data->lifeparams->gen, chamber_num+1); 364 395 var cr2 = Populations[0].add(geno); 365 396 … … 367 398 cr2.energy = cr2.energy0; 368 399 369 setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2 });400 setGenotype({"cr" : cr2, "parent_genes" : cr.data->genes, "parent_lifeparams" : cr.data->lifeparams, "opt" : 2, "energy0" : cr.energy0}); 370 401 cr2.moveAbs(cr.center_x - cr2.size_x / 2, cr.center_y - cr2.size_y / 2, cr.pos_z); 371 402 setForamMeta(cr2); … … 442 473 } 443 474 475 function fence(pos) 476 { 477 return Math.min(Math.max(0,pos),World.wrldsiz); 478 } 479 444 480 function foramMove(cr) 445 481 { … … 447 483 448 484 //adjustment in z axis 449 cr.moveAbs( cr.pos_x, cr.pos_y, 0);485 cr.moveAbs(fence(cr.pos_x), fence(cr.pos_y), 0); 450 486 451 487 //are there any nutrients in zone 1 or 2? … … 459 495 460 496 //no nutrients in zone 2 461 var hibernation = 0; 462 if (cr.data->lifeparams->gen == 0) hibernation = cr.data->genes->hibernation; 463 else hibernation = cr.data->genes[0]->hibernation; 464 //hibernation 465 if (hibernation == 1) 497 if (getGene(cr, "hibernation",0) == 1) 466 498 { 467 499 reverseHib(cr); … … 469 501 } 470 502 //random move 471 else if ( cr.lifespan%int(dir_change/ExpProperties.secPerStep) == 0)503 else if (Simulator.stepNumber%int(dir_change/ExpProperties.secPerStep) == 0) 472 504 { 473 505 cr.data->lifeparams->dir = randomDir(); … … 732 764 function createStatistics() 733 765 { 734 var number = [ [0, 0],[0,0]]; // [species][gen]735 var e_inc = [ [0, 0],[0,0]];766 var number = []; 767 var e_inc = []; 736 768 var e_nut = 0.0; 769 770 for (var s = 0; s < species_genes.size; s++) 771 { 772 number.add([0,0]);// [haplo][diplo] 773 e_inc.add([0,0]); 774 } 737 775 738 776 for (var i = 0; i < Populations[0].size; i++) … … 752 790 } 753 791 754 var log_numbers = [number[1][0], number[1][1], number[0][0], number[0][1], Populations[1].size]; 755 var log_energies = [e_inc[1][0], e_inc[1][1], e_inc[0][0], e_inc[0][1], e_nut]; 792 var log_numbers = []; 793 var log_energies = []; 794 795 for (var s = 0; s < species_genes.size; s++) 796 { 797 for (var p = 0; p < 2; p++) 798 { 799 log_numbers.add(number[s][p]); 800 log_energies.add(e_inc[s][p]); 801 } 802 } 803 804 log_numbers.add(Populations[1].size); 805 log_energies.add(e_nut); 756 806 757 807 log(log_numbers, "forams_log.txt"); -
experiments/frams/foraminifera/data/scripts/foraminifera.inc
r486 r487 28 28 } 29 29 30 function createForam Genotype(gen, species, chamber_num)30 function createForamMorphology(morphotype, gen, chamber_num) 31 31 { 32 32 var rad = getProperty(gen, "chamber_proculus"); 33 var geno = "//0\np:" + chambers[ species][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen];34 35 chamber_num = Math.min(chamber_num, chambers[ species].size - 1);33 var geno = "//0\np:" + chambers[morphotype][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen]; 34 35 chamber_num = Math.min(chamber_num, chambers[morphotype].size - 1); 36 36 37 37 for (var i = 0; i < chamber_num; i++) 38 38 { 39 39 rad = getProperty(gen, "chamber_proculus") + getProperty(gen, "chamber_difference") * (i + 1); 40 geno += "\n" + "p:" + chambers[ species][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen];40 geno += "\n" + "p:" + chambers[morphotype][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen]; 41 41 } 42 42 … … 46 46 } 47 47 48 if ( species== 0) geno += "\nn:p=0,d=\"S\"";48 if (morphotype == 0) geno += "\nn:p=0,d=\"S\""; 49 49 50 50 return geno; … … 55 55 if (mode->opt == 0) //initial 56 56 { 57 mode->cr.data->genes = {"min_repro_energies" : [energyFromVolume(max_chamber_volume[0][getProperty(0, "min_repro_energ")],0), energyFromVolume(max_chamber_volume[1][getProperty(1, "min_repro_energ")],0)], "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(), "chamber_growth" : -1, "division_time" : -1};57 mode->cr.data->genes = String.deserialize(String.serialize(mode->genes)); 58 mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : 0, "hibernated" : 0, "species" : mode->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1}; 59 59 } 60 60 else if (mode->opt == 1) //child 61 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(), "chamber_growth" : -1, "division_time" : -1};63 mode->cr.data->genes = mode->parent_genes;62 mode->cr.data->lifeparams = {"max_energy_level" : mode->energy0, "gen" : 1 - mode->parent_lifeparams->gen, "hibernated" : 0, "species" : mode->parent_lifeparams->species, "reproduce" : 0, "dir" : randomDir(), "chamber_growth" : -1, "division_time" : -1}; 63 mode->cr.data->genes = String.deserialize(String.serialize(mode->parent_genes)); 64 64 } 65 65 else //grow … … 81 81 //Simulator.print("parent: " + parent_energy + " result: " + result + " number " + number); 82 82 return {"energy" : result, "number" : number}; 83 } 84 85 function getEnergy0(radius) 86 { 87 return energyFromVolume(micronsToFrams(radius),1); 83 88 } 84 89 … … 88 93 if (clone == 1) 89 94 { 90 var offspring = gametsDivision(parent.energy,get Property(0,"energies0"));95 var offspring = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0",0)[0])); 91 96 energy0 = offspring->energy; 92 97 number = offspring->number; … … 97 102 else 98 103 { 99 var offspring1 = gametsDivision(parent.energy,get Property(1,"energies0"));100 var offspring2 = gametsDivision(parent2.energy,get Property(1,"energies0"));104 var offspring1 = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0", 0)[1])); 105 var offspring2 = gametsDivision(parent2.energy,getEnergy0(getGene(parent2,"energies0", 0)[1])); 101 106 energy0 = (offspring1->energy+offspring2->energy); 102 107 number = ExpProperties.gametSuccessRate*(offspring1->number+offspring2->number)/2; … … 109 114 for (var j = 0; j < number; j++) 110 115 { 111 createOffspring(createForam Genotype(gen, parent.data->lifeparams->species, 0), energy0, new_genes, parent.data->lifeparams);116 createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), gen, 0), energy0, new_genes, parent.data->lifeparams); 112 117 } 113 118 } … … 115 120 function reproduce_diploid(parent) 116 121 { 117 var energy0 = getProperty(0,"energies0");122 var energy0 =getEnergy0( getGene(parent,"energies0", 0)[0]); 118 123 var number = ((1 - (getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent.energy) / energy0; 119 124 … … 132 137 for (var k = 0; k < 2; k++) 133 138 { 134 createOffspring(createForam Genotype(1 - parent.data->lifeparams->gen, parent.data->lifeparams->species, 0), energy0, parent.data->genes[0], parent.data->lifeparams);139 createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), 1 - parent.data->lifeparams->gen, 0), energy0, parent.data->genes[0], parent.data->lifeparams); 135 140 } 136 141 … … 236 241 } 237 242 238 239 240 243 function foramReproduce(cr) 241 244 { 242 var properEnergy = 0; 243 var reproduced = 0; 244 245 if (cr.data->lifeparams->gen == 0) 246 { 247 properEnergy = ( cr.energy >= cr.data->genes->min_repro_energies[cr.data->lifeparams->gen] ); 248 } 249 else 250 { 251 properEnergy = ( cr.energy >= cr.data->genes[0]->min_repro_energies[cr.data->lifeparams->gen] ); //TODO gene selection 252 } 245 var properEnergy = cr.energy >= energyFromVolume(max_chamber_volume[0][getGene(cr, "min_repro_energies",0)[cr.data->lifeparams->gen]],0); 246 var reproduced = 0; 253 247 254 248 //if creature has proper energy … … 289 283 cr.energy0 = energy; 290 284 cr.energy = cr.energy0; 291 setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1 });285 setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1, "energy0" : cr.energy0}); 292 286 placeRandomlyNotColliding(cr); 293 287 }
Note: See TracChangeset
for help on using the changeset viewer.