[401] | 1 | //size versus energy
|
---|
| 2 | //real proportions
|
---|
| 3 |
|
---|
[422] | 4 | function init_chambers()
|
---|
| 5 | {
|
---|
| 6 | colors = ["1.0,1.0,0.0","1.0,0.5,0.0"];
|
---|
[493] | 7 | retColors = ["1.0,1.0,1.0", "1.0,0.0,0.0"];
|
---|
[432] | 8 | chambers = [ ["0.0,0.0,0.0,", //coiled
|
---|
[430] | 9 | "1.08020961284637, -0.0597195439040661, -0.0393781512975693,",
|
---|
| 10 | "1.08020961284637, -0.0597195439040661, -0.0393781512975693,",
|
---|
| 11 | "0.615013539791107, 0.778662621974945, 0.535521030426025,",
|
---|
| 12 | "0.488581955432892, 0.826426684856415, -0.381044268608093,",
|
---|
| 13 | "0.732419908046722, -0.0084995785728097, -1.02214300632477,",
|
---|
| 14 | "1.35288727283478, 0.875738024711609, -1.03719782829285,",
|
---|
| 15 | "0.342692613601685, 0.938660383224487, -1.45657968521118,",
|
---|
| 16 | "1.0958571434021, 0.316927701234818, -1.813929438591,",
|
---|
| 17 | "0.903768002986908, 1.11856341362, -2.53161096572876,",
|
---|
[432] | 18 | "0.21014116704464, 0.295340299606323, -2.45328187942505,"],
|
---|
| 19 | ["0.0,0.0,0.0,", //longitudal
|
---|
| 20 | "0.98089325428009, 0.00591040402650833, 0.00389722990803421,",
|
---|
| 21 | "1.90962779521942, -0.256769120693207, -0.16194811463356,",
|
---|
| 22 | "2.63965249061584, -0.727959632873535, -0.609036147594452,",
|
---|
| 23 | "3.17575979232788, -1.34843015670776, -1.14828503131866,",
|
---|
| 24 | "3.55273032188416, -2.22369408607483, -1.3917418718338,",
|
---|
| 25 | "3.64916682243347, -3.11888360977173, -1.01666414737701,",
|
---|
| 26 | "3.50461649894714, -3.84039807319641, -0.377427101135254,",
|
---|
| 27 | "3.15921688079834, -4.50001525878906, 0.261153399944305,",
|
---|
| 28 | "2.51528453826904, -5.16421365737915, 0.59241509437561,"]];
|
---|
[422] | 29 | }
|
---|
[401] | 30 |
|
---|
[487] | 31 | function createForamMorphology(morphotype, gen, chamber_num)
|
---|
[401] | 32 | {
|
---|
[422] | 33 | var rad = getProperty(gen, "chamber_proculus");
|
---|
[487] | 34 | var geno = "//0\np:" + chambers[morphotype][0] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ", rz=3.14159265358979,vr=" + colors[gen];
|
---|
[401] | 35 |
|
---|
[487] | 36 | chamber_num = Math.min(chamber_num, chambers[morphotype].size - 1);
|
---|
[422] | 37 |
|
---|
| 38 | for (var i = 0; i < chamber_num; i++)
|
---|
| 39 | {
|
---|
[432] | 40 | rad = getProperty(gen, "chamber_proculus") + getProperty(gen, "chamber_difference") * (i + 1);
|
---|
[487] | 41 | geno += "\n" + "p:" + chambers[morphotype][i+1] + "sh=1,sx=" + rad + ",sy=" + rad + ",sz=" + rad + ",vr=" + colors[gen];
|
---|
[422] | 42 | }
|
---|
| 43 |
|
---|
| 44 | for (var i = 0; i < chamber_num; i++)
|
---|
| 45 | {
|
---|
| 46 | geno += "\n" + "j:"+ i +", "+ (i+1) +", sh=1";
|
---|
| 47 | }
|
---|
[430] | 48 |
|
---|
[487] | 49 | if (morphotype == 0) geno += "\nn:p=0,d=\"S\"";
|
---|
[422] | 50 |
|
---|
| 51 | return geno;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | function setGenotype(mode)
|
---|
| 55 | {
|
---|
[476] | 56 | if (mode->opt == 0) //initial
|
---|
[422] | 57 | {
|
---|
[487] | 58 | mode->cr.data->genes = String.deserialize(String.serialize(mode->genes));
|
---|
| 59 | 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};
|
---|
[422] | 60 | }
|
---|
[476] | 61 | else if (mode->opt == 1) //child
|
---|
[422] | 62 | {
|
---|
[487] | 63 | 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};
|
---|
| 64 | mode->cr.data->genes = String.deserialize(String.serialize(mode->parent_genes));
|
---|
[422] | 65 | }
|
---|
| 66 | else //grow
|
---|
| 67 | {
|
---|
[476] | 68 | mode->cr.data->genes = mode->parent_genes;
|
---|
| 69 | mode->cr.data->lifeparams = mode->parent_lifeparams;
|
---|
[422] | 70 | }
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[479] | 73 | function gametsDivision(parent_energy, energy0)
|
---|
| 74 | {
|
---|
| 75 | var number = 1;
|
---|
| 76 | var result = parent_energy;
|
---|
[486] | 77 | while ((result-ExpProperties.divisionCost) >= energy0)
|
---|
[479] | 78 | {
|
---|
[486] | 79 | result = (result-ExpProperties.divisionCost)/2;
|
---|
[479] | 80 | number *= 2;
|
---|
| 81 | }
|
---|
| 82 | //Simulator.print("parent: " + parent_energy + " result: " + result + " number " + number);
|
---|
| 83 | return {"energy" : result, "number" : number};
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[487] | 86 | function getEnergy0(radius)
|
---|
| 87 | {
|
---|
| 88 | return energyFromVolume(micronsToFrams(radius),1);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[422] | 91 | function reproduce_haploid(parent, parent2, clone)
|
---|
| 92 | {
|
---|
[476] | 93 | var number, energy0, new_genes, gen;
|
---|
[422] | 94 | if (clone == 1)
|
---|
| 95 | {
|
---|
[487] | 96 | var offspring = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0",0)[0]));
|
---|
[479] | 97 | energy0 = offspring->energy;
|
---|
| 98 | number = offspring->number;
|
---|
[476] | 99 | new_genes = parent.data->genes;
|
---|
| 100 | parent.data->lifeparams->gen = 1 - parent.data->lifeparams->gen; //because of reversal of "gen" in createOffspring function
|
---|
| 101 | gen = parent.data->lifeparams->gen;
|
---|
[422] | 102 | }
|
---|
| 103 | else
|
---|
| 104 | {
|
---|
[487] | 105 | var offspring1 = gametsDivision(parent.energy,getEnergy0(getGene(parent,"energies0", 0)[1]));
|
---|
| 106 | var offspring2 = gametsDivision(parent2.energy,getEnergy0(getGene(parent2,"energies0", 0)[1]));
|
---|
[479] | 107 | energy0 = (offspring1->energy+offspring2->energy);
|
---|
[486] | 108 | number = ExpProperties.gametSuccessRate*(offspring1->number+offspring2->number)/2;
|
---|
[476] | 109 | new_genes = [parent.data->genes, parent2.data->genes];
|
---|
| 110 | gen = 1 - parent.data->lifeparams->gen;
|
---|
[493] | 111 |
|
---|
| 112 | if (ExpProperties.logging == 1)
|
---|
| 113 | {
|
---|
| 114 | log(createLogVector(parent, parent.energy),ExpProperties.logPref+"repro_energies_log.txt");
|
---|
| 115 | log(createLogVector(parent2, parent2.energy),ExpProperties.logPref+"repro_energies_log.txt");
|
---|
| 116 | log(createLogVector(parent, number),ExpProperties.logPref+"repro_num_log.txt");
|
---|
| 117 | }
|
---|
[422] | 118 | }
|
---|
| 119 |
|
---|
[430] | 120 | Simulator.print("haploid number of offspring: " + number + " energ0: " + energy0);
|
---|
[422] | 121 |
|
---|
[418] | 122 | for (var j = 0; j < number; j++)
|
---|
[401] | 123 | {
|
---|
[487] | 124 | createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), gen, 0), energy0, new_genes, parent.data->lifeparams);
|
---|
[401] | 125 | }
|
---|
| 126 | }
|
---|
| 127 |
|
---|
[418] | 128 | function reproduce_diploid(parent)
|
---|
[401] | 129 | {
|
---|
[487] | 130 | var energy0 =getEnergy0( getGene(parent,"energies0", 0)[0]);
|
---|
[476] | 131 | var number = ((1 - (getProperty(parent.data->lifeparams->gen, "e_repro_cost"))) * parent.energy) / energy0;
|
---|
[422] | 132 |
|
---|
[493] | 133 | if (ExpProperties.logging == 1)
|
---|
| 134 | {
|
---|
| 135 | log(createLogVector(parent, parent.energy),ExpProperties.logPref+"repro_energies_log.txt");
|
---|
| 136 | log(createLogVector(parent, number),ExpProperties.logPref+"repro_num_log.txt");
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[430] | 139 | Simulator.print("diploid number of offspring: " + number+ " energ0: " + energy0);
|
---|
[422] | 140 |
|
---|
[418] | 141 | for (var j = 0; j < number / 2; j++)
|
---|
[401] | 142 | {
|
---|
[418] | 143 | var crossed = 0;
|
---|
| 144 | //crossover
|
---|
[486] | 145 | if (Math.rnd01 < ExpProperties.crossprob)
|
---|
[418] | 146 | {
|
---|
[422] | 147 | crossover(parent, "min_repro_energies");
|
---|
[418] | 148 | crossed = 1;
|
---|
| 149 | }
|
---|
[401] | 150 |
|
---|
[418] | 151 | for (var k = 0; k < 2; k++)
|
---|
[404] | 152 | {
|
---|
[487] | 153 | createOffspring(createForamMorphology(getGene(parent, "morphotype", 0), 1 - parent.data->lifeparams->gen, 0), energy0, parent.data->genes[0], parent.data->lifeparams);
|
---|
[404] | 154 | }
|
---|
| 155 |
|
---|
[418] | 156 | //reverse of crossover for fossilization
|
---|
| 157 | if (crossed == 1)
|
---|
[401] | 158 | {
|
---|
[422] | 159 | crossover(parent, "min_repro_energies");
|
---|
[418] | 160 | crossed = 0;
|
---|
[401] | 161 | }
|
---|
[418] | 162 |
|
---|
[401] | 163 | }
|
---|
[404] | 164 | }
|
---|
| 165 |
|
---|
[422] | 166 | function reproduce_parents(species)
|
---|
[404] | 167 | {
|
---|
[418] | 168 | var parent1 = null;
|
---|
| 169 | var parent2 = null;
|
---|
| 170 | var pop = Populations[0];
|
---|
| 171 | for (var i = pop.size-1; i >= 0; i--)
|
---|
[401] | 172 | {
|
---|
[476] | 173 | if (pop[i].data->lifeparams->reproduce == 1 && pop[i].data->lifeparams->species == species)
|
---|
[418] | 174 | {
|
---|
[486] | 175 | if ((pop[i].data->lifeparams->gen==1) || ((pop[i].data->lifeparams->gen==0) && ExpProperties.stress == 0))
|
---|
[401] | 176 | {
|
---|
[422] | 177 | continue;
|
---|
[401] | 178 | }
|
---|
[418] | 179 | else if (parent1 == null)
|
---|
[401] | 180 | {
|
---|
[418] | 181 | parent1 = pop[i];
|
---|
[401] | 182 | }
|
---|
[418] | 183 | else if (parent2 == null)
|
---|
| 184 | {
|
---|
| 185 | parent2 = pop[i];
|
---|
| 186 | }
|
---|
[430] | 187 | if (parent1 != null && parent2 != null)
|
---|
[418] | 188 | {
|
---|
[479] | 189 | //when parents are ready for reproduction start gametogenesis
|
---|
| 190 | if (parent1.data->lifeparams->division_time == -1 && parent2.data->lifeparams->division_time == -1)
|
---|
| 191 | {
|
---|
[486] | 192 | var time = int(ExpProperties.gametoPeriod/ExpProperties.secPerStep);
|
---|
[479] | 193 | parent1.data->lifeparams->division_time = time;
|
---|
| 194 | parent2.data->lifeparams->division_time = time;
|
---|
| 195 | parent1.idleen = 0;
|
---|
| 196 | parent2.idleen = 0;
|
---|
| 197 | //Simulator.print("parents "+parent1.uid + " " + parent2.uid + " ready to repro: "+Simulator.stepNumber);
|
---|
| 198 | }
|
---|
| 199 | //when gametogenesis is finished fuse gamets
|
---|
| 200 | else if (parent1.data->lifeparams->division_time == 0 && parent2.data->lifeparams->division_time == 0)
|
---|
| 201 | {
|
---|
| 202 | reproduce_haploid(parent1, parent2, 0);
|
---|
| 203 | print_repro_info(parent1);
|
---|
| 204 | print_repro_info(parent2);
|
---|
| 205 | pop.kill(parent1);
|
---|
| 206 | pop.kill(parent2);
|
---|
| 207 | parent1 = null;
|
---|
| 208 | parent2 = null;
|
---|
| 209 | }
|
---|
[430] | 210 | }
|
---|
[418] | 211 | }
|
---|
[401] | 212 | }
|
---|
[422] | 213 | }
|
---|
| 214 |
|
---|
| 215 | function readyToRepro(cr)
|
---|
| 216 | {
|
---|
| 217 | var reproduced = 1;
|
---|
| 218 |
|
---|
| 219 |
|
---|
[476] | 220 | if (cr.data->lifeparams->gen == 1)
|
---|
[422] | 221 | {
|
---|
| 222 | reproduce_diploid(cr);
|
---|
[401] | 223 | }
|
---|
| 224 |
|
---|
[486] | 225 | else if (ExpProperties.stress == 0)
|
---|
[401] | 226 | {
|
---|
[422] | 227 | reproduce_haploid(cr, null, 1);
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | else
|
---|
| 231 | {
|
---|
| 232 | if (cr.signals.size == 0)
|
---|
[401] | 233 | {
|
---|
[476] | 234 | cr.signals.add("repro"+cr.data->lifeparams->species);
|
---|
[422] | 235 | cr.signals[0].power = 1;
|
---|
[401] | 236 | }
|
---|
[422] | 237 | reproduced = 0;
|
---|
[476] | 238 | cr.data->lifeparams->reproduce = 1;
|
---|
[401] | 239 | }
|
---|
[422] | 240 |
|
---|
| 241 | if (reproduced == 1)
|
---|
| 242 | {
|
---|
| 243 | print_repro_info(cr);
|
---|
| 244 | Populations[0].kill(cr);
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | return reproduced;
|
---|
[401] | 248 | }
|
---|
| 249 |
|
---|
[422] | 250 | function print_repro_info(cr)
|
---|
[421] | 251 | {
|
---|
[476] | 252 | Simulator.print("Reproduced " + cr.data->lifeparams->gen + " of species " + cr.data->lifeparams->species + " energy: " + cr.energy);
|
---|
[422] | 253 | }
|
---|
[421] | 254 |
|
---|
[422] | 255 | function foramReproduce(cr)
|
---|
| 256 | {
|
---|
[488] | 257 | var properEnergy = cr.energy >= energyFromVolume(max_chamber_volume[cr.data->lifeparams->gen][getGene(cr, "min_repro_energies",0)[cr.data->lifeparams->gen]],0);
|
---|
[487] | 258 | var reproduced = 0;
|
---|
[422] | 259 |
|
---|
| 260 | //if creature has proper energy
|
---|
| 261 | if ( properEnergy && cr.signals.size == 0)
|
---|
| 262 | {
|
---|
| 263 | //reproduce with probability repro_prob
|
---|
[486] | 264 | if (Math.rnd01 <= ExpProperties.repro_prob) //TODO env trigger
|
---|
[421] | 265 | {
|
---|
[422] | 266 | reproduced = readyToRepro(cr);
|
---|
[421] | 267 | }
|
---|
[476] | 268 | else if (cr.signals.receive("repro"+cr.data->lifeparams->species) > 0)
|
---|
[421] | 269 | {
|
---|
[422] | 270 | reproduced = readyToRepro(cr);
|
---|
[421] | 271 | }
|
---|
[422] | 272 | if (reproduced == 1)
|
---|
[430] | 273 | return 1;
|
---|
[421] | 274 | }
|
---|
| 275 |
|
---|
[422] | 276 | else if (!properEnergy)
|
---|
[421] | 277 | {
|
---|
[422] | 278 | cr.signals.clear();
|
---|
[476] | 279 | cr.data->lifeparams->reproduce = 0;
|
---|
[421] | 280 | }
|
---|
[430] | 281 |
|
---|
| 282 | return 0;
|
---|
[422] | 283 | }
|
---|
[421] | 284 |
|
---|
[422] | 285 | function crossover(parent, gene)
|
---|
| 286 | {
|
---|
[476] | 287 | var tmp = parent.data->genes[0][gene];
|
---|
| 288 | parent.data->genes[0][gene] = parent.data->genes[1][gene];
|
---|
| 289 | parent.data->genes[1][gene] = tmp;
|
---|
[422] | 290 | }
|
---|
[421] | 291 |
|
---|
[476] | 292 | function createOffspring(geno, energy, parent_genes, parent_lifeparams)
|
---|
[422] | 293 | {
|
---|
[493] | 294 | curColor = retColors[1-parent_lifeparams->gen];
|
---|
[422] | 295 | var cr = Populations[0].add(geno);
|
---|
| 296 | cr.energy0 = energy;
|
---|
| 297 | cr.energy = cr.energy0;
|
---|
[487] | 298 | setGenotype({"cr" : cr, "parent_genes" : parent_genes, "parent_lifeparams" : parent_lifeparams, "opt" : 1, "energy0" : cr.energy0});
|
---|
[422] | 299 | placeRandomlyNotColliding(cr);
|
---|
[421] | 300 | }
|
---|