Debian Codegraph @

src/dr/evomodel/coalescent/structure/ConstantMigrationModel.java

raw symbols SCIP
1 /*
2 * ConstantMigrationModel.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.structure;
27
28 import dr.evolution.colouring.ColourChangeMatrix;
29 import dr.inference.model.Parameter;
30 import dr.inference.model.Variable;
31 import dr.xml.*;
32
33 /**
34 * A wrapper for ConstantPopulation.
35 *
36 * @author Andrew Rambaut
37 * @author Alexei Drummond
38 * @version $Id: ConstantMigrationModel.java,v 1.4 2006/09/08 14:28:07 rambaut Exp $
39 */
40 @Deprecated
41 public class ConstantMigrationModel extends MigrationModel {
42 //
43 // Public stuff
44 //
45
46 public static String CONSTANT_MIGRATION_MODEL = "constantMigrationModel";
47 public static String MIGRATION_RATES = "migrationRates";
48
49 /**
50 * Construct demographic model with default settings
51 */
52 public ConstantMigrationModel(int demeCount, Parameter migrationParameter) {
53
54 this(CONSTANT_MIGRATION_MODEL, demeCount, migrationParameter);
55 }
56
57 /**
58 * Construct demographic model with default settings
59 */
60 public ConstantMigrationModel(String name, int demeCount, Parameter migrationParameter) {
61
62 super(name);
63
64 this.demeCount = demeCount;
65 this.migrationParameter = migrationParameter;
66 addVariable(migrationParameter);
67 migrationParameter.addBounds(new Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, migrationParameter.getDimension()));
68 }
69
70 // general functions
71
72 public ColourChangeMatrix getMigrationMatrix() {
73 if (colourChangeMatrix == null) {
74 colourChangeMatrix = new ColourChangeMatrix(migrationParameter.getParameterValues(), demeCount);
75 }
76 return colourChangeMatrix;
77 }
78
79 public double[] getMigrationRates(double time) {
80 return migrationParameter.getParameterValues();
81 }
82
83
84 protected final void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
85 colourChangeMatrix = null;
86 }
87
88 protected void restoreState() {
89 colourChangeMatrix = null;
90 }
91
92 /**
93 * Parses an element from an DOM document into a ConstantPopulation.
94 */
95 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
96
97 public String getParserName() {
98 return CONSTANT_MIGRATION_MODEL;
99 }
100
101 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
102
103 int demeCount = 2;
104
105 XMLObject cxo = xo.getChild(MIGRATION_RATES);
106 Parameter migrationParameter = (Parameter) cxo.getChild(Parameter.class);
107
108
109 return new ConstantMigrationModel(demeCount, migrationParameter);
110 }
111
112 //************************************************************************
113 // AbstractXMLObjectParser implementation
114 //************************************************************************
115
116 public String getParserDescription() {
117 return "A migration model representing constant migration rates through time.";
118 }
119
120 public Class getReturnType() {
121 return ConstantMigrationModel.class;
122 }
123
124 public XMLSyntaxRule[] getSyntaxRules() {
125 return rules;
126 }
127
128 private final XMLSyntaxRule[] rules = {
129 new ElementRule(MIGRATION_RATES,
130 new XMLSyntaxRule[]{new ElementRule(Parameter.class)})
131 };
132 };
133
134 //
135 // protected stuff
136 //
137
138 private int demeCount;
139 private Parameter migrationParameter;
140 private ColourChangeMatrix colourChangeMatrix = null;
141 }