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.ofnumd + parent2.user2["Va"] / ExpParams.ofnumd;
|
---|
9 |
|
---|
10 | for (var j = 0; j < number; j++)
|
---|
11 | {
|
---|
12 | createOffspring(ExpParams.gend, ExpParams.ofnumd, [parent.user1, parent2.user1], {"Va" : ExpParams.ofnumd, "gen" : 1 , "growth_step" : ExpParams.growth_step, "rsize": ExpParams.rads[1], "vinit": ExpParams.ofnumd}); //TODO genes from both generations in user1
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | function reproduce_diploid(parent)
|
---|
17 | {
|
---|
18 | var number = parent.user2["Va"] / ExpParams.ofnumh;
|
---|
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, "vamin");
|
---|
26 | crossed = 1;
|
---|
27 | }
|
---|
28 |
|
---|
29 | for (var k = 0; k < 2; k++)
|
---|
30 | {
|
---|
31 | createOffspring(ExpParams.genh, ExpParams.ofnumh, {"vamin" : ExpParams.v_min_h, "amin": ExpParams.age_min_h}, {"Va" : ExpParams.ofnumh, "gen" : 0 , "growth_step" : ExpParams.growth_step, "rsize" : ExpParams.rads[0], "vinit": ExpParams.ofnumh});
|
---|
32 | }
|
---|
33 |
|
---|
34 | //reverse of crossover for fossilization
|
---|
35 | if (crossed == 1)
|
---|
36 | {
|
---|
37 | crossover(parent, "vamin");
|
---|
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 | var haploids = 0;
|
---|
64 | var diploids = 0;
|
---|
65 | var e_inc_h = 0.0;
|
---|
66 | var e_inc_d = 0.0;
|
---|
67 | var e_nut = 0.0;
|
---|
68 | var size_h = 0.0;
|
---|
69 | var size_d = 0.0;
|
---|
70 | var vmin_h = 0.0;
|
---|
71 | var vmin_d = 0.0;
|
---|
72 |
|
---|
73 | for (var i = 0; i < Populations[0].size; i++)
|
---|
74 | {
|
---|
75 | var cr = Populations[0].get(i);
|
---|
76 | if (cr.user2["gen"] == 0)
|
---|
77 | {
|
---|
78 | haploids += 1;
|
---|
79 | e_inc_h += cr.energy;
|
---|
80 | size_h += ExpParams.rads[0]; //TODO change of size dependent on gene
|
---|
81 | vmin_h += cr.user1["vamin"];
|
---|
82 | }
|
---|
83 | else if (cr.user2["gen"] == 1)
|
---|
84 | {
|
---|
85 | diploids += 1;
|
---|
86 | e_inc_d += cr.energy;
|
---|
87 | size_d += ExpParams.rads[1]; //TODO change of size dependent on gene
|
---|
88 | vmin_d += cr.user1[0]["vamin"];
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | for (var i = 0; i < Populations[1].size; i++)
|
---|
93 | {
|
---|
94 | var cr = Populations[1].get(i);
|
---|
95 | e_nut += cr.energy;
|
---|
96 | }
|
---|
97 |
|
---|
98 | if (haploids < 2 && diploids == 0)
|
---|
99 | {
|
---|
100 | Simulator.print("no more creatures, stopped.");
|
---|
101 | Simulator.stop();
|
---|
102 | }
|
---|
103 |
|
---|
104 | var l1 = [haploids, diploids, Populations[1].size];
|
---|
105 | var l2 = [e_inc_h, e_inc_d, e_nut];
|
---|
106 | var dp = diploids;
|
---|
107 | var hp = haploids;
|
---|
108 | if (dp == 0) dp = 0.000001;
|
---|
109 | if (hp == 0) hp = 0.000001;
|
---|
110 | var l3 = [size_h / hp, vmin_h / hp, size_d / dp, vmin_d / dp];
|
---|
111 |
|
---|
112 | if (ExpParams.logging == 1)
|
---|
113 | {
|
---|
114 | log(l1, "log.txt");
|
---|
115 | log(l2, "log2.txt");
|
---|
116 | log(l3, "log3.txt");
|
---|
117 | }
|
---|
118 | //food growth ---------------------------------------------
|
---|
119 | foodenergywaiting = foodenergywaiting + ExpParams.feedrate;
|
---|
120 | if (foodenergywaiting > ExpParams.feede0)
|
---|
121 | {
|
---|
122 | for (var i = 0; i < ExpParams.foodPop; i++)
|
---|
123 | {
|
---|
124 | addfood();
|
---|
125 | }
|
---|
126 |
|
---|
127 | foodenergywaiting = 0.0;
|
---|
128 | Simulator.checkpoint();
|
---|
129 | }
|
---|
130 |
|
---|
131 | //reproduction --------------------------------------------
|
---|
132 | reprocounter += 1;
|
---|
133 | if (reprocounter > ExpParams.repro_time)
|
---|
134 | {
|
---|
135 | reprocounter = 0;
|
---|
136 | var parent1 = null;
|
---|
137 | var parent2 = null;
|
---|
138 | var pop = Populations[0];
|
---|
139 | for (var i = pop.size-1; i >= 0; i--)
|
---|
140 | {
|
---|
141 | if (pop[i].signals.size > 0)
|
---|
142 | {
|
---|
143 | if (pop[i].user2["gen"]==1)
|
---|
144 | {
|
---|
145 | reproduce_diploid(pop[i]);
|
---|
146 | pop.kill(i);
|
---|
147 | }
|
---|
148 | else if (parent1 == null)
|
---|
149 | {
|
---|
150 | parent1 = pop[i];
|
---|
151 | }
|
---|
152 | else if (parent2 == null)
|
---|
153 | {
|
---|
154 | parent2 = pop[i];
|
---|
155 | }
|
---|
156 | else
|
---|
157 | {
|
---|
158 | reproduce_haploid(parent1, parent2);
|
---|
159 | pop.kill(parent1);
|
---|
160 | pop.kill(parent2);
|
---|
161 | parent1 = null;
|
---|
162 | parent2 = null;
|
---|
163 | }
|
---|
164 |
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | //check for death -----------------------------------------------
|
---|
170 | if (Populations[0].size == 0)
|
---|
171 | {
|
---|
172 | if (ExpParams.autorestart)
|
---|
173 | {
|
---|
174 | Simulator.print("no more creatures, restarting...");
|
---|
175 | onExpInit();
|
---|
176 | }
|
---|
177 | else
|
---|
178 | {
|
---|
179 | Simulator.print("no more creatures, stopped.");
|
---|
180 | Simulator.stop();
|
---|
181 | }
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | // -------------------------------- step end --------------------------------
|
---|