internal static Automaton <BDD> computeDFA(List <string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2, int n) { int pos1 = variables.IndexOf(set1); int pos2 = variables.IndexOf(set2); Dictionary <int, Dictionary <Pair <int, Pair <int, int> >, Automaton <BDD> > > dic1; if (!hashedDfa.ContainsKey(alphabet)) { hashedDfa[alphabet] = new Dictionary <int, Dictionary <Pair <int, Pair <int, int> >, Automaton <BDD> > >(); } dic1 = hashedDfa[alphabet]; Dictionary <Pair <int, Pair <int, int> >, Automaton <BDD> > dic2; if (!dic1.ContainsKey(variables.Count)) { dic1[variables.Count] = new Dictionary <Pair <int, Pair <int, int> >, Automaton <BDD> >(); } dic2 = dic1[variables.Count]; var hash = new Pair <int, Pair <int, int> >(pos1, new Pair <int, int>(pos2, n)); if (dic2.ContainsKey(hash)) { return(dic2[hash]); } var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var pos1is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos1)); var pos1is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos1)); var pos2is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos2)); var pos2is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos2)); var both0 = solver.MkAnd(new BDD[] { pos1is0, pos2is0 }); var pos11pos20 = solver.MkAnd(new BDD[] { pos1is1, pos2is0 }); var pos10pos21 = solver.MkAnd(new BDD[] { pos1is0, pos2is1 }); //Create automaton for condition var moves = new List <Move <BDD> >(); moves.Add(new Move <BDD>(0, 0, both0)); moves.Add(new Move <BDD>(0, 1, pos11pos20)); for (int i = 1; i < n; i++) { moves.Add(new Move <BDD>(i, i + 1, both0)); } moves.Add(new Move <BDD>(n, n + 1, pos10pos21)); moves.Add(new Move <BDD>(n + 1, n + 1, both0)); var dfa = Automaton <BDD> .Create(0, new int[] { n + 1 }, moves).Determinize(solver).Minimize(solver); if (hashing) { dic2[hash] = dfa; } return(dfa); }
internal static Automaton <BDD> computeDFA(List <string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2) { var pos1 = variables.IndexOf(set1); var pos2 = variables.IndexOf(set2); Dictionary <Pair <int, int>, Automaton <BDD> > dic1 = null; Pair <int, int> pair = null; if (hashing) { if (!hashedDfa.ContainsKey(alphabet)) { hashedDfa[alphabet] = new Dictionary <int, Dictionary <Pair <int, int>, Automaton <BDD> > >(); } var dic = hashedDfa[alphabet]; if (!dic.ContainsKey(variables.Count)) { dic[variables.Count] = new Dictionary <Pair <int, int>, Automaton <BDD> >(); } dic1 = dic[variables.Count]; pair = new Pair <int, int>(pos1, pos2); if (dic1.ContainsKey(pair)) { return(dic1[pair]); } } //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 7) - 1), variables.Count + 7 - 1); var pos2is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos2)); var pos1is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos1)); var subsetCond = solver.MkOr(pos2is1, pos1is0); //Create automaton for condition var moves = new Move <BDD>[] { new Move <BDD>(0, 0, subsetCond) }; var dfa = Automaton <BDD> .Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver); if (hashing) { dic1[pair] = dfa; } return(dfa); }
internal static Automaton <BDD> computeDFA(List <string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2) { int pos1 = variables.IndexOf(set1); int pos2 = variables.IndexOf(set2); Dictionary <int, Dictionary <Pair <int, int>, Automaton <BDD> > > dic1; if (!hashedDfa.ContainsKey(alphabet)) { hashedDfa[alphabet] = new Dictionary <int, Dictionary <Pair <int, int>, Automaton <BDD> > >(); } dic1 = hashedDfa[alphabet]; Dictionary <Pair <int, int>, Automaton <BDD> > dic2; if (!dic1.ContainsKey(variables.Count)) { dic1[variables.Count] = new Dictionary <Pair <int, int>, Automaton <BDD> >(); } dic2 = dic1[variables.Count]; var hash = new Pair <int, int>(pos1, pos2); if (dic2.ContainsKey(hash)) { return(dic2[hash]); } //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var both1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(pos1), solver.MkSetWithBitTrue(pos2) }); var both0 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitFalse(pos1), solver.MkSetWithBitFalse(pos2) }); var eqCond = solver.MkOr(new BDD[] { both0, both1 }); //Create automaton for condition var moves = new Move <BDD>[] { new Move <BDD>(0, 0, eqCond) }; var dfa = Automaton <BDD> .Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver); if (hashing) { dic2[hash] = dfa; } return(dfa); }
internal static Automaton <BDD> computeDFA(List <string> variables, BDD alphabet, CharSetSolver solver, string set, BDD pred) { int setbit = variables.IndexOf(set); //Compute predicates for pos-th bit is 0 or 1 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var posIs1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(setbit), solver.ShiftLeft(pred, variables.Count) }); var posIs0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(setbit)); //Create automaton for condition var moves = new Move <BDD>[] { new Move <BDD>(0, 0, posIs0), new Move <BDD>(0, 0, posIs1) }; var dfa = Automaton <BDD> .Create(0, new int[] { 0 }, moves); return(dfa); }
internal static Automaton <BDD> computeDFA(List <string> variables, BDD alphabet, CharSetSolver solver, string set) { int setbit = variables.IndexOf(set); Dictionary <Pair <int, int>, Automaton <BDD> > dic; if (!hashedDfa.ContainsKey(alphabet)) { hashedDfa[alphabet] = new Dictionary <Pair <int, int>, Automaton <BDD> >(); } dic = hashedDfa[alphabet]; var hash = new Pair <int, int>(variables.Count, setbit); if (dic.ContainsKey(hash)) { return(dic[hash]); } //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var posIs1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(setbit)); var posIs0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(setbit)); //Create automaton for condition var moves = new Move <BDD>[] { new Move <BDD>(0, 0, posIs0), new Move <BDD>(0, 1, posIs1), new Move <BDD>(1, 1, posIs0) }; //Generate the dfa correpsonding to regexp var dfa = Automaton <BDD> .Create(0, new int[] { 1 }, moves); if (hashing) { dic[hash] = dfa; } return(dfa); }
internal override Automaton <BDD> getDFA(List <string> variables, BDD alphabet, CharSetSolver solver) { int varbit = variables.IndexOf(var1); Dictionary <Pair <int, int>, Automaton <BDD> > dic; if (!hashedDfa.ContainsKey(alphabet)) { hashedDfa[alphabet] = new Dictionary <Pair <int, int>, Automaton <BDD> >(); } dic = hashedDfa[alphabet]; var hash = new Pair <int, int>(variables.Count, varbit); if (dic.ContainsKey(hash)) { return(dic[hash]); } //Create conditions var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 7) - 1), variables.Count + 7 - 1); var posis1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(varbit)); var posis0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(varbit)); //Create automaton for condition var moves = new Move <BDD>[] { new Move <BDD>(0, 1, posis1), new Move <BDD>(1, 1, posis0) }; var dfa = Automaton <BDD> .Create(0, new int[] { 1 }, moves).Determinize(solver).Minimize(solver); dic[hash] = dfa; return(dfa); }
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2) { int pos1 = variables.IndexOf(set1); int pos2 = variables.IndexOf(set2); Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>> dic1; if (!hashedDfa.ContainsKey(alphabet)) hashedDfa[alphabet] = new Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>>(); dic1 = hashedDfa[alphabet]; Dictionary<Pair<int, int>, Automaton<BDD>> dic2; if (!dic1.ContainsKey(variables.Count)) dic1[variables.Count] = new Dictionary<Pair<int, int>, Automaton<BDD>>(); dic2 = dic1[variables.Count]; var hash = new Pair<int, int>(pos1, pos2); if (dic2.ContainsKey(hash)) return dic2[hash]; //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var both1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(pos1), solver.MkSetWithBitTrue(pos2) }); var both0 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitFalse(pos1), solver.MkSetWithBitFalse(pos2) }); var eqCond = solver.MkOr(new BDD[] { both0, both1 }); //Create automaton for condition var moves = new Move<BDD>[] { new Move<BDD>(0, 0, eqCond) }; var dfa = Automaton<BDD>.Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver); if(hashing) dic2[hash] = dfa; return dfa; }
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2, int n) { int pos1 = variables.IndexOf(set1); int pos2 = variables.IndexOf(set2); Dictionary<int, Dictionary<Pair<int, Pair<int, int>>, Automaton<BDD>>> dic1; if (!hashedDfa.ContainsKey(alphabet)) hashedDfa[alphabet] = new Dictionary<int, Dictionary<Pair<int, Pair<int, int>>, Automaton<BDD>>>(); dic1 = hashedDfa[alphabet]; Dictionary<Pair<int, Pair<int, int>>, Automaton<BDD>> dic2; if (!dic1.ContainsKey(variables.Count)) dic1[variables.Count] = new Dictionary<Pair<int, Pair<int, int>>, Automaton<BDD>>(); dic2 = dic1[variables.Count]; var hash = new Pair<int, Pair<int, int>>(pos1, new Pair<int, int>(pos2, n)); if (dic2.ContainsKey(hash)) return dic2[hash]; var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var pos1is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos1)); var pos1is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos1)); var pos2is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos2)); var pos2is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos2)); var both0 = solver.MkAnd(new BDD[] { pos1is0, pos2is0 }); var pos11pos20 = solver.MkAnd(new BDD[] { pos1is1, pos2is0 }); var pos10pos21 = solver.MkAnd(new BDD[] { pos1is0, pos2is1 }); //Create automaton for condition var moves = new List<Move<BDD>>(); moves.Add(new Move<BDD>(0, 0, both0)); moves.Add(new Move<BDD>(0, 1, pos11pos20)); for(int i = 1;i<n;i++){ moves.Add(new Move<BDD>(i, i+1, both0)); } moves.Add(new Move<BDD>(n, n+1, pos10pos21)); moves.Add(new Move<BDD>(n+1, n+1, both0)); var dfa = Automaton<BDD>.Create(0, new int[] { n+1 }, moves).Determinize(solver).Minimize(solver); if(hashing) dic2[hash] = dfa; return dfa; }
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set, BDD pred) { int setbit = variables.IndexOf(set); //Compute predicates for pos-th bit is 0 or 1 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var posIs1 = solver.MkAnd(new BDD[] { trueBv, solver.MkSetWithBitTrue(setbit), solver.ShiftLeft(pred, variables.Count) }); var posIs0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(setbit)); //Create automaton for condition var moves = new Move<BDD>[] { new Move<BDD>(0, 0, posIs0), new Move<BDD>(0, 0, posIs1) }; var dfa = Automaton<BDD>.Create(0, new int[] { 0 }, moves); return dfa; }
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set) { int setbit = variables.IndexOf(set); Dictionary<Pair<int, int>, Automaton<BDD>> dic; if (!hashedDfa.ContainsKey(alphabet)) hashedDfa[alphabet] = new Dictionary<Pair<int, int>, Automaton<BDD>>(); dic = hashedDfa[alphabet]; var hash = new Pair<int, int>(variables.Count, setbit); if (dic.ContainsKey(hash)) return dic[hash]; //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 16) - 1), variables.Count + 16 - 1); var posIs1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(setbit)); var posIs0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(setbit)); //Create automaton for condition var moves = new Move<BDD>[] { new Move<BDD>(0, 0, posIs0), new Move<BDD>(0, 1, posIs1), new Move<BDD>(1, 1, posIs0) }; //Generate the dfa correpsonding to regexp var dfa = Automaton<BDD>.Create(0, new int[] { 1 }, moves); if(hashing) dic[hash] = dfa; return dfa; }
internal static Automaton<BDD> computeDFA(List<string> variables, BDD alphabet, CharSetSolver solver, string set1, string set2) { var pos1 = variables.IndexOf(set1); var pos2 = variables.IndexOf(set2); Dictionary<Pair<int, int>, Automaton<BDD>> dic1 = null; Pair<int, int> pair = null; if (hashing) { if (!hashedDfa.ContainsKey(alphabet)) hashedDfa[alphabet] = new Dictionary<int, Dictionary<Pair<int, int>, Automaton<BDD>>>(); var dic = hashedDfa[alphabet]; if (!dic.ContainsKey(variables.Count)) dic[variables.Count] = new Dictionary<Pair<int, int>, Automaton<BDD>>(); dic1 = dic[variables.Count]; pair = new Pair<int, int>(pos1, pos2); if (dic1.ContainsKey(pair)) return dic1[pair]; } //Create conditions that bit in pos1 is smaller than pos2 var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 7) - 1), variables.Count + 7 - 1); var pos2is1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(pos2)); var pos1is0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(pos1)); var subsetCond = solver.MkOr(pos2is1, pos1is0); //Create automaton for condition var moves = new Move<BDD>[] { new Move<BDD>(0, 0, subsetCond) }; var dfa = Automaton<BDD>.Create(0, new int[] { 0 }, moves).Determinize(solver).Minimize(solver); if(hashing) dic1[pair] = dfa; return dfa; }
internal override Automaton<BDD> getDFA(List<string> variables, BDD alphabet, CharSetSolver solver) { int varbit = variables.IndexOf(var1); Dictionary<Pair<int, int>, Automaton<BDD>> dic; if (!hashedDfa.ContainsKey(alphabet)) hashedDfa[alphabet] = new Dictionary<Pair<int, int>, Automaton<BDD>>(); dic = hashedDfa[alphabet]; var hash = new Pair<int, int>(variables.Count, varbit); if (dic.ContainsKey(hash)) return dic[hash]; //Create conditions var trueBv = solver.MkSetFromRange(0, (uint)(Math.Pow(2, variables.Count + 7) - 1), variables.Count + 7 - 1); var posis1 = solver.MkAnd(trueBv, solver.MkSetWithBitTrue(varbit)); var posis0 = solver.MkAnd(trueBv, solver.MkSetWithBitFalse(varbit)); //Create automaton for condition var moves = new Move<BDD>[] { new Move<BDD>(0, 1, posis1), new Move<BDD>(1, 1, posis0) }; var dfa = Automaton<BDD>.Create(0, new int[] { 1 }, moves).Determinize(solver).Minimize(solver); dic[hash] = dfa; return dfa; }