Debian Codegraph @

src/dr/evolution/phylogeny/Phylogeny.java

raw symbols SCIP
1 /*
2 * Phylogeny.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.evolution.phylogeny;
27
28 public abstract class Phylogeny {
29
30 public static final int INCREMENT=10000;
31
32 Lineage[] lineages = new Lineage[INCREMENT];
33 int lineageCount = 0;
34 int availableSize = 0;
35
36 int[] extantLineages;
37
38 Phylogeny() {
39 }
40
41 public void lineageBirth(Lineage lineage, double birthTime) {
42
43 int descendantIndex1 = createLineage(lineage, birthTime);
44 int descendantIndex2 = createLineage(lineage, birthTime);
45
46 int lineageIndex = extantLineages[lineage.getExtantIndex()];
47 extantLineages[lineage.getExtantIndex()] = descendantIndex1;
48 }
49
50 public void lineageDeath(Lineage lineage, double deathTime) {
51
52 lineage.setDeathTime(deathTime);
53 }
54
55 private int createLineage(Lineage parent, double birthTime) {
56 int index = lineageCount;
57
58 if (availableSize > 0) {
59 // there are some unused lineage available so return one..
60 availableSize--;
61 } else {
62
63 if (lineageCount == lineages.length) {
64 // run out of space in the array so reallocate it...
65 Lineage[] newLineages = new Lineage[lineages.length + INCREMENT];
66 for (int i = 0; i < lineages.length; i++) {
67 newLineages[i] = lineages[i];
68 }
69
70 lineages = newLineages;
71 }
72 lineages[index] = newLineage(parent, birthTime);
73 lineages[index].setIndex(index);
74 }
75
76 lineageCount++;
77
78 return index;
79 }
80
81 /**
82 * Override this to return a new class that implements the Lineage interface
83 */
84 protected abstract Lineage newLineage(Lineage parent, double birthTime);
85
86 }