1 2 package gov.nasa.ltl.trans; 21 22 import gov.nasa.ltl.graph.*; 23 24 import java.util.*; 25 26 27 30 class Transition { 31 private TreeSet propositions; 32 private int pointsTo; 33 private BitSet accepting; 34 private boolean safe_accepting; 35 36 public Transition (TreeSet prop, int nd_id, BitSet acc, boolean safety) { 37 propositions = prop; 38 pointsTo = nd_id; 39 accepting = new BitSet(Node.getAcceptingConds()); 40 accepting.or(acc); 41 safe_accepting = safety; 42 } 43 44 public void FSPoutput () { 45 if (propositions.isEmpty()) { 46 System.out.print("TRUE{"); 47 } else { 48 Iterator it = propositions.iterator(); 50 Formula nextForm = null; 51 StringBuffer act = new StringBuffer (); 52 char cont; boolean need_AND = false; 55 while (it.hasNext()) { 56 nextForm = (Formula) it.next(); 57 cont = nextForm.getContent(); 58 59 if (need_AND) { 60 act.append("_AND_"); 61 } 62 63 need_AND = true; 64 65 switch (cont) { 66 case 'N': 67 act.append('N'); 68 act.append(nextForm.getSub1().getName()); 69 70 break; 71 72 case 't': 73 act.append("TRUE"); 74 75 break; 76 77 default: 78 act.append(nextForm.getName()); 79 80 break; 81 } 82 } 83 84 System.out.print(act + "{"); 85 } 86 87 if (Node.accepting_conds == 0) { 88 if (safe_accepting == true) { 89 System.out.print("0"); 90 } 91 } else { 92 for (int i = 0; i < Node.accepting_conds; i++) { 93 if (!accepting.get(i)) { 94 System.out.print(i); 95 } 96 } 97 } 98 99 100 System.out.print("} -> S" + pointsTo + " "); 102 } 103 104 public void SMoutput (gov.nasa.ltl.graph.Node[] nodes, 105 gov.nasa.ltl.graph.Node node) { 106 String guard = "-"; 107 String action = "-"; 108 109 if (!propositions.isEmpty()) { 110 Iterator it = propositions.iterator(); 111 Formula nextForm = null; 112 StringBuffer sb = new StringBuffer (); 113 char cont; boolean need_AND = false; 116 while (it.hasNext()) { 117 nextForm = (Formula) it.next(); 118 cont = nextForm.getContent(); 119 120 if (need_AND) { 121 sb.append("&"); 122 } 123 124 need_AND = true; 125 126 switch (cont) { 127 case 'N': 128 sb.append('!'); 129 sb.append(nextForm.getSub1().getName()); 130 131 break; 132 133 case 't': 134 sb.append("true"); 135 136 break; 137 138 default: 139 sb.append(nextForm.getName()); 140 141 break; 142 } 143 } 144 145 guard = sb.toString(); 146 } 147 148 Edge e = new Edge(node, nodes[pointsTo], guard, action); 149 150 if (Node.accepting_conds == 0) { 151 e.setBooleanAttribute("acc0", true); 158 159 } else { 161 for (int i = 0; i < Node.accepting_conds; i++) { 162 if (!accepting.get(i)) { 163 e.setBooleanAttribute("acc" + i, true); 164 165 } 167 } 168 } 169 } 170 171 public boolean enabled (Hashtable ProgramState) { 172 Iterator mustHold = propositions.iterator(); 173 Formula form = null; 174 char c; 175 Boolean value; 176 177 while (mustHold.hasNext()) { 178 form = (Formula) mustHold.next(); 179 180 switch (c = form.getContent()) { 181 case 'N': 182 value = (Boolean ) ProgramState.get(form.getSub1().getName()); 183 184 if (value == null) { 185 return false; 187 } else if (value.booleanValue()) { 188 return false; 189 } 190 191 break; 192 193 case 't': 194 break; 195 196 case 'p': 197 value = (Boolean ) ProgramState.get(form.getName()); 198 199 if (value == null) { 200 return false; 202 } else if (!value.booleanValue()) { 203 return false; 204 } 205 206 break; 207 } 208 } 209 210 return true; 211 } 212 213 public int goesTo () { 214 return pointsTo; 215 } 216 } | Popular Tags |