Menu

[01c4ec]: / WorldStatistics.java  Maximize  Restore  History

Download this file

475 lines (368 with data), 11.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
/* Copyright (C) 2006-2010 Joan Queralt Molina
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package biogenesis;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class WorldStatistics implements Serializable {
private static final long serialVersionUID = Utils.FILE_VERSION;
private long time;
private int maxPopulation;
private int maxBirths = 0;
private int maxDeaths = 0;
private long maxPopulationTime;
private int minPopulation = Utils.INITIAL_ORGANISMS;
private long minPopulationTime;
// private int lastTimePopulation;
private int massExtintions;
private int massExtintionState;
private static final int EXTINTION_NO = 0;
private static final int EXTINTION_POSSIBLE = 1;
private static final int EXTINTION_CONFIRMED = 2;
private static final int EXTINTION_FINISHING = 3;
private int createdOrganisms;
private long populationSum;
private long deathSum;
private int deathLastTime;
private long birthSum;
private int birthLastTime;
private long infectionsSum;
private double maxOxygen = Utils.INITIAL_O2;
private long maxOxygenTime;
private double minOxygen = Utils.INITIAL_O2;
private long minOxygenTime;
private double maxCarbonDioxide = Utils.INITIAL_CO2;
private long maxCarbonDioxideTime;
private double minCarbonDioxide = Utils.INITIAL_CO2;
private long minCarbonDioxideTime;
private GeneticCode aliveBeingMostChildren;
private int aliveBeingMostChildrenNumber;
private GeneticCode aliveBeingMostKills;
private int aliveBeingMostKillsNumber;
private GeneticCode aliveBeingMostInfections;
private int aliveBeingMostInfectionsNumber;
private GeneticCode beingMostChildren;
private int beingMostChildrenNumber;
private long beingMostChildrenTime;
private GeneticCode beingMostKills;
private int beingMostKillsNumber;
private long beingMostKillsTime;
private GeneticCode beingMostInfections;
private int beingMostInfectionsNumber;
private long beingMostInfectionsTime;
private GeneticCode lastBornBeing;
private GeneticCode lastDeadBeing;
private GeneticCode lastInfectedBeing;
private List<Double> populationList = new ArrayList<Double>(100);
private List<Double> deathList = new ArrayList<Double>(100);
private List<Double> birthList = new ArrayList<Double>(100);
private List<Double> oxygenList = new ArrayList<Double>(100);
private List<Double> carbonDioxideList = new ArrayList<Double>(100);
public long getTime() {
return time;
}
public int getMaxPopulation() {
return maxPopulation;
}
public int getMaxBirth() {
return maxBirths;
}
public int getMaxDeaths() {
return maxDeaths;
}
public long getMaxPopulationTime() {
return maxPopulationTime;
}
public int getMinPopulation() {
return minPopulation;
}
public long getMinPopulationTime() {
return minPopulationTime;
}
public int getMassExtintions() {
return massExtintions;
}
public int getCreatedOrganisms() {
return createdOrganisms;
}
public double getAveragePopulation() {
if (time > 0)
return populationSum / (double) time;
return 0;
}
public double getAverageDeaths() {
if (time > 0)
return deathSum / (double) time;
return 0;
}
public double getAverageBirths() {
if (time > 0)
return birthSum / (double) time;
return 0;
}
public double getAverageInfections() {
if (time > 0)
return infectionsSum / (double) time;
return 0;
}
public double getMaxOxygen() {
return maxOxygen;
}
public long getMaxOxygenTime() {
return maxOxygenTime;
}
public double getMinOxygen() {
return minOxygen;
}
public long getMinOxygenTime() {
return minOxygenTime;
}
public double getMaxCarbonDioxide() {
return maxCarbonDioxide;
}
public long getMaxCarbonDioxideTime() {
return maxCarbonDioxideTime;
}
public double getMinCarbonDioxide() {
return minCarbonDioxide;
}
public long getMinCarbonDioxideTime() {
return minCarbonDioxideTime;
}
public GeneticCode getAliveBeingMostChildren() {
return aliveBeingMostChildren;
}
public int getAliveBeingMostChildrenNumber() {
return aliveBeingMostChildrenNumber;
}
public GeneticCode getAliveBeingMostKills() {
return aliveBeingMostKills;
}
public int getAliveBeingMostKillsNumber() {
return aliveBeingMostKillsNumber;
}
public GeneticCode getAliveBeingMostInfections() {
return aliveBeingMostInfections;
}
public int getAliveBeingMostInfectionsNumber() {
return aliveBeingMostInfectionsNumber;
}
public GeneticCode getBeingMostChildren() {
return beingMostChildren;
}
public int getBeingMostChildrenNumber() {
return beingMostChildrenNumber;
}
public long getBeingMostChildrenTime() {
return beingMostChildrenTime;
}
public GeneticCode getBeingMostKills() {
return beingMostKills;
}
public int getBeingMostKillsNumber() {
return beingMostKillsNumber;
}
public long getBeingMostKillsTime() {
return beingMostKillsTime;
}
public GeneticCode getBeingMostInfections() {
return beingMostInfections;
}
public int getBeingMostInfectionsNumber() {
return beingMostInfectionsNumber;
}
public long getBeingMostInfectionsTime() {
return beingMostInfectionsTime;
}
public GeneticCode getLastBornBeing() {
return lastBornBeing;
}
public GeneticCode getLastDeadBeing() {
return lastDeadBeing;
}
public GeneticCode getLastInfectedBeing() {
return lastInfectedBeing;
}
public List<Double> getPopulationList() {
return populationList;
}
public List<Double> getDeathList() {
return deathList;
}
public List<Double> getBirthList() {
return birthList;
}
public List<Double> getOxygenList() {
return oxygenList;
}
public List<Double> getCarbonDioxideList() {
return carbonDioxideList;
}
public void eventPopulationIncrease(int newPopulation) {
if (newPopulation > maxPopulation) {
maxPopulation = newPopulation;
maxPopulationTime = time;
}
}
public void eventPopulationDecrease(int newPopulation) {
if (newPopulation < minPopulation) {
minPopulation = newPopulation;
minPopulationTime = time;
}
}
public void eventOrganismCreated() {
createdOrganisms++;
}
public void eventOrganismBorn(Organism newOrganism, Organism parent) {
lastBornBeing = newOrganism.getGeneticCode();
if (parent.getTotalChildren() > beingMostChildrenNumber) {
beingMostChildren = parent.getGeneticCode();
beingMostChildrenNumber = parent.getTotalChildren();
beingMostChildrenTime = time;
}
birthSum++;
birthLastTime++;
}
public void eventOrganismDie(Organism dyingOrganism,
Organism killingOrganism) {
lastDeadBeing = dyingOrganism.getGeneticCode();
if (killingOrganism != null
&& killingOrganism.getTotalKills() > beingMostKillsNumber) {
beingMostKills = killingOrganism.getGeneticCode();
beingMostKillsNumber = killingOrganism.getTotalKills();
beingMostKillsTime = time;
}
deathSum++;
deathLastTime++;
}
public void eventOrganismInfects(Organism infectedOrganism,
Organism infectingOrganism) {
lastInfectedBeing = infectedOrganism.getGeneticCode();
if (infectingOrganism != null
&& infectingOrganism.getTotalInfected() > beingMostInfectionsNumber) {
beingMostInfections = infectingOrganism.getGeneticCode();
beingMostInfectionsNumber = infectingOrganism.getTotalInfected();
beingMostInfectionsTime = time;
}
infectionsSum++;
}
public void eventTime(int population, double O2, double CO2) {
time++;
if (deathLastTime > 1.5 * getAverageDeaths()) {
if (deathLastTime > 3 * getAverageDeaths()) {
if (massExtintionState != EXTINTION_CONFIRMED
&& massExtintionState != EXTINTION_FINISHING)
massExtintions++;
massExtintionState = EXTINTION_CONFIRMED;
} else {
switch (massExtintionState) {
case (EXTINTION_NO):
massExtintionState = EXTINTION_POSSIBLE;
break;
case (EXTINTION_POSSIBLE):
massExtintionState = EXTINTION_CONFIRMED;
massExtintions++;
break;
case (EXTINTION_FINISHING):
massExtintionState = EXTINTION_CONFIRMED;
break;
}
}
} else {
switch (massExtintionState) {
case (EXTINTION_POSSIBLE):
case (EXTINTION_FINISHING):
massExtintionState = EXTINTION_NO;
break;
case (EXTINTION_CONFIRMED):
massExtintionState = EXTINTION_FINISHING;
break;
}
}
//System.out.println(deathLastTime + " " + getAverageDeaths() + " " +
//massExtintionState + " " + massExtintions);
// lastTimePopulation = population;
populationSum += population;
if (O2 > maxOxygen) {
maxOxygen = O2;
maxOxygenTime = time;
}
if (O2 < minOxygen) {
minOxygen = O2;
minOxygenTime = time;
}
if (CO2 > maxCarbonDioxide) {
maxCarbonDioxide = CO2;
maxCarbonDioxideTime = time;
}
if (CO2 < minCarbonDioxide) {
minCarbonDioxide = CO2;
minCarbonDioxideTime = time;
}
if (birthLastTime > maxBirths)
maxBirths = birthLastTime;
if (deathLastTime > maxDeaths)
maxDeaths = deathLastTime;
if (populationList.size() == 100)
populationList.remove(0);
populationList.add(Double.valueOf(population));
if (deathList.size() == 100)
deathList.remove(0);
deathList.add(Double.valueOf(deathLastTime));
if (birthList.size() == 100)
birthList.remove(0);
birthList.add(Double.valueOf(birthLastTime));
if (oxygenList.size() == 100)
oxygenList.remove(0);
oxygenList.add(Double.valueOf(O2));
if (carbonDioxideList.size() == 100)
carbonDioxideList.remove(0);
carbonDioxideList.add(Double.valueOf(CO2));
deathLastTime = 0;
birthLastTime = 0;
}
public void findBestAliveBeings(List<Organism> organisms) {
Organism org;
aliveBeingMostChildren = null;
aliveBeingMostChildrenNumber = 0;
aliveBeingMostKills = null;
aliveBeingMostKillsNumber = 0;
aliveBeingMostInfections = null;
aliveBeingMostInfectionsNumber = 0;
synchronized(organisms) {
for (Iterator<Organism> it = organisms.iterator(); it.hasNext();) {
org = it.next();
if (org.isAlive()) {
if (org.getTotalChildren() > aliveBeingMostChildrenNumber) {
aliveBeingMostChildrenNumber = org.getTotalChildren();
aliveBeingMostChildren = org.getGeneticCode();
}
if (org.getTotalKills() > aliveBeingMostKillsNumber) {
aliveBeingMostKillsNumber = org.getTotalKills();
aliveBeingMostKills = org.getGeneticCode();
}
if (org.getTotalInfected() > aliveBeingMostInfectionsNumber) {
aliveBeingMostInfectionsNumber = org.getTotalInfected();
aliveBeingMostInfections = org.getGeneticCode();
}
}
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.