1 2 21 package gov.nasa.ltl.trans; 23 24 import gov.nasa.ltl.graph.*; 25 26 27 30 class LinkNode { 31 private Node node; 32 private LinkNode next; 33 34 public LinkNode (Node nd, LinkNode nxt) { 35 node = nd; 36 next = nxt; 37 } 38 39 public LinkNode getNext () { 40 return next; 41 } 42 43 public Node getNode () { 44 return node; 45 } 46 47 public void LinkWith (LinkNode lk) { 48 next = lk; 49 } 50 } 51 52 55 class Automaton { 56 private LinkNode head; 57 private LinkNode tail; 58 private Node[] equivalence_classes; 60 public Automaton () { 61 head = tail = null; 62 equivalence_classes = null; 63 } 64 65 public static void FSPoutput (State[] automaton) { 66 boolean comma = false; 67 68 if (automaton == null) { 69 System.out.println("\n\nRES = STOP."); 70 71 return; 72 } else { 73 System.out.println("\n\nRES = S0,"); 74 } 75 76 int size = Pool.assign(); 77 78 for (int i = 0; i < size; i++) { 79 if ((automaton[i] != null) && 80 (i == automaton[i].get_representativeId())) { 82 if (comma) { 83 System.out.println("),"); 84 } 85 86 comma = true; 87 System.out.print("S" + automaton[i].get_representativeId()); 88 System.out.print("="); 89 automaton[i].FSPoutput(); 90 } 91 } 92 93 System.out.println(").\n"); 94 } 95 96 public static Graph SMoutput (State[] automaton) { 97 Graph g = new Graph(); 98 g.setStringAttribute("type", "gba"); 99 g.setStringAttribute("ac", "edges"); 100 101 if (automaton == null) { 102 return g; 103 } 104 105 int size = Pool.assign(); 106 gov.nasa.ltl.graph.Node[] nodes = new gov.nasa.ltl.graph.Node[size]; 107 108 for (int i = 0; i < size; i++) { 109 if ((automaton[i] != null) && 110 (i == automaton[i].get_representativeId())) { 111 nodes[i] = new gov.nasa.ltl.graph.Node(g); 112 nodes[i].setStringAttribute("label", 113 "S" + 114 automaton[i].get_representativeId()); 115 } 116 } 117 118 for (int i = 0; i < size; i++) { 119 if ((automaton[i] != null) && 120 (i == automaton[i].get_representativeId())) { 121 automaton[i].SMoutput(nodes, nodes[i]); 122 } 123 } 124 125 if (Node.accepting_conds == 0) { 126 g.setIntAttribute("nsets", 1); 127 } else { 128 g.setIntAttribute("nsets", Node.accepting_conds); 129 } 130 131 return g; 132 } 133 134 public void add (Node nd) { 135 LinkNode newNode = new LinkNode(nd, null); 136 137 if (head == null) { 139 head = tail = newNode; 140 } else { 142 tail.LinkWith(newNode); 143 tail = newNode; 144 } 145 } 146 147 public Node alreadyThere (Node nd) { 148 152 LinkNode nextNd = head; 153 154 while (nextNd != null) { 155 Node currState = nextNd.getNode(); 156 157 if (currState.getField_next().equals(nd.getField_next()) && 158 currState.compare_accepting(nd) && 159 (Translator.get_algorithm() == Translator.LTL2BUCHI || 160 (currState.getField_old().equals(nd.getField_old())))) { 161 return currState; 163 } else { 164 nextNd = nextNd.getNext(); 165 } 166 } 167 168 return null; 170 } 171 172 177 public int index_equivalence (Node nd) { 178 int index; 180 181 for (index = 0; index < Pool.assign(); index++) { 182 if (equivalence_classes[index] == null) { 183 break; 185 } else if ((Translator.get_algorithm() == Translator.LTL2BUCHI) && 186 (equivalence_classes[index].getField_next().equals(nd.getField_next()))) { 187 return (equivalence_classes[index].getNodeId()); 189 } 190 } 191 192 if (index == Pool.assign()) { 193 System.out.println( 194 "ERROR - size of equivalence classes array was incorrect"); 195 } 196 197 equivalence_classes[index] = nd; 198 199 return (equivalence_classes[index].getNodeId()); 200 } 201 202 public State[] structForRuntAnalysis () { 203 Pool.stop(); 205 206 int automatonSize = Pool.assign(); 207 State[] RTstruct = new State[automatonSize]; 208 equivalence_classes = new Node[automatonSize]; 209 210 if (head == null) { 211 return RTstruct; 212 } 213 214 LinkNode nextNd = head; 215 Node current; 216 217 while (nextNd != null) { 218 current = nextNd.getNode(); 219 current.set_equivalenceId(index_equivalence(current)); 220 nextNd.getNode().RTstructure(RTstruct); 221 nextNd = nextNd.getNext(); 222 } 223 224 return RTstruct; 225 } 226 } | Popular Tags |