1 2 21 package gov.nasa.ltl.trans; 23 24 import java.util.*; 25 26 27 30 class Node implements Comparable { 31 public static int accepting_conds = 0; 32 private static boolean init_collapsed = false; 33 private int nodeId; 34 private TreeSet incoming; 35 private TreeSet toBeDone; 36 private TreeSet old; 37 private TreeSet next; 38 private BitSet accepting; 39 private BitSet right_of_untils; 40 private Node OtherTransitionSource; 41 private int equivalenceId; 42 43 public Node () { 44 nodeId = Pool.assign(); 45 incoming = new TreeSet(); 46 toBeDone = new TreeSet(); 47 old = new TreeSet(); 48 next = new TreeSet(); 49 OtherTransitionSource = null; 50 accepting = new BitSet(accepting_conds); 51 right_of_untils = new BitSet(accepting_conds); 52 } 53 54 public Node (TreeSet in, TreeSet newForm, TreeSet done, TreeSet nx, 55 BitSet acc, BitSet rous) { 56 nodeId = Pool.assign(); 57 incoming = new TreeSet(in); 58 toBeDone = new TreeSet(newForm); 59 old = new TreeSet(done); 60 next = new TreeSet(nx); 61 OtherTransitionSource = null; 62 accepting = new BitSet(accepting_conds); 63 accepting.or(acc); 64 right_of_untils = new BitSet(accepting_conds); 65 right_of_untils.or(rous); 66 } 67 68 public static int getAcceptingConds () { 69 return accepting_conds; 70 } 71 72 public static Node createInitial (Formula form) { 73 accepting_conds = form.initialize(); 75 Node init = new Node(); 77 init.nodeId = 0; 78 79 if (form.getContent() != 't') { 80 init.decompose_ands_for_next(form); 81 } 82 83 return init; 84 } 85 86 public static void reset_static () { 87 accepting_conds = 0; 88 init_collapsed = false; 89 } 90 91 public TreeSet getField_next () { 92 return next; 93 } 94 95 public TreeSet getField_old () { 96 return old; 97 } 98 99 public int getId () { 100 return nodeId; 101 } 102 103 public boolean isInitial () { 104 return nodeId == 0; 105 } 106 107 public int getNodeId () { 108 return nodeId; 109 } 110 111 public void RTstructure (State[] RTautomaton) { 112 boolean safety = false; 113 114 if (RTautomaton[nodeId] == null) { 115 RTautomaton[nodeId] = new State(accepting, equivalenceId); 116 } else { 117 RTautomaton[nodeId].update_acc(accepting, equivalenceId); 118 } 119 120 if (is_safety_acc_node()) { 121 RTautomaton[nodeId].update_safety_acc(true); 122 safety = true; 123 } 124 125 Node Alternative = this; 126 127 while (Alternative != null) { 128 Iterator iterIncom = Alternative.incoming.iterator(); 129 Node nextNode; 130 131 while (iterIncom.hasNext()) { 132 nextNode = (Node) iterIncom.next(); 133 134 int stateId = nextNode.getId(); 135 136 if (RTautomaton[stateId] == null) { 137 RTautomaton[stateId] = new State(); 138 } 139 140 RTautomaton[stateId].add( 141 new Transition(Alternative.old, equivalenceId, accepting, safety)); 142 } 143 144 Alternative = Alternative.OtherTransitionSource; 145 } 146 } 147 148 public int compareTo (Object f) { 149 if (this == f) { 150 return 0; 151 } else { 152 return 1; 153 } 154 } 155 156 public boolean compare_accepting (Node nd) { 157 if ((nodeId == 0) && !init_collapsed) { 160 return true; 162 } 163 164 return (accepting.equals(nd.accepting)); } 166 167 182 public void debug () { 183 Iterator iterOld = old.iterator(); 184 Formula nextForm = null; 185 186 while (iterOld.hasNext()) { 188 nextForm = (Formula) iterOld.next(); 189 190 } 192 } 193 194 public void decompose_ands_for_next (Formula form) { 195 if (form.getContent() == 'A') { 196 decompose_ands_for_next(form.getSub1()); 197 decompose_ands_for_next(form.getSub2()); 198 } else if (is_redundant(next, null, form) == false) { 199 next.add(form); 200 } 201 } 202 203 public Automaton expand (Automaton states) { 204 Node tempNode; 206 207 if (toBeDone.isEmpty()) { 208 if (nodeId != 0) { 209 update_accepting(); 210 } 211 212 213 tempNode = states.alreadyThere(this); 215 216 if (tempNode != null) { 217 tempNode.modify(this); 219 220 return states; 221 } else { 222 Node NewN = new Node(); 223 NewN.incoming.add(this); 224 NewN.toBeDone.addAll(next); 225 226 states.add(this); 227 228 return (NewN.expand(states)); 229 } 230 } else { 232 Formula temp_form; 233 Formula ita = (Formula) toBeDone.first(); 234 toBeDone.remove(ita); 235 236 if (testForContradictions(ita)) { 238 return states; 240 } 241 242 if (ita.is_right_of_until(accepting_conds)) { 245 right_of_untils.or(ita.get_rightOfWhichUntils()); 246 } 247 248 TreeSet set_checked_against = new TreeSet(); 249 set_checked_against.addAll(old); 250 set_checked_against.addAll(toBeDone); 251 252 if (is_redundant(set_checked_against, next, ita)) { 253 return expand(states); 254 } 255 256 if (ita.getContent() == 'U') { accepting.set(ita.get_untils_index()); 260 261 } 263 264 if (!ita.is_literal()) { 265 switch (ita.getContent()) { 266 case 'U': 267 case 'W': 268 case 'V': 269 case 'O': 270 271 Node node2 = split(ita); 272 273 return node2.expand(this.expand(states)); 274 275 case 'X': 276 decompose_ands_for_next(ita.getSub1()); 277 278 return expand(states); 279 280 case 'A': 281 temp_form = ita.getSub1(); 282 283 if (!old.contains(temp_form)) { 284 toBeDone.add(temp_form); 285 } 286 287 temp_form = ita.getSub2(); 288 289 if (!old.contains(temp_form)) { 290 toBeDone.add(temp_form); 291 } 292 293 return expand(states); 294 295 default: 296 System.out.println("default case of switch entered"); 297 298 return null; 299 } 300 } else { 302 if (ita.getContent() != 't') { 305 old.add(ita); 306 } 307 308 return (expand(states)); 310 } 311 } 312 } 313 314 public int get_equivalenceId () { 315 return equivalenceId; 316 } 317 318 public void set_equivalenceId (int value) { 319 equivalenceId = value; 320 } 321 322 public void update_accepting () { 323 accepting.andNot(right_of_untils); 324 325 } 327 328 private static boolean is_redundant (TreeSet main_set, TreeSet next_set, 329 Formula ita) { 330 if ((ita.is_special_case_of_V(main_set)) || ((ita.is_synt_implied(main_set, next_set)) && 332 (!(ita.getContent() == 'U') || 333 (ita.getSub2().is_synt_implied(main_set, next_set))))) { 334 return true; 336 } else { 337 return false; 338 } 339 } 340 341 private boolean is_safety_acc_node () { 342 if (next.isEmpty()) { 343 return true; 344 } 345 346 Iterator iterNext = next.iterator(); 347 Formula nextForm = null; 348 349 while (iterNext.hasNext()) { 351 nextForm = (Formula) iterNext.next(); 352 353 if ((nextForm.getContent() != 'V') && (nextForm.getContent() != 'W')) { 354 return false; 355 } 356 } 357 358 return true; 359 } 360 361 private void modify (Node current) { 362 boolean match = false; 363 Node Tail = this; 364 Node Alternative = this; 365 366 if ((this.nodeId == 0) && !init_collapsed) { 367 accepting = current.accepting; 368 init_collapsed = true; 369 } 370 371 while (Alternative != null) { 372 if (Alternative.old.equals(current.old)) { 373 Alternative.incoming.addAll(current.incoming); 374 match = true; 375 } 376 377 Tail = Alternative; 378 Alternative = Alternative.OtherTransitionSource; 379 } 380 381 if (!match) { 382 Tail.OtherTransitionSource = current; 383 } 384 } 385 386 private Node split (Formula form) { 387 Formula temp_form; 389 390 Node Node2 = new Node(this.incoming, this.toBeDone, this.old, this.next, 392 this.accepting, this.right_of_untils); 393 394 temp_form = form.getSub2(); 395 396 if (!old.contains(temp_form)) 398 { 399 Node2.toBeDone.add(temp_form); 400 } 401 402 if (form.getContent() == 'V') { 404 temp_form = form.getSub1(); 405 406 if (!old.contains(temp_form)) 408 { 409 Node2.toBeDone.add(temp_form); 410 } 411 } 412 413 414 temp_form = form.getSub1(); 416 417 if (!old.contains(temp_form)) 419 { 420 toBeDone.add(temp_form); 421 } 422 423 temp_form = form.getNext(); 424 425 if (temp_form != null) { 426 decompose_ands_for_next(temp_form); 427 } 428 429 430 if (form.is_literal()) 431 { 432 old.add(form); 433 System.out.println("added " + form); Node2.old.add(form); 435 } 436 437 return Node2; 441 } 442 443 private boolean testForContradictions (Formula ita) { 444 Formula Not_ita = ita.negate(); 445 446 if (Not_ita.is_synt_implied(old, next)) { 447 return true; 448 } else { 449 return false; 450 } 451 } 452 } | Popular Tags |