Debian Codegraph @

src/dr/evomodel/coalescent/MultiLociTreeSet.java

raw symbols SCIP
1 /*
2 * MultiLociTreeSet.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.evomodel.coalescent;
27
28 import dr.evolution.tree.Tree;
29 import dr.evolution.coalescent.TreeIntervals;
30 import dr.evomodel.tree.TreeModel;
31 import dr.inference.model.Model;
32 import dr.inference.model.ModelListener;
33
34 import java.util.Arrays;
35 import java.util.List;
36
37 /**
38 * @author Joseph Heled
39 * Date: 19/11/2007
40 */
41 public interface MultiLociTreeSet {
42 /**
43 *
44 * @return Number of independent loci in set.
45 */
46 int nLoci();
47
48 /**
49 *
50 * @param nt index of tree to return
51 * @return the nt's loci (i.e. tree)
52 */
53 Tree getTree(int nt);
54
55 /**
56 *
57 * @param nt index of tree to return
58 * @return Coalecsent intervals for nt's tree
59 */
60 TreeIntervals getTreeIntervals(int nt);
61
62 /**
63 *
64 * @param nt
65 * @return Population factor of nt's tree
66 */
67 double getPopulationFactor(int nt);
68
69 void storeTheState();
70
71 void restoreTheState();
72
73 public class Default implements MultiLociTreeSet, ModelListener {
74 private final List<TreeModel> trees;
75 private final List<Double> factors;
76 private final boolean[] dirty;
77 private final boolean[] gotDirty;
78
79 private final TreeIntervals[] intervals;
80
81 public Default(List<TreeModel> trees, List<Double> popFactors) {
82 this.trees = trees;
83 this.factors = popFactors;
84
85 for(TreeModel t : trees ) {
86 t.addModelListener(this);
87 }
88
89 final int nt = trees.size();
90 dirty = new boolean[nt];
91 gotDirty = new boolean[nt];
92 intervals = new TreeIntervals[nt];
93 Arrays.fill(dirty, true);
94 Arrays.fill(intervals, null);
95 }
96
97 public int nLoci() {
98 return trees.size();
99 }
100
101 public Tree getTree(int nt) {
102 return trees.get(nt);
103 }
104
105 public TreeIntervals getTreeIntervals(int nt) {
106 if( dirty[nt] ) {
107 intervals[nt] = new TreeIntervals(trees.get(nt));
108 intervals[nt].setMultifurcationLimit(0);
109 dirty[nt] = false;
110 }
111 return intervals[nt];
112 }
113
114 public double getPopulationFactor(int nt) {
115 return factors.get(nt);
116 }
117
118 public void storeTheState() {
119 Arrays.fill(gotDirty, false);
120 }
121
122 public void restoreTheState() {
123 for(int nt = 0; nt < gotDirty.length; ++nt) {
124 if( gotDirty[nt] ) {
125 dirty[nt] = true;
126 }
127 }
128 }
129
130 public void modelChangedEvent(Model model, Object object, int index) {
131 assert model instanceof TreeModel;
132 final int k = trees.indexOf((TreeModel)model);
133 dirty[k] = gotDirty[k] = true;
134 }
135
136 public void modelRestored(Model model) {}
137 }
138 }