public static void addAtomsToBoogieFile(Program inprog, string outfile) { DeleteNonFreeTemplates(inprog); BoogieUtil.PrintProgram(inprog, outfile); #region ZL: read atoms from atoms.db. var database = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "atoms.db"); if (!System.IO.File.Exists(database)) { throw new Exception("File does not exist: " + database); } AtomDictionary summaries = null; while (true) { try { using (var fs = new System.IO.FileStream(database, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) { var serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); summaries = serializer.Deserialize(fs) as AtomDictionary; break; } } catch (System.IO.IOException ex) { Thread.Sleep(300); Console.WriteLine("-- {0}: {1}", ex.GetType().Name, ex.ToString()); } } var numPreds = 0; string s = @"procedure {:trainingPredicates} summaryTrainingtemplate();"; //string s = @"procedure {:XXX} YYY();"; s += summaries.DumpPredicates(out numPreds); #endregion // Add procedure summaryTrainingtemplate() by reading summary.db. using (var file = new System.IO.StreamWriter(outfile, true)) { file.WriteLine(s); if (debugging) { Console.WriteLine("Read atoms from atoms.db"); } } }
private void Awake() { atomDictionary = GameObject.FindGameObjectWithTag("GameMaster").GetComponent <AtomDictionary>(); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.A), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.B), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.C), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.D), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.E), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.F), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.G), 0); moleculeAtoms.Add(atomDictionary.TypeToClass(AtomType.H), 0); }
/// <summary> /// Opens the database. /// </summary> public void Open() { if (m_state == State.Closed) { m_dict = new AtomDictionary(m_name); m_sBucket = new Bucket(m_name, new SortOrder(TriplePosition.S, TriplePosition.O, TriplePosition.P)); m_pBucket = new Bucket(m_name, new SortOrder(TriplePosition.P, TriplePosition.S, TriplePosition.O)); m_oBucket = new Bucket(m_name, new SortOrder(TriplePosition.O, TriplePosition.S, TriplePosition.P)); m_sBucketMini = new Bucket(m_name, new SortOrder(TriplePosition.S, TriplePosition.O, TriplePosition.P), true); m_pBucketMini = new Bucket(m_name, new SortOrder(TriplePosition.P, TriplePosition.S, TriplePosition.O), true); m_oBucketMini = new Bucket(m_name, new SortOrder(TriplePosition.O, TriplePosition.S, TriplePosition.P), true); m_index = new Index(m_name, m_sBucket, m_pBucket, m_oBucket); m_stats = new Statistics(m_name, this); m_isBatchInserting = false; m_state = State.Open; } else { throw new InvalidOperationException("Database is not in closed state!"); } }
private void Awake() { atomDictionary = GameObject.FindGameObjectWithTag("GameMaster").GetComponent <AtomDictionary>(); chemicalNotation = "ass"; }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: generator file.[c|bpl]"); return; } for (int i = 0; i < args.Count(); i++) { ProcessArg(args[i]); } var files = CommonLib.Util.GetFilesForUnion(args); if (files != null) { if (mode == MODE.GENERATE_ATOMS) { // merge atoms.db var dbs = new List <AtomDictionary>(); files.Iter(f => dbs.Add(TrainerDB.Driver.ReadAtomDB(f))); TrainerDB.Driver.WriteDB( AtomDictionary.Merge(dbs), CommonLib.GlobalConfig.util_result_file); } else if (mode == MODE.GENERATE_CANDIDATES) { // merge candidates db var dbs = new List <StubAnnotatedSummaryDictionary>(); files.Iter(f => dbs.Add(TrainerDB.Driver.ReadCandidateDB(f))); TrainerDB.Driver.WriteDB( StubAnnotatedSummaryDictionary.Merge(dbs), CommonLib.GlobalConfig.util_result_file); } else { // merge corral output var cat = new List <string>(); foreach (var file in files) { cat.AddRange(System.IO.File.ReadAllLines(file)); cat.Add("========="); } System.IO.File.WriteAllLines(CommonLib.GlobalConfig.util_result_file, cat); } return; } try { // Set up Boogie CommandLineOptions.Install(new CommandLineOptions()); CommandLineOptions.Clo.PrintInstrumented = true; // Set up corral, duality var root = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); wlimitexe = Path.Combine(root, "wlimit.exe"); corralexe = Path.Combine(root, "..", "corral", "corral.exe"); z3exe = Path.Combine(root, "..", "corral", "z3.exe"); iz3exe = Path.Combine(root, "..", "iz3", "z3.exe"); runGenerator(); } catch (Exception e) { Console.WriteLine(e.Message); } }
private static void addAtomsFromDualityOutput(string filename) { var pwd = Environment.CurrentDirectory; var dualityOutputFiles = System.IO.Directory.GetFiles(pwd, "cp.*").ToList(); dualityOutputFiles.RemoveAll(fname => fname == System.IO.Path.Combine(pwd, "cp.tmp")); if (System.IO.File.Exists("fp.bpl")) { dualityOutputFiles.Add("fp.bpl"); } //foreach (var file in dualityOutputFiles) // Console.WriteLine("file: {0}", file); if (!dualityOutputFiles.Any()) { return; } // Get the set of variables with annotation {:environment}. var slicVars = new HashSet <string>(); var testBpl = BoogieUtil.ParseProgram(filename); testBpl.TopLevelDeclarations.OfType <Variable>() .Where(g => QKeyValue.FindBoolAttribute(g.Attributes, "environment")) .Iter(g => slicVars.Add(g.Name)); var outatoms = new HashSet <string>(); var summaries = new AtomDictionary(); foreach (var file in dualityOutputFiles) { // Parse the procedure summary file fp.bpl generated by Duality. var program = BoogieUtil.ParseProgram(file); // Collect atomic propositions that talk about slic variables. var literalVisitor = new LiteralVisitor(); foreach (var proc in program.TopLevelDeclarations.OfType <Procedure>()) { foreach (var ens in proc.Ensures) { literalVisitor.VisitEnsures(ens); } } // Filter literals that talk about SLIC variables only. var literals = new HashSet <Expr>(); foreach (var lit in literalVisitor.literals) { var fv = new VarsInExpr(); fv.VisitExpr(lit); bool allVarsAreSlicVars = true; foreach (var v in fv.Vars) { if (!slicVars.Contains(v)) { allVarsAreSlicVars = false; } } if (allVarsAreSlicVars) { literals.Add(lit); } } // Get pre/post annotation var GetAtomFromLiteral = new Func <Expr, Tuple <string, Expr> >(e => { if (HasNonOldExpr.Process(e)) { return(Tuple.Create("{:post}", e)); } else { return(Tuple.Create("{:pre}", e)); } }); literals.Select(l => GetAtomFromLiteral(l)) .Iter(t => { summaries.Add(t.Item1, t.Item2); outatoms.Add(t.Item1 + " " + t.Item2); }); } var atomDatabasePath = CommonLib.GlobalConfig.util_result_file; Debug.Assert(!System.IO.File.Exists(atomDatabasePath)); TrainerDB.Driver.WriteDB(summaries, atomDatabasePath); if (debugging) { foreach (var atom in outatoms) { Console.WriteLine("Dumped atom: {0}", atom); } Console.WriteLine("Dumped atoms to db."); } }