public void DileepTest1() { PDLEnumerator pdlEnumerator = new PDLEnumerator(); PDLPred phi = new PDLAtSet('a', new PDLPredSet("x", new PDLModSetEq(new PDLAllPosBefore(new PDLPosVar("x")), 2, 1))); var solver = new CharSetSolver(BitWidth.BV64); var alph = new List <char> { 'a', 'b' }; var al = new HashSet <char>(alph); var dfa = phi.GetDFA(al, solver); //solver.SaveAsDot(dfa, "C:/Users/Dileep/Desktop/oddPos.dot"); PDLPred synthPhi = null; StringBuilder sb = new StringBuilder(); foreach (var phi1 in pdlEnumerator.SynthesizePDL(al, dfa, solver, sb, 10000)) { synthPhi = phi1; break; } Console.WriteLine(sb); }
private static void PrintDFA(PDLPred phi, string name, List <char> alph) { HashSet <char> al = new HashSet <char>(alph); var solver = new CharSetSolver(BitWidth.BV64); PrintDFA(phi.GetDFA(al, solver), name, al); }
public void contains_aa_notend_ab() { var solver = new CharSetSolver(BitWidth.BV64); List <char> alph = new List <char> { 'a', 'b' }; HashSet <char> al = new HashSet <char>(alph); //new PDL PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0)); PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab"))); //PDLpred phi2 = new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast())); PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2)); //new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast()))); StringBuilder sb = new StringBuilder(); phi.ToMSO(new FreshGen()).ToString(sb); System.Console.WriteLine(sb); var dfa = phi.GetDFA(al, solver); var test = solver.Convert(@"^(a|b)*aa(((a|b)*(aa|ba|bb))|(a*))$"); //string file = "../../../TestPDL/DotFiles/contains_aa_notend_ab"; //solver.SaveAsDot(dfa, "aut", file); Assert.IsTrue(dfa.IsEquivalentWith(test, solver)); }
public readonly long elapsedTime; // in milliseconds //public readonly double densityDiffAverage, densityDifferenceDeviation; //public readonly double editDistanceAverage, editDistanceDeviation; public MeasurementResultSet(PDLPred originalFormula, IEnumerable <PDLPred> generatedFormulas, long time, VariableCache.ConstraintMode constraintmode, PdlFilter.Filtermode filtermode, HashSet <char> alphabet, IDictionary <PDLPred, SingleMeasurementResult> cache, IDictionary <Automaton <BDD>, SingleMeasurementResult> automatonCache) { this.originalFormula = originalFormula; this.alphabet = alphabet; this.originalAutomaton = originalFormula.GetDFA(alphabet, new CharSetSolver()); this.constraintmode = constraintmode; this.filtermode = filtermode; this.elapsedTime = time; this.results = new List <SingleMeasurementResult>(); foreach (PDLPred generatedFormula in generatedFormulas) { SingleMeasurementResult result; if (cache.ContainsKey(generatedFormula)) { result = cache[generatedFormula]; } else { result = SingleMeasurementResult.Create(this.originalAutomaton, generatedFormula, this.alphabet, automatonCache); cache[generatedFormula] = result; } this.results.Add(result); } // Compute statistics /* * double densityDiffSum = 0; * int editDistanceSum = 0; * * foreach (SingleMeasurementResult result in this.results) * { * densityDiffSum += result.densityDiff; * editDistanceSum += result.editDistance; * } * * this.densityDiffAverage = ((double)densityDiffSum) / ((double)this.results.Count); * this.editDistanceAverage = ((double)editDistanceSum) / ((double)this.results.Count); * * double densityDiffDeviation = 0; * double editDistanceDeviation = 0; * foreach (SingleMeasurementResult result in this.results) * { * densityDiffDeviation += Math.Pow(result.densityDiff - this.densityDiffAverage, 2.0); * editDistanceDeviation += Math.Pow(((double)result.editDistance) - this.editDistanceAverage, 2.0); * } * densityDiffDeviation /= this.results.Count; * densityDiffDeviation = Math.Sqrt(densityDiffDeviation); * * editDistanceDeviation /= this.results.Count; * editDistanceDeviation = Math.Sqrt(editDistanceDeviation); */ }
public readonly long elapsedTime; // in milliseconds //public readonly double densityDiffAverage, densityDifferenceDeviation; //public readonly double editDistanceAverage, editDistanceDeviation; public MeasurementResultSet(PDLPred originalFormula, IEnumerable<PDLPred> generatedFormulas, long time, VariableCache.ConstraintMode constraintmode, PdlFilter.Filtermode filtermode, HashSet<char> alphabet, IDictionary<PDLPred, SingleMeasurementResult> cache, IDictionary<Automaton<BDD>, SingleMeasurementResult> automatonCache) { this.originalFormula = originalFormula; this.alphabet = alphabet; this.originalAutomaton = originalFormula.GetDFA(alphabet, new CharSetSolver()); this.constraintmode = constraintmode; this.filtermode = filtermode; this.elapsedTime = time; this.results = new List<SingleMeasurementResult>(); foreach (PDLPred generatedFormula in generatedFormulas) { SingleMeasurementResult result; if (cache.ContainsKey(generatedFormula)) { result = cache[generatedFormula]; } else { result = SingleMeasurementResult.Create(this.originalAutomaton, generatedFormula, this.alphabet, automatonCache); cache[generatedFormula] = result; } this.results.Add(result); } // Compute statistics /* double densityDiffSum = 0; int editDistanceSum = 0; foreach (SingleMeasurementResult result in this.results) { densityDiffSum += result.densityDiff; editDistanceSum += result.editDistance; } this.densityDiffAverage = ((double)densityDiffSum) / ((double)this.results.Count); this.editDistanceAverage = ((double)editDistanceSum) / ((double)this.results.Count); double densityDiffDeviation = 0; double editDistanceDeviation = 0; foreach (SingleMeasurementResult result in this.results) { densityDiffDeviation += Math.Pow(result.densityDiff - this.densityDiffAverage, 2.0); editDistanceDeviation += Math.Pow(((double)result.editDistance) - this.editDistanceAverage, 2.0); } densityDiffDeviation /= this.results.Count; densityDiffDeviation = Math.Sqrt(densityDiffDeviation); editDistanceDeviation /= this.results.Count; editDistanceDeviation = Math.Sqrt(editDistanceDeviation); */ }
public void Test17() // string not containing aa but ends with ab { PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0)); PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab"))); PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2)); PrintDFA(phi, "Test17", new List <char> { 'a', 'b' }); }
private SingleMeasurementResult(Automaton <BDD> originalAutomaton, PDLPred generatedFormula, Automaton <BDD> generatedAutomaton, HashSet <char> alphabet) { this.generatedFormula = generatedFormula; CharSetSolver solver = new CharSetSolver(); DFAEditScript editScript = DFAEditDistance.GetDFAOptimalEdit(originalAutomaton, generatedAutomaton, alphabet, solver, 100, new System.Text.StringBuilder()); if (editScript != null) { this.editDistance = editScript.script.Count; } else { this.editDistance = int.MaxValue; } this.densityDiff = DFADensity.GetDFADifferenceRatio(originalAutomaton, generatedAutomaton, alphabet, solver); }
private List <Pair <PDLPred, long> > SynthTimer(PDLPred phi, HashSet <char> al, StringBuilder sb) { PDLEnumerator pdlEnumerator = new PDLEnumerator(); var solver = new CharSetSolver(BitWidth.BV64); Stopwatch sw = new Stopwatch(); var dfa = phi.GetDFA(al, solver); List <Pair <PDLPred, long> > predList = new List <Pair <PDLPred, long> >(); List <PDLPred> phiList = new List <PDLPred>(); PDLPred v; var func = new Func <PDLPred>(() => { sw.Start(); foreach (var p in pdlEnumerator.SynthesizePDL(al, dfa, solver, new StringBuilder(), 5000)) { sw.Stop(); predList.Add(new Pair <PDLPred, long>(p, sw.ElapsedMilliseconds)); sw.Start(); } return(null); }); var test = TryExecute(func, timeout, out v); phi.ToString(sb); sb.AppendLine(); sb.AppendLine("="); foreach (var pair in predList) { sb.AppendLine(); pair.First.ToString(sb); sb.AppendLine(); sb.AppendLine("Elapsed Time: " + pair.Second + " ms"); } return(predList); }
public void contains_aa_notend_ab() { var solver = new CharSetSolver(BitWidth.BV64); List <char> alph = new List <char> { 'a', 'b' }; HashSet <char> al = new HashSet <char>(alph); //new PDL PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0)); PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab"))); //PDLpred phi2 = new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast())); PDLPred phi = new PDLAnd(phi1, new PDLNot(phi2)); //new PDLAnd(new PDLatPos('a', new PDLprev(new PDLlast())), new PDLatPos('b', new PDLlast()))); StringBuilder sb = new StringBuilder(); List <Pair <int, Pair <PDLPred, long> > > pairs = SynthTimer(phi, al, sb); Output(sb, "contains_aa_notend_ab"); }
public void checkEval() { PDLPred phi = new PDLIntEq(new PDLIndicesOf("aaa"), 1); System.Console.WriteLine("Exactly once aaa:"); System.Console.WriteLine(phi.Eval("baaaabbb", new Dictionary <string, int>())); PDLPred phi1 = new PDLNot(new PDLIntLeq(new PDLIndicesOf("aa"), 0)); PDLPred phi2 = (new PDLBelongs(new PDLPredecessor(new PDLLast()), new PDLIndicesOf("ab"))); //System.Console.WriteLine("prevLast " + (new PDLprev(new PDLlast())).Eval("aaabbccab", new Dictionary<string, int>())); //System.Console.WriteLine("indab " + (new PDLindicesOf("ab")).Eval("aaabbccab", new Dictionary<string, int>())); //System.Console.WriteLine("phi2 " + phi2.Eval("aaabbccab", new Dictionary<string, int>())); phi = new PDLAnd(phi1, new PDLNot(phi2)); System.Console.WriteLine("Contains aa and not end ab:"); System.Console.WriteLine(phi.Eval("aaabbccabc", new Dictionary <string, int>())); phi = new PDLAnd(new PDLIf(new PDLAtPos('a', new PDLFirst()), new PDLAtPos('a', new PDLLast())), new PDLIf(new PDLAtPos('b', new PDLFirst()), new PDLAtPos('b', new PDLLast()))); System.Console.WriteLine("Same First Last:"); System.Console.WriteLine(phi.Eval("abbba", new Dictionary <string, int>())); phi = new PDLExistsFO("x0", new PDLAtPos('a', new PDLPosVar("x0"))); System.Console.WriteLine("exists a:"); System.Console.WriteLine(phi.Eval("ab", new Dictionary <string, int>())); phi = new PDLEndsWith("abc"); System.Console.WriteLine("ends with abc:"); System.Console.WriteLine(phi.Eval("bc", new Dictionary <string, int>())); phi = new PDLStartsWith("abc"); System.Console.WriteLine("starts with abc:"); System.Console.WriteLine(phi.Eval("abcababcccabc", new Dictionary <string, int>())); }
public void DileepTest() { PDLEnumerator pdlEnumerator = new PDLEnumerator(); PDLPred phi = new PDLIntGeq(new PDLIndicesOf("ab"), 2); var solver = new CharSetSolver(BitWidth.BV64); var alph = new List <char> { 'a', 'b' }; var al = new HashSet <char>(alph); var dfa = phi.GetDFA(al, solver); PDLPred synthPhi = null; StringBuilder sb = new StringBuilder(); foreach (var phi1 in pdlEnumerator.SynthesizePDL(al, dfa, solver, sb, 10000)) { synthPhi = phi1; break; } Console.WriteLine(sb); }
private void runTest(string testName) { PDLEnumerator pdlEnumerator = new PDLEnumerator(); CharSetSolver solver = new CharSetSolver(BitWidth.BV64); var dfa_al = ReadDFA(testName, solver); PDLPred synthPhi = null; StringBuilder sb = new StringBuilder(); sb.AppendLine("*------------------------------------"); sb.AppendLine("| " + testName); sb.AppendLine("|------------------------------------"); foreach (var phi in pdlEnumerator.SynthesizePDL(dfa_al.First, dfa_al.Second, solver, sb, timeout)) { synthPhi = phi; break; } sb.AppendLine("*------------------------------------"); sb.AppendLine(); System.Console.WriteLine(sb); }
private SingleMeasurementResult(Automaton<BDD> originalAutomaton, PDLPred generatedFormula, Automaton<BDD> generatedAutomaton, HashSet<char> alphabet) { this.generatedFormula = generatedFormula; CharSetSolver solver = new CharSetSolver(); DFAEditScript editScript = DFAEditDistance.GetDFAOptimalEdit(originalAutomaton, generatedAutomaton, alphabet, solver, 100, new System.Text.StringBuilder()); if (editScript != null) { this.editDistance = editScript.script.Count; } else { this.editDistance = int.MaxValue; } this.densityDiff = DFADensity.GetDFADifferenceRatio(originalAutomaton, generatedAutomaton, alphabet, solver); }
private static Boolean KeepProblem(PDLPred original, PDLPred phi, int distance, HashSet<char> alphabet, CharSetSolver solver) { return true; }
//Return what percentage of testSet phi accepts private static double PercentagePosSet(PDLPred phi, IEnumerable<string> testSet) { double correct =0; double total = 0; foreach (var test in testSet) { total++; if (!phi.Eval(test, new Dictionary<string, int>())) correct++; } return total==0?0:correct/total; }
public static SingleMeasurementResult Create(Automaton<BDD> originalAutomaton, PDLPred generatedFormula, HashSet<char> alphabet, IDictionary<Automaton<BDD>, SingleMeasurementResult> cache) { CharSetSolver solver = new CharSetSolver(); Automaton<BDD> generatedAutomaton = generatedFormula.GetDFA(alphabet, solver); SingleMeasurementResult returnValue; if (cache.ContainsKey(generatedAutomaton)) { returnValue = cache[generatedAutomaton]; System.Diagnostics.Debug.WriteLine("Automaton Cache Hit"); } else { returnValue = new SingleMeasurementResult(originalAutomaton, generatedFormula, generatedAutomaton, alphabet); cache[generatedAutomaton] = returnValue; System.Diagnostics.Debug.WriteLine("Automaton Cache Miss"); } return returnValue; }
public static TreeDefinition MakeTree(Dictionary<string, Pair<PDL, string>> nodeMapping, String treeSpec, String rootID, PDLPred pdl) { Dictionary<String, List<String>> aTree = new Dictionary<String, List<String>>(); String root = rootID; String[] edges = treeSpec.Split(';'); foreach (String edge in edges) if (edge != "") { String[] nodes = edge.Split('-'); addEdge(nodes[0], nodes[1], aTree); if (root == null) root = nodes[0]; } BasicTree aBasicTree = new BasicTree(aTree, root, BasicTree.POSTORDER); aBasicTree.pdlNodeMapping = nodeMapping; aBasicTree.pdl = pdl; return aBasicTree; }
public DfaStateNumberFilter(PDLPred original, HashSet<char> alphabet) { this.charsetSolver = new CharSetSolver(); this.alphabet = alphabet; this.numOriginalStates = original.GetDFA(alphabet, this.charsetSolver).StateCount; }
private List <Pair <int, Pair <PDLPred, long> > > SynthTimer(PDLPred phi, HashSet <char> al, StringBuilder sb) { PDLEnumerator pdlEnumerator = new PDLEnumerator(); var solver = new CharSetSolver(BitWidth.BV64); Stopwatch sw = new Stopwatch(); var dfa = DFAUtilities.normalizeDFA(phi.GetDFA(al, solver)).First; List <Pair <int, Pair <PDLPred, long> > > predList = new List <Pair <int, Pair <PDLPred, long> > >(); List <PDLPred> phiList = new List <PDLPred>(); PDLPred v; var func = new Func <PDLPred>(() => { foreach (var state in dfa.States) { var dfaSt = Automaton <BDD> .Create(dfa.InitialState, new int[] { state }, dfa.GetMoves()); dfaSt = dfaSt.Determinize(solver).Minimize(solver); sw.Reset(); sw.Start(); foreach (var p in pdlEnumerator.SynthesizePDL(al, dfaSt, solver, new StringBuilder(), 3000)) { sw.Stop(); predList.Add(new Pair <int, Pair <PDLPred, long> >(state, new Pair <PDLPred, long>(p, sw.ElapsedMilliseconds))); break; } } return(null); }); var test = TryExecute(func, timeout, out v); sb.Append("Language: "); phi.ToString(sb); sb.AppendLine(); //sb.AppendLine("States: "+dfa.StateCount); sb.AppendLine(); sb.AppendLine("---------------------------"); sb.AppendLine("STATE SUMMARY"); sb.AppendLine("---------------------------"); var coveredStates = new HashSet <int>(); foreach (var pair in predList) { sb.AppendLine(); coveredStates.Add(pair.First); sb.AppendLine("State " + pair.First + (((dfa.GetFinalStates()).Contains(pair.First))?(" is final"):(""))); sb.AppendLine("Elapsed Time: " + pair.Second.Second + " ms"); sb.AppendLine("Formula: "); pair.Second.First.ToString(sb); sb.AppendLine(); } sb.AppendLine(); foreach (var state in dfa.States) { if (!coveredStates.Contains(state)) { sb.AppendLine(string.Format("description for state {0} not found", state)); } } return(predList); }
/// <summary> /// Returns the edit distance ration between 2 PDLpred A1,A2 /// </summary> /// <param name="phi1"></param> /// <param name="phi2"></param> /// <returns>d(A1,A2)</returns> internal static Transformation GetFormulaEditDistance(PDLPred phi1, PDLPred phi2) { TreeEditDistance treeCorrector = new TreeEditDistance(); TreeDefinition aTree = CreateTreeHelper.MakeTree(phi1); TreeDefinition bTree = CreateTreeHelper.MakeTree(phi2); Transformation transform = treeCorrector.getTransformation(aTree, bTree); return transform; }
public static int GetSMTVariables(PDLPred phi, IEnumerable<char> alphabet) { CPDLPred choiceTree = phi.GetCPDL(); HashSet<char> alphabetHashSet = new HashSet<char>(alphabet); Context z3Context = new Context(); Solver z3Solver = z3Context.MkSolver(); VariableCache variableGenerator = VariableCache.Create(VariableCache.ConstraintMode.BOTH); choiceTree.ToSMTConstraints(z3Context, z3Solver, alphabetHashSet.Count, variableGenerator); variableGenerator.GenerateAdditionalConstraints(z3Context, z3Solver); return variableGenerator.GetNumVariables(); }
public override bool KeepPredicate(PDLPred candidate) { return true; }
public static SingleMeasurementResult Create(Automaton <BDD> originalAutomaton, PDLPred generatedFormula, HashSet <char> alphabet, IDictionary <Automaton <BDD>, SingleMeasurementResult> cache) { CharSetSolver solver = new CharSetSolver(); Automaton <BDD> generatedAutomaton = generatedFormula.GetDFA(alphabet, solver); SingleMeasurementResult returnValue; if (cache.ContainsKey(generatedAutomaton)) { returnValue = cache[generatedAutomaton]; System.Diagnostics.Debug.WriteLine("Automaton Cache Hit"); } else { returnValue = new SingleMeasurementResult(originalAutomaton, generatedFormula, generatedAutomaton, alphabet); cache[generatedAutomaton] = returnValue; System.Diagnostics.Debug.WriteLine("Automaton Cache Miss"); } return(returnValue); }
public static PdlFilter Create(Filtermode filtermode, PDLPred original, HashSet<char> alphabet) { switch (filtermode) { case Filtermode.NONE: return new NoFilter(); case Filtermode.TRIVIAL: return new TrivialFormulaFilter(alphabet, 4); case Filtermode.STATEBASED: return new DfaStateNumberFilter(original, alphabet); case Filtermode.BOTH: PdlFilter trivialFilter = new TrivialFormulaFilter(alphabet, 4); PdlFilter stateFilter = new DfaStateNumberFilter(original, alphabet); return new ConsFilter(trivialFilter, stateFilter); } return null; }
public override bool KeepPredicate(PDLPred candidate) { Automaton<BDD> candidateDfa = candidate.GetDFA(this.alphabet, this.charsetSolver); int stateDifference = Math.Abs(numOriginalStates - candidateDfa.StateCount); return IsAcceptableStateDifference(stateDifference); }
public Testcase(int id, IEnumerable<char> alphabet, PDLPred language) { this.id = id; this.alphabet = alphabet; this.language = language; }
public static IEnumerable<PDLPred> GeneratePDLWithEDn(PDLPred phi, IEnumerable<char> alphabet, VariableCache.ConstraintMode constConst, PdlFilter.Filtermode filtermode) { CPDLPred choiceTree = phi.GetCPDL(); HashSet<char> alphabetHashSet = new HashSet<char>(alphabet); PdlFilter filter = PdlFilter.Create(filtermode, phi, alphabetHashSet); // Concretize yields all feasible concretizations of the choiceTree foreach(PDLPred candidate in Concretize(choiceTree, alphabetHashSet, constConst)) { if (filter.KeepPredicate(candidate) == true) { yield return candidate; } } }
public override string ToString() { long enumTimeout = 1000L; #region feedback components PDLEnumerator pdlEnumerator = new PDLEnumerator(); PDLPred symmPhi = null; PDLPred underPhi = null; string posWitness = null; string negWitness = null; //If hint or solution try computing the description of the symmdiff if (level == FeedbackLevel.Hint || level == FeedbackLevel.Solution) { //Avoid formulas that are too complex var maxSize = 7; if (symmetricDifference.StateCount < 15) { foreach (var phi1 in pdlEnumerator.SynthesizePDL(alphabet, symmetricDifference, solver, new StringBuilder(), enumTimeout)) { var sizePhi1 = phi1.GetFormulaSize(); if (sizePhi1 < maxSize && !phi1.IsComplex()) { maxSize = sizePhi1; symmPhi = phi1; } } } } //Avoid empty string case and particular string if (symmPhi is PDLEmptyString || symmPhi is PDLIsString) { symmPhi = null; } //If not minimal try computing and underapprox of symmdiff if (symmPhi == null && level != FeedbackLevel.Minimal) { //Avoid formulas that are too complex var minSize = 9; if (symmetricDifference.StateCount < 15) { foreach (var phi2 in pdlEnumerator.SynthesizeUnderapproximationPDL(alphabet, symmetricDifference, solver, new StringBuilder(), enumTimeout)) { var formula = phi2.First; var sizeForm = formula.GetFormulaSize(); if (sizeForm < minSize && !formula.IsComplex()) { minSize = sizeForm; underPhi = formula; } break; } } } //Avoid empty string case and particular string if (underPhi is PDLEmptyString || underPhi is PDLIsString) { underPhi = null; } if (!positiveDifference.IsEmpty) { posWitness = DFAUtilities.GenerateShortTerm(positiveDifference, solver); } else { negWitness = DFAUtilities.GenerateShortTerm(negativeDifference, solver); } #endregion string result = ""; //string.Format("U: {0}%. ", utility); if (symmPhi != null) { if (symmPhi is PDLEmptyString) { result += "Your solution does not behave correctly on the empty string"; } else { result += string.Format("Your solution is not correct on this set of strings: <br /> <div align='center'>{0}</div>", PDLUtil.ToEnglishString(symmPhi)); } } else if (underPhi != null) { if (underPhi is PDLEmptyString) { result += "Your solution does not behave correctly on the empty string"; } else { result += string.Format("Your solution is not correct on this set of strings: <br /> <div align='center'>{0}</div>", PDLUtil.ToEnglishString(underPhi)); } } else { if (posWitness != null) { result += string.Format("Your solution does not accept the {0} while the correct solution does.", posWitness != "" ? "string '<i>" + posWitness + "</i>'" : "empty string"); } else { result += string.Format("Your solution accepts the {0} while the correct solution doesn't.", negWitness != "" ? "string '<i>" + negWitness + "</i>'" : "empty string"); } } return(result); }
public Transformation() { totalCost = 0; editScriptAtoB = new TreeEditScript(); editScriptBtoA = new TreeEditScript(); pdlA = null; pdlB = null; pdlMappingTreeA = new Dictionary<string,Pair<PDL,string>>(); pdlMappingTreeB = new Dictionary<string, Pair<PDL, string>>(); minSizeForTreeA = 0; }
/* This takes a String describing a tree and converts it into a * TreeDefinition. The format of the string is a series of edges * represented as pairs of string separated by semi-colons. Each * pair is comma separated. The first substring in the pair is * the parent, the second is the child. The first edge parent * must be the root of the tree. * * For example: "a-b;a-c;c-d;c-e;c-f;" */ public static TreeDefinition MakeTree(PDLPred phi) { Dictionary<string, Pair<PDL, string>> dic = new Dictionary<string,Pair<PDL,string>>(); string pdlTreeString = phi.ToTreeString(dic); return MakeTree(dic, pdlTreeString, null, phi); }
public override bool KeepPredicate(PDLPred candidate) { return this.firstFilter.KeepPredicate(candidate) && this.secondFilter.KeepPredicate(candidate); }
public static string ToEnglishString(PDLPred phi) { Transformation t = new Transformation(); return t.ToEnglishString(phi); }
/// <summary> /// Discards a formula if it has the same result on all test strings. The idea is that this formula is probably too /// easy. /// </summary> /// <param name="candidates"></param> /// <returns></returns> public override bool KeepPredicate(PDLPred candidate) { bool firstResult = candidate.Eval(this.testStrings[0], new Dictionary<string, int>()); for (int testStringIndex = 1; testStringIndex < this.testStrings.Count; ++testStringIndex) { string testString = this.testStrings[testStringIndex]; bool currentResult = candidate.Eval(testString, new Dictionary<string, int>()); if (currentResult != firstResult) { // Since a single differing result is enough, we can return from here return true; } } return false; }
//True if phi accepts all the strings in testset private static bool CorrectOnPosSet(PDLPred phi, IEnumerable<string> testSet) { foreach (var test in testSet) if (!phi.Eval(test, new Dictionary<string, int>())) { return false; } return true; }
public abstract bool KeepPredicate(PDLPred candidate);
public Testcase(int id, IEnumerable <char> alphabet, PDLPred language) { this.id = id; this.alphabet = alphabet; this.language = language; }
private static void PrintDFA(PDLPred phi, string name, List<char> alph) { HashSet<char> al = new HashSet<char>(alph); var solver = new CharSetSolver(BitWidth.BV64); PrintDFA(phi.GetDFA(al, solver), name, al); }