Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 package dfengine;
00025
00026 import java.util.*;
00027
00028 import utils.*;
00029
00030 public class RepairOrderDAG extends DoubleLinkedDAG {
00031
00032
00033
00034
00035 protected TreeMap components = new TreeMap();
00036
00037 protected GraphMatrix transClosure = null;
00038
00039
00040 public RepairOrderDAG(ModeAssignment ma) {
00041 createFromModeAssignment(ma);
00042
00043 assert(invariant());
00044 }
00045
00046
00047
00048
00049 protected void addNode(Component comp) {
00050 assert(invariant());
00051
00052 RepairOrderDAGNode newNode = new RepairOrderDAGNode(comp);
00053 super.addNode(newNode);
00054 components.put(comp, newNode);
00055
00056 assert(invariant());
00057 }
00058
00059 public RepairOrderDAGNode getNode(Component comp) {
00060 Object o = components.get(comp);
00061 if (o == null) return null;
00062 else return (RepairOrderDAGNode)o;
00063 }
00064
00065 public void addEdge(Component from, Component to) {
00066
00067 assert(invariant());
00068
00069 RepairOrderDAGNode fromNode = getNode(from);
00070 RepairOrderDAGNode toNode = getNode(to);
00071
00072 addEdge(fromNode, toNode);
00073 updateTransClosureForNewEdge(getTransitiveClosure(), fromNode, toNode, false);
00074
00075
00076 assert(hasEdge(from, to));
00077 assert(correctTransitiveClosure(getTransitiveClosure(), false));
00078
00079 assert(invariant());
00080 }
00081
00082 public boolean hasEdge(Component from, Component to) {
00083 return hasEdge(getNode(from), getNode(to));
00084 }
00085
00086 protected void createFromModeAssignment(ModeAssignment ma) {
00087
00088 System.out.println("createFromModeAssignment(): ma = " + ma.toStringShort());
00089
00090
00091
00092 Iterator itModes = ma.iterator();
00093 while (itModes.hasNext()) {
00094 Mode mode = (Mode)itModes.next();
00095 addNode(mode.component);
00096 }
00097
00098
00099
00100 itModes = ma.iterator();
00101 while (itModes.hasNext()) {
00102 Mode mode = (Mode)itModes.next();
00103 if (mode.type == Mode.MODE_DF) {
00104 RepairOrderDAGNode node = getNode(mode.component);
00105 RepairOrderDAGNode parentNode = getNode(mode.parent);
00106 addEdge(parentNode, node);
00107 }
00108 }
00109
00110 transClosure = null;
00111
00112 System.out.println("createFromModeAssignment() results in: " + this);
00113 }
00114
00115 protected boolean invariant() {
00116
00117
00118 if ((transClosure != null) && !correctTransitiveClosure(transClosure, false)) {
00119 System.err.println("ERROR: invariant of RepairOrderDAG violated: incorrect transitive closure!");
00120 return false;
00121 }
00122
00123
00124 Iterator itNodes = iterator();
00125 while (itNodes.hasNext()) {
00126 RepairOrderDAGNode n = (RepairOrderDAGNode)itNodes.next();
00127 if (!n.invariant()) {
00128 System.err.println("ERROR: invariant of RepairOrderDAG violated: invariant of a node does not hold!");
00129 return false;
00130 }
00131 }
00132
00133
00134 if (!uniqueComponents()) {
00135 System.err.println("ERROR: invariant of RepairOrderDAG violated: components are not unique!");
00136 return false;
00137 }
00138
00139 return true;
00140 }
00141
00142 public GraphMatrix getTransitiveClosure() {
00143 if (transClosure == null) transClosure = computeTransitiveClosure(false);
00144 return transClosure;
00145 }
00146
00147 public boolean equalComponents(Set comps) {
00148
00149 return (components.keySet().equals(comps));
00150
00151 }
00152
00153
00154 protected boolean uniqueComponents() {
00155 for (int i = 0; i < nodes.size(); ++i) {
00156 for (int j = i + 1; j < nodes.size(); ++j) {
00157 if (nodes.get(i).equals(nodes.get(j))) return false;
00158 }
00159 }
00160 return true;
00161 }
00162
00163 public String toString() {
00164 if (!uniqueComponents()) {
00165 System.err.println("ERROR: invariant of RepairOrderDAG violated: components are not unique!");
00166 }
00167
00168 StringBuffer result = new StringBuffer();
00169 ToStringVisitor visitor = new ToStringVisitor(result);
00170 visitRoots(visitor, true);
00171 return result.toString();
00172 }
00173
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 class ToStringVisitor extends DoubleLinkedDAGVisitor {
00183
00184 StringBuffer str;
00185
00186 public ToStringVisitor(StringBuffer str) {
00187 this.str = str;
00188 }
00189
00190 public boolean wantMoreNodes() {
00191 return true;
00192 }
00193
00194 public void visit(DoubleLinkedDAGNode node) {
00195 Iterator itParents = node.getParentsIterator();
00196 if (!itParents.hasNext()) {
00197 if (str.length() > 0) str.append("; ");
00198 str.append("IF(" + node.toString() + ")");
00199 }
00200 while (itParents.hasNext()) {
00201 DoubleLinkedDAGNode parentNode = (DoubleLinkedDAGNode)itParents.next();
00202 if (str.length() > 0) str.append("; ");
00203 str.append("DF(" + parentNode.toString() + ", " + node.toString() + ")");
00204 }
00205 }
00206
00207 public String getStr() {
00208 return str.toString();
00209 }
00210
00211 }