1 | //size versus energy
|
---|
2 | //real proportions
|
---|
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;
|
---|
9 |
|
---|
10 | for (var j = 0; j < number; j++)
|
---|
11 | {
|
---|
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 user1
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | function reproduce_diploid(parent)
|
---|
17 | {
|
---|
18 | var number = parent.user2["Va"] / ExpParams.energy0h;
|
---|
19 | for (var j = 0; j < number / 2; j++)
|
---|
20 | {
|
---|
21 | var crossed = 0;
|
---|
22 | //crossover
|
---|
23 | if (Math.rnd01 < ExpParams.crossprob)
|
---|
24 | {
|
---|
25 | crossover(parent, "minenergy");
|
---|
26 | crossed = 1;
|
---|
27 | }
|
---|
28 |
|
---|
29 | for (var k = 0; k < 2; k++)
|
---|
30 | {
|
---|
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?
|
---|
32 | }
|
---|
33 |
|
---|
34 | //reverse of crossover for fossilization
|
---|
35 | if (crossed == 1)
|
---|
36 | {
|
---|
37 | crossover(parent, "minenergy");
|
---|
38 | crossed = 0;
|
---|
39 | }
|
---|
40 |
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
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;
|
---|
87 | var parent1 = null;
|
---|
88 | var parent2 = null;
|
---|
89 | var pop = Populations[0];
|
---|
90 | for (var i = pop.size-1; i >= 0; i--)
|
---|
91 | {
|
---|
92 | if (pop[i].signals.size > 0)
|
---|
93 | {
|
---|
94 | if (pop[i].user2["gen"]==1)
|
---|
95 | {
|
---|
96 | reproduce_diploid(pop[i]);
|
---|
97 | pop.kill(i);
|
---|
98 | }
|
---|
99 | else if (parent1 == null)
|
---|
100 | {
|
---|
101 | parent1 = pop[i];
|
---|
102 | }
|
---|
103 | else if (parent2 == null)
|
---|
104 | {
|
---|
105 | parent2 = pop[i];
|
---|
106 | }
|
---|
107 | else
|
---|
108 | {
|
---|
109 | reproduce_haploid(parent1, parent2);
|
---|
110 | pop.kill(parent1);
|
---|
111 | pop.kill(parent2);
|
---|
112 | parent1 = null;
|
---|
113 | parent2 = null;
|
---|
114 | }
|
---|
115 |
|
---|
116 | }
|
---|
117 | }
|
---|
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 --------------------------------
|
---|