Debian Codegraph @

src/dr/evomodel/epidemiology/DynamicalForce.java

raw symbols SCIP
1 /*
2 * DynamicalForce.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.epidemiology;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32 * @author Trevor Bedford
33 */
34 public class DynamicalForce {
35
36 private String name = "force";
37 private double coefficient = 0.0;
38 private List<DynamicalVariable> multipliers = new ArrayList<DynamicalVariable>();
39 private List<DynamicalVariable> divisors = new ArrayList<DynamicalVariable>();
40 private DynamicalVariable increasingVariable;
41 private DynamicalVariable decreasingVariable;
42
43 private double storedCoefficient = 0.0;
44
45 public DynamicalForce(String n, double c, DynamicalVariable increasing, DynamicalVariable decreasing) {
46 name = n;
47 coefficient = c;
48 increasingVariable = increasing;
49 decreasingVariable = decreasing;
50 }
51
52 public String getName() {
53 return name;
54 }
55
56 public void addMultiplier(DynamicalVariable var) {
57 multipliers.add(var);
58 }
59
60 public void addDivisor(DynamicalVariable var) {
61 divisors.add(var);
62 }
63
64 // reset
65 public void reset(double c) {
66 coefficient = c;
67 }
68
69 public void store() {
70 storedCoefficient = coefficient;
71 }
72
73 public void restore() {
74 coefficient = storedCoefficient;
75 }
76
77 public double getForce(double t) {
78 double force = coefficient;
79 for (DynamicalVariable var : multipliers) {
80 force *= var.getValue(t);
81 }
82 for (DynamicalVariable var : divisors) {
83 force /= var.getValue(t);
84 }
85 if (increasingVariable.getValue(t) < 0 || decreasingVariable.getValue(t) < 0) {
86 force = 0.0;
87 }
88 return force;
89 }
90
91 public void modCurrentValue(double t, double dt) {
92 double dv = getForce(t) * dt;
93 increasingVariable.modCurrentValue(dv);
94 decreasingVariable.modCurrentValue(-dv);
95 }
96
97 }