00001 package gov.nasa.arc.ase.ltl;
00002
00003
00004
00005
00006 import gov.nasa.arc.ase.util.graph.*;
00007 import gov.nasa.arc.ase.jpf.JPFErrorException;
00008 import java.io.*;
00009
00010 public class LTL2Buchi {
00011 private static String loadLTL(String fname) {
00012 try {
00013 BufferedReader in = new BufferedReader(new FileReader(fname));
00014
00015 return in.readLine();
00016 } catch(FileNotFoundException e) {
00017 throw new JPFErrorException("Can't load LTL formula: " + fname);
00018 } catch(IOException e) {
00019 throw new JPFErrorException("Error read on LTL formula: " + fname);
00020 }
00021 }
00022 public static void main(String[] args) {
00023 if(args.length > 1) {
00024 System.out.println("usage:");
00025 System.out.println("\tjava gov.nasa.arc.ase.ltl.LTL2Buchi [<filename>|<ltl-formula>]");
00026 return;
00027 }
00028
00029 String ltl = null;
00030
00031 if(args.length == 0)
00032 ltl = readLTL();
00033 else {
00034 ltl = args[0];
00035
00036 if(ltl.endsWith(".ltl"))
00037 ltl = loadLTL(ltl);
00038 else if(ltl.equals("-"))
00039 ltl = readLTL();
00040 }
00041
00042 Graph g = translate(ltl);
00043
00044 g.save(Graph.FSP_FORMAT);
00045 }
00046 private static String readLTL() {
00047 try {
00048 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
00049
00050 System.out.print("Insert LTL formula: ");
00051 return in.readLine();
00052 } catch(IOException e) {
00053 throw new JPFErrorException("Invalid LTL formula");
00054 }
00055 }
00056 public static Graph translate(String formula) {
00057 try {
00058 System.out.println("Translating formula: " + formula);
00059 System.out.println();
00060
00061 formula = Rewriter.rewrite(formula);
00062 System.out.println("Rewritten as : " + formula);
00063 System.out.println();
00064
00065 Graph gba = Translator.translate(formula);
00066
00067 gba.save(System.getProperty("user.dir")+File.separator+"gba.sm");
00068
00069
00070
00071
00072 System.out.println("Generalized buchi automaton generated: gba.sm");
00073 System.out.println("\t" + gba.getNodeCount() + " states " + gba.getEdgeCount() + " transitions");
00074 System.out.println();
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 gba = SuperSetReduction.reduce(gba);
00086
00087 gba.save(System.getProperty("user.dir")+File.separator+"ssr-gba.sm");
00088
00089
00090
00091 System.out.println("Superset reduction: ssr-gba.sm");
00092 System.out.println("\t" + gba.getNodeCount() + " states " + gba.getEdgeCount() + " transitions");
00093 System.out.println();
00094
00095 Graph ba = Degeneralize.degeneralize(gba);
00096
00097 ba.save(System.getProperty("user.dir")+File.separator+"ba.sm");
00098
00099
00100
00101 System.out.println("Degeneralized buchi automaton generated: ba.sm");
00102 System.out.println("\t" + ba.getNodeCount() + " states " + ba.getEdgeCount() + " transitions");
00103 System.out.println();
00104
00105 ba = SCCReduction.reduce(ba);
00106
00107 ba.save(System.getProperty("user.dir")+File.separator+"scc-ba.sm");
00108
00109
00110
00111 System.out.println("Strongly connected component reduction: scc-ba.sm");
00112 System.out.println("\t" + ba.getNodeCount() + " states " + ba.getEdgeCount() + " transitions");
00113 System.out.println();
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 ba = SFSReduction.reduce(ba);
00127
00128 ba.save(System.getProperty("user.dir")+File.separator+"scc-ba.sm");
00129
00130
00131
00132 System.out.println("Fair simulation applied: fairSim-final.sm");
00133 System.out.println("\t" + ba.getNodeCount() + " states " + ba.getEdgeCount() + " transitions");
00134 System.out.println();
00135
00136 return ba;
00137 } catch(IOException e) {
00138 throw new JPFErrorException(e.getMessage());
00139 }
00140 }
00141 }