| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.evomodel.epidemiology.casetocase; |
| 27 |
|
| 28 |
import dr.evolution.alignment.Alignment; |
| 29 |
import dr.evolution.tree.NodeRef; |
| 30 |
import dr.evomodel.tree.TreeModel; |
| 31 |
import dr.inference.model.*; |
| 32 |
|
| 33 |
import java.util.ArrayList; |
| 34 |
import java.util.Arrays; |
| 35 |
import java.util.HashSet; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class BranchMapModel extends AbstractModel { |
| 41 |
|
| 42 |
private AbstractCase[] map; |
| 43 |
private AbstractCase[] storedMap; |
| 44 |
public final static String BRANCH_MAP_MODEL = "branchMapModel"; |
| 45 |
|
| 46 |
public BranchMapModel(PartitionedTreeModel tree){ |
| 47 |
super(BRANCH_MAP_MODEL); |
| 48 |
map = new AbstractCase[tree.getNodeCount()]; |
| 49 |
storedMap = new AbstractCase[tree.getNodeCount()]; |
| 50 |
} |
| 51 |
|
| 52 |
public void set(int index, AbstractCase aCase, boolean silent){ |
| 53 |
|
| 54 |
AbstractCase oldCase = map[index]; |
| 55 |
|
| 56 |
map[index] = aCase; |
| 57 |
|
| 58 |
if(!silent){ |
| 59 |
pushMapChangedEvent(new BranchMapChangedEvent(index, oldCase, aCase)); |
| 60 |
} |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
public AbstractCase get(int index){ |
| 65 |
return map[index]; |
| 66 |
} |
| 67 |
|
| 68 |
public void pushMapChangedEvents(ArrayList<BranchMapChangedEvent> events){ |
| 69 |
listenerHelper.fireModelChanged(this, events); |
| 70 |
} |
| 71 |
|
| 72 |
public void pushMapChangedEvent(BranchMapChangedEvent event){ |
| 73 |
ArrayList<BranchMapChangedEvent> out = new ArrayList<BranchMapChangedEvent>(); |
| 74 |
out.add(event); |
| 75 |
|
| 76 |
pushMapChangedEvents(out); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public AbstractCase[] getArray(){ |
| 82 |
return map; |
| 83 |
} |
| 84 |
|
| 85 |
public void setAll(AbstractCase[] newMap, boolean silent){ |
| 86 |
ArrayList<BranchMapChangedEvent> changes = new ArrayList<BranchMapChangedEvent>(); |
| 87 |
|
| 88 |
for(int i=0; i<map.length; i++){ |
| 89 |
if(map[i]!=newMap[i]){ |
| 90 |
changes.add(new BranchMapChangedEvent(i, map[i], newMap[i])); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
if(!silent){ |
| 95 |
pushMapChangedEvents(changes); |
| 96 |
} |
| 97 |
|
| 98 |
map = newMap; |
| 99 |
} |
| 100 |
|
| 101 |
public AbstractCase[] getArrayCopy(){ |
| 102 |
return Arrays.copyOf(map, map.length); |
| 103 |
} |
| 104 |
|
| 105 |
protected void handleModelChangedEvent(Model model, Object object, int index) { |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
public int size() { |
| 110 |
return map.length; |
| 111 |
} |
| 112 |
|
| 113 |
protected void storeState() { |
| 114 |
storedMap = Arrays.copyOf(map, map.length); |
| 115 |
} |
| 116 |
|
| 117 |
protected void restoreState() { |
| 118 |
map = storedMap; |
| 119 |
} |
| 120 |
|
| 121 |
protected void acceptState() { |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
protected void handleVariableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 126 |
|
| 127 |
} |
| 128 |
|
| 129 |
public class BranchMapChangedEvent { |
| 130 |
|
| 131 |
private final int nodeToRecalculate; |
| 132 |
private final AbstractCase oldCase; |
| 133 |
private final AbstractCase newCase; |
| 134 |
|
| 135 |
public BranchMapChangedEvent(int node, AbstractCase oldCase, AbstractCase newCase){ |
| 136 |
this.nodeToRecalculate = node; |
| 137 |
this.oldCase = oldCase; |
| 138 |
this.newCase = newCase; |
| 139 |
} |
| 140 |
|
| 141 |
public int getNodeToRecalculate(){ |
| 142 |
return nodeToRecalculate; |
| 143 |
} |
| 144 |
|
| 145 |
public AbstractCase getOldCase() { |
| 146 |
return oldCase; |
| 147 |
} |
| 148 |
|
| 149 |
public AbstractCase getNewCase() { |
| 150 |
return newCase; |
| 151 |
} |
| 152 |
|
| 153 |
} |
| 154 |
|
| 155 |
} |