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