Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

LTL2Buchi.java

00001 package gov.nasa.arc.ase.ltl;
00002 
00003 /* (c) 2001 Dimitra Giannakopoulou and Flavio Lerda*/
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 //#ifdef BANDERA
00067       gba.save(System.getProperty("user.dir")+File.separator+"gba.sm");
00068 //#else BANDERA
00069 
00070 //#endif BANDERA
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       gba = SCCReduction.reduce(gba);
00079       gba.save("scc-gba.sm");
00080       System.out.println("Strongly connected component reduction: scc-gba.sm");
00081       System.out.println("\t" + gba.getNodeCount() + " states " + gba.getEdgeCount() + " transitions");
00082       System.out.println();
00083       */
00084 
00085       gba = SuperSetReduction.reduce(gba);
00086 //#ifdef BANDERA
00087       gba.save(System.getProperty("user.dir")+File.separator+"ssr-gba.sm");
00088 //#else BANDERA
00089 
00090 //#endif BANDERA
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 //#ifdef BANDERA
00097       ba.save(System.getProperty("user.dir")+File.separator+"ba.sm");
00098 //#else BANDERA
00099 
00100 //#endif BANDERA
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 //#ifdef BANDERA
00107       ba.save(System.getProperty("user.dir")+File.separator+"scc-ba.sm");
00108 //#else BANDERA
00109 
00110 //#endif BANDERA
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       ba = Simplify.simplify(ba);
00116 //#ifdef BANDERA
00117       ba.save(System.getProperty("user.dir")+File.separator+"final.sm");
00118 //#else BANDERA
00119 
00120 //#endif BANDERA
00121       System.out.println("Simplification applied: final.sm");
00122       System.out.println("\t" + ba.getNodeCount() + " states " + ba.getEdgeCount() + " transitions");
00123       System.out.println();
00124 */
00125       
00126       ba = SFSReduction.reduce(ba);
00127 //#ifdef BANDERA
00128       ba.save(System.getProperty("user.dir")+File.separator+"scc-ba.sm");
00129 //#else BANDERA
00130 
00131 //#endif BANDERA
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 }

Generated at Thu Feb 7 06:50:11 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001