Debian Codegraph @

src/dr/evolution/coalescent/structure/Event.java

raw symbols SCIP
1 /*
2 * Event.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.coalescent.structure;
27
28 import dr.evolution.coalescent.IntervalType;
29
30 /**
31 * @author Alexei
32 * @version $Id: Event.java,v 1.5 2005/09/21 15:58:34 rambaut Exp $
33 */
34 public class Event implements Comparable {
35
36 double time;
37 int[] lineageChanges;
38 private IntervalType type;
39 private int aboveColour;
40 private int belowColour;
41
42 public static Event createCoalescentEvent(double time, int colour, int colourCount) {
43
44 int[] lineageChanges = new int[colourCount];
45 lineageChanges[colour] = -1;
46
47 return new Event(time, IntervalType.COALESCENT, lineageChanges, colour, colour);
48 }
49
50 public static Event createAddSampleEvent(double time, int colour, int colourCount) {
51
52 int[] lineageChanges = new int[colourCount];
53 lineageChanges[colour] = +1;
54
55 return new Event(time, IntervalType.SAMPLE, lineageChanges, colour, colour);
56 }
57
58 public static Event createMigrationEvent(double time, int belowColour, int aboveColour, int colourCount) {
59
60 int[] lineageChanges = new int[colourCount];
61 lineageChanges[belowColour] = -1;
62 lineageChanges[aboveColour] = +1;
63
64 return new Event(time, IntervalType.MIGRATION, lineageChanges, aboveColour, belowColour);
65 }
66
67 private Event(double time, IntervalType type, int[] lineageChanges, int aboveColour, int belowColour) {
68 this.time = time;
69 this.type = type;
70 this.lineageChanges = lineageChanges;
71 this.aboveColour = aboveColour;
72 this.belowColour = belowColour;
73 }
74
75 public int getAboveColour() {
76 return aboveColour;
77 }
78
79 public int getBelowColour() {
80 return belowColour;
81 }
82
83 public IntervalType getType() {
84 return type;
85 }
86
87 public String toString() {
88 return type + " event at time " + time + " (above=" + aboveColour + ", below=" + belowColour + ")";
89 }
90
91 public int compareTo(Object o) {
92 Event e2 = (Event) o;
93
94 return new Double(time).compareTo(e2.time);
95 }
96 }