00001 package gov.nasa.arc.ase.ltl;
00002
00003
00004 import java.util.*;
00005 import gov.nasa.arc.ase.util.graph.*;
00006
00007 class Transition
00008 {
00009 private TreeSet propositions;
00010 private int pointsTo;
00011 private BitSet accepting;
00012 private boolean safe_accepting;
00013
00014
00015 public Transition (TreeSet prop, int nd_id, BitSet acc, boolean safety)
00016 {
00017 propositions = prop;
00018 pointsTo = nd_id;
00019 accepting = new BitSet(Node.getAcceptingConds());
00020 accepting.or(acc);
00021 safe_accepting = safety;
00022 }
00023 public boolean enabled (Hashtable ProgramState)
00024 {
00025 Iterator mustHold = propositions.iterator();
00026 Formula form = null;
00027 char c;
00028 Boolean value;
00029
00030 while (mustHold.hasNext())
00031 {
00032 form = (Formula) mustHold.next();
00033 switch (c = form.getContent()) {
00034 case 'N':
00035 value = (Boolean) ProgramState.get(form.getSub1().getName());
00036 if (value== null)
00037 {
00038
00039 return false;
00040 }
00041 else
00042 if (value.booleanValue()) return false;
00043 break;
00044 case 't':
00045 break;
00046 case 'p':
00047 value = (Boolean) ProgramState.get(form.getName());
00048 if (value== null)
00049 {
00050
00051 return false;
00052 }
00053 else
00054 if (!value.booleanValue()) return false;
00055 break;
00056 }
00057 }
00058 return true;
00059 }
00060 public void FSPoutput()
00061 {
00062 if (propositions.isEmpty())
00063 System.out.print("TRUE{");
00064 else
00065 {
00066
00067 Iterator it = propositions.iterator();
00068 Formula nextForm = null;
00069 StringBuffer act = new StringBuffer();
00070 char cont;
00071 boolean need_AND = false;
00072
00073 while (it.hasNext())
00074 {
00075 nextForm = (Formula) it.next();
00076
00077 {
00078
00079 cont = nextForm.getContent();
00080 if (need_AND)
00081 act.append("_AND_");
00082 need_AND = true;
00083 switch (cont)
00084 {
00085 case 'N': act.append('N');
00086 act.append(nextForm.getSub1().getName());
00087 break;
00088 case 't' : act.append("TRUE");
00089 break;
00090 default: act.append(nextForm.getName());
00091 break;
00092 }
00093 }
00094 }
00095 System.out.print(act + "{");
00096 }
00097 if (Node.accepting_conds == 0)
00098 {
00099 if (safe_accepting == true)
00100 {
00101 System.out.print("0");
00102 }
00103 }
00104 else
00105 {
00106 for (int i=0; i<Node.accepting_conds; i++)
00107 if (!accepting.get(i))
00108 System.out.print(i);
00109 }
00110
00111 System.out.print("} -> S" + pointsTo + " ");
00112 }
00113 public int goesTo ()
00114 {
00115 return pointsTo;
00116 }
00117 public void SMoutput(gov.nasa.arc.ase.util.graph.Node[] nodes, gov.nasa.arc.ase.util.graph.Node node)
00118 {
00119 String guard = "-";
00120 String action = "-";
00121
00122 if (!propositions.isEmpty()) {
00123 Iterator it = propositions.iterator();
00124 Formula nextForm = null;
00125 StringBuffer sb = new StringBuffer();
00126 char cont;
00127 boolean need_AND = false;
00128
00129 while (it.hasNext())
00130 {
00131 nextForm = (Formula) it.next();
00132 {
00133 cont = nextForm.getContent();
00134 if (need_AND)
00135 sb.append("&");
00136 need_AND = true;
00137 switch (cont)
00138 {
00139 case 'N': sb.append('!');
00140 sb.append(nextForm.getSub1().getName());
00141 break;
00142 case 't' : sb.append("true");
00143 break;
00144 default: sb.append(nextForm.getName());
00145 break;
00146 }
00147 }
00148 }
00149 guard = sb.toString();
00150 }
00151
00152 Edge e = new Edge(node, nodes[pointsTo], guard, action);
00153
00154 if (Node.accepting_conds == 0)
00155 {
00156 if (safe_accepting == true)
00157 e.setBooleanAttribute("acc0", true);
00158 }
00159 else
00160 for(int i = 0; i < Node.accepting_conds; i++)
00161 if(!accepting.get(i))
00162 e.setBooleanAttribute("acc"+i, true);
00163 }
00164 }