Debian Codegraph @

src/dr/inference/model/IntersectionBounds.java

raw symbols SCIP
1 /*
2 * IntersectionBounds.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.inference.model;
27
28 import java.util.ArrayList;
29
30
31 public class IntersectionBounds implements Bounds<Double> {
32
33 IntersectionBounds(int dimension) {
34 this.dimension = dimension;
35 }
36
37 public void addBounds(Bounds<Double> boundary) {
38 if (boundary.getBoundsDimension() != dimension) {
39 throw new IllegalArgumentException("Incorrect dimension of bounds, expected " +
40 dimension + " but received " + boundary.getBoundsDimension());
41 }
42 if (bounds == null) {
43 bounds = new ArrayList<Bounds<Double>>();
44 }
45 bounds.add(boundary);
46 }
47
48 /**
49 * Gets the maximum lower limit of this parameter and all its slave parameters
50 */
51 public Double getLowerLimit(int index) {
52
53 double lower = Double.NEGATIVE_INFINITY;
54 if (bounds != null) {
55 for (Bounds<Double> boundary : bounds) {
56 if (boundary.getLowerLimit(index) > lower) {
57 lower = boundary.getLowerLimit(index);
58 }
59 }
60 }
61 return lower;
62 }
63
64 /**
65 * Gets the minimum upper limit of this parameter and all its slave parameters
66 */
67 public Double getUpperLimit(int index) {
68
69 double upper = Double.POSITIVE_INFINITY;
70 if (bounds != null) {
71 for (Bounds<Double> boundary : bounds) {
72 if (boundary.getUpperLimit(index) < upper) {
73 upper = boundary.getUpperLimit(index);
74 }
75 }
76 }
77 return upper;
78 }
79
80 public int getBoundsDimension() {
81 return dimension;
82 }
83
84 public String toString() {
85 String str = "upper=[" + getUpperLimit(0);
86 for (int i = 1; i < getBoundsDimension(); i++) {
87 str += ", " + getUpperLimit(i);
88 }
89 str += "] lower=[" + getLowerLimit(0);
90 for (int i = 1; i < getBoundsDimension(); i++) {
91 str += ", " + getLowerLimit(i);
92 }
93
94 str += "]";
95 return str;
96 }
97
98 private ArrayList<Bounds<Double>> bounds = null;
99 private final int dimension;
100 }