public BVAlgebra(CharSetSolver solver, BDD[] minterms) { this.minterms = minterms; this.solver = solver; this.nrOfBits = minterms.Length; var K = (nrOfBits - 1) / 64; int last = nrOfBits % 64; ulong lastMask = (last == 0 ? ulong.MaxValue : (((ulong)1 << last) - 1)); all0 = new ulong[K]; all1 = new ulong[K]; for (int i = 0; i < K; i++) { all0[0] = 0; if (i < K - 1) { all1[i] = ulong.MaxValue; } else { all1[i] = lastMask; } } this.zero = new BV(minterms.Length, 0, all0); this.ones = new BV(minterms.Length, (K == 0 ? lastMask : ulong.MaxValue), all1); this.mtg = new MintermGenerator <BV>(this); this.dtree = DecisionTree.Create(solver, minterms); this.atoms = new BV[minterms.Length]; for (int i = 0; i < minterms.Length; i++) { atoms[i] = MkBV(i); } }
public static BVAlgebra Create(CharSetSolver solver, BDD[] minterms) { var dtree = DecisionTree.Create(solver, minterms); var partitionBase = Array.ConvertAll(minterms, m => solver.ToRanges(m)); var partition = Array.ConvertAll(partitionBase, p => new IntervalSet(p)); return(new BVAlgebra(dtree, partition)); }
public static BV64Algebra Create(CharSetSolver solver, BDD[] minterms) { if (minterms.Length > 64) { throw new AutomataException(AutomataExceptionKind.NrOfMintermsCanBeAtMost64); } var dtree = DecisionTree.Create(solver, minterms); var partitionBase = Array.ConvertAll(minterms, m => m.ToRanges()); var partition = Array.ConvertAll(partitionBase, p => new IntervalSet(p)); return(new BV64Algebra(dtree, partition)); }
static internal RegexAutomaton Create(CharSetSolver solver, Regex regex) { int t0 = System.Environment.TickCount; var nfa = solver.Convert(regex.ToString(), regex.Options); var minterms = GetMinterms(nfa); //create specialized BV algebra for this particular minterm partition var bvsolver = new BVAlgebra(solver, minterms); //convert the nfa to the specialized algebra var nfa_BV = nfa.ReplaceAlgebra <BV>(bvsolver.MapPredToBV, bvsolver); t0 = System.Environment.TickCount - t0; int t = System.Environment.TickCount; var nfa1 = nfa.Minimize();//.RemoveEpsilons().Minimize(); var dfa = nfa1.Determinize().Minimize().Normalize(); t = System.Environment.TickCount - t; int t_BV = System.Environment.TickCount; var nfa1_BV = nfa_BV;//.RemoveEpsilons().Minimize(); var dfa_BV = nfa1_BV.Minimize().Determinize(); var dfa_BV_min = dfa_BV.Minimize().Normalize(); t_BV = System.Environment.TickCount - t_BV; //number of states var N = dfa.StateCount; //number of symbols int t2 = System.Environment.TickCount; var K = minterms.Length; var isfinalstate = new HashSet <int>(); var nonfinalSinkstate = -1; var finalSinkstate = -1; for (int q = 0; q < N; q++) { if (dfa.IsFinalState(q)) { isfinalstate.Add(q); } if (dfa.IsLoopState(q) && dfa.GetMovesCountFrom(q) == 1) { //there can only be at most one of each because dfa is minimal if (dfa.IsFinalState(q)) { if (finalSinkstate != -1) { throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton); } finalSinkstate = q; } else { if (nonfinalSinkstate != -1) { throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton); } nonfinalSinkstate = q; } } } var delta = new int[K * N]; for (int q = 0; q < dfa.StateCount; q++) { int symbols_mapped = 0; foreach (var move in dfa.GetMovesFrom(q)) { for (int a = 0; a < K; a++) { var phi = solver.MkAnd(move.Label, minterms[a]); if (!phi.IsEmpty) { delta[(move.SourceState * K) + a] = move.TargetState; symbols_mapped += 1; } } } if (symbols_mapped != K) { throw new AutomataException(AutomataExceptionKind.InternalError_RegexAutomaton); } } var dt = DecisionTree.Create(solver, minterms); var ra = new RegexAutomaton(bvsolver, regex, K, N, delta, isfinalstate, dt, nonfinalSinkstate, finalSinkstate); t2 = System.Environment.TickCount - t2; return(ra); }