当前位置: 首页>>代码示例>>C#>>正文


C# Automaton.GetFinalStates方法代码示例

本文整理汇总了C#中Automaton.GetFinalStates方法的典型用法代码示例。如果您正苦于以下问题:C# Automaton.GetFinalStates方法的具体用法?C# Automaton.GetFinalStates怎么用?C# Automaton.GetFinalStates使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Automaton的用法示例。


在下文中一共展示了Automaton.GetFinalStates方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertToAutomatonOverBvSet

        static Automaton<BDD> ConvertToAutomatonOverBvSet(Z3Provider solver, Automaton<Expr> aut)
        {
            var moves = new List<Move<BDD>>();
             foreach (var move in aut.GetMoves())
                 if (move.IsEpsilon)
                     moves.Add(Move<BDD>.Epsilon(move.SourceState, move.TargetState));
                 else
                     moves.Add(Move<BDD>.Create(move.SourceState, move.TargetState, solver.ConvertToCharSet(move.Label)));

             var res = Automaton<BDD>.Create(solver.CharSetProvider, aut.InitialState, aut.GetFinalStates(), moves);
             return res;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:12,代码来源:Bek2Tests.cs

示例2: GetClosestElement


//.........这里部分代码省略.........
                                Lnew[c][S, T] = Lold[c][S, T];
                        }
                    }

                }
                Pold = Pnew;
                Pnew=new int[states.Length, states.Length];
                foreach (var c in chars)
                    Lold[c] = Lnew[c];

                Lnew = new Dictionary<char, bool[,]>();
                foreach (var c in chars)
                    Lnew[c] = new bool[states.Length, states.Length];

            }

            //Initialize table for value 0
            Pair<int, int>[,] F = new Pair<int, int>[maxl, automaton.StateCount];
            foreach (var st in automaton.States)
            {
                var T = stToInd[st];
                if (st == automaton.InitialState)
                    F[0, T] = new Pair<int, int>(0, -1);
                else
                    F[0, T] = new Pair<int, int>(int.MaxValue, -1);
            }

            //solver.ShowGraph(automaton,"aa");
            //Dynamic programming loop
            List<int> stateList = new List<int>();
            for (int j = 1; j < maxl; j++)
            {
                var aj = input[j - 1];
                foreach (var stT in automaton.States)
                {
                    var T = stToInd[stT];
                    int min = int.MaxValue;
                    int minSt = -1;
                    foreach (var stS in automaton.States)
                    {
                        var S = stToInd[stS];

                        var pts = Pold[S, T];
                        if (pts != int.MaxValue)
                        {
                            var ltsc = Lold[aj][S, T] ? 1 : 0;
                            int vts = pts == 0 ? 1 - ltsc : pts - ltsc;
                            var fjm1t = F[j - 1, S];
                            int expr = fjm1t.First + vts;

                            if (fjm1t.First == int.MaxValue || vts == int.MaxValue)
                                expr = int.MaxValue;
                            else
                                if (expr <= min)
                                {
                                    min = expr;
                                    minSt = S;
                                    if (min == 0)
                                        break;
                                }
                        }
                    }
                    F[j, T] = new Pair<int, int>(min, minSt);
                }
            }

            //Iteration over final states
            int minAcc = int.MaxValue;
            int minState = -1;
            foreach (var st in automaton.GetFinalStates())
            {
                var S = stToInd[st];
                if (F[input.Length, S].First < minAcc)
                {
                    minAcc = F[input.Length, S].First;
                    minState = F[input.Length, S].Second;
                    minState = S;
                }
            }
            var minString ="";
            int curr = minState;
            int strindex = input.Length;
            while (strindex > 0)
            {
                var f = F[strindex, curr];
                var aj = input[strindex-1];

                var pts = Pold[f.Second,curr];
                var ltsc = Lold[aj][f.Second,curr] ? 1 : 0;
                string vts = pts == 0 ? ((ltsc == 1)? aj.ToString():"") : ((ltsc == 1) ? ShortStringStoTwithC(aj, states[f.Second], states[curr], automaton, bound, solver) : ShortStringStoT(states[f.Second], states[curr], automaton, bound, solver));

                minString = vts + minString;

                curr = f.Second;
                strindex--;
            }

            distance=minAcc;
            return minString;
        }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:101,代码来源:EditDistance.cs

示例3: GetTestSets

        public static Pair<List<string>, List<string>> GetTestSets(
            Automaton<BDD> dfa, HashSet<char> alphabet, CharSetSolver solver)
        {
            List<string> positive = new List<string>();
            List<string> negative = new List<string>();
            var finalStates = dfa.GetFinalStates().ToList();

            ComputeModels("", dfa.InitialState, dfa, finalStates, alphabet, solver, positive, negative);

            positive.Sort();
            negative.Sort();
            return new Pair<List<string>, List<string>>(positive, negative);
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:13,代码来源:DFAUtilities.cs

示例4: getSimplePathsDFS

        internal static void getSimplePathsDFS(int currState, Automaton<BDD> dfa, List<List<int>> paths, List<int> currPath)
        {
            foreach (var move in dfa.GetMovesFrom(currState))
            {
                if (!currPath.Contains(move.TargetState))
                {
                    var npath = new List<int>(currPath);
                    npath.Add(move.TargetState);
                    if (dfa.GetFinalStates().Contains(move.TargetState))
                        paths.Add(npath);
                    getSimplePathsDFS(move.TargetState, dfa, paths, npath);
                }
            }

        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:15,代码来源:DFAUtilities.cs

示例5: normalizeDFA

        public static Pair<Automaton<BDD>,Dictionary<int,int>> normalizeDFA(Automaton<BDD> dfa)
        {
            Dictionary<int, int> stateToNewNames = new Dictionary<int, int>();
            Dictionary<int, int> newNamesToStates = new Dictionary<int, int>();
            int i = 0;
            foreach (var state in dfsStartingTimes(dfa))
            {
                newNamesToStates[i] = state;
                stateToNewNames[state] = i;
                i++;
            }

            var oldFinalStates = dfa.GetFinalStates();
            var newFinalStates = new List<int>();
            foreach (var st in oldFinalStates)
                newFinalStates.Add(stateToNewNames[st]);

            var oldMoves = dfa.GetMoves();
            var newMoves = new List<Move<BDD>>();
            foreach (var move in oldMoves)
                newMoves.Add(new Move<BDD>(stateToNewNames[move.SourceState], stateToNewNames[move.TargetState], move.Label));

            return new Pair<Automaton<BDD>, Dictionary<int, int>>(Automaton<BDD>.Create(0, newFinalStates, newMoves), newNamesToStates);
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:24,代码来源:DFAUtilities.cs

示例6: GenerateShortTerm

        internal static string GenerateShortTerm(Automaton<BDD> dfa, CharSetSolver solver)
        {
            if (dfa.IsEmpty)
                return null;

            Dictionary<int, string> shortStr = new Dictionary<int, string>();

            HashSet<int> reachedStates = new HashSet<int>();
            List<int> toExplore = new List<int>();


            reachedStates.Add(dfa.InitialState);
            toExplore.Add(dfa.InitialState);
            shortStr.Add(dfa.InitialState, "");
            var finSts = dfa.GetFinalStates();
            if (finSts.Contains(dfa.InitialState))
                return "";

            string sCurr = ""; char condC = 'a';
            while (toExplore.Count != 0)
            {
                var current = toExplore.First();
                toExplore.RemoveAt(0);
                shortStr.TryGetValue(current, out sCurr);

                var reachableFromCurr = dfa.GetMovesFrom(current);
                foreach (var move in reachableFromCurr)
                {
                    if (!reachedStates.Contains(move.TargetState))
                    {
                        reachedStates.Add(move.TargetState);
                        toExplore.Add(move.TargetState);

                        if (move.Label == null)
                        {
                            shortStr.Add(move.TargetState, sCurr);
                        }
                        else
                        {
                            foreach (var v in solver.GenerateAllCharacters(move.Label, false))
                            {
                                condC = v;
                                break;
                            }
                            shortStr.Add(move.TargetState, sCurr + condC);
                        }
                        if (finSts.Contains(move.TargetState))
                        {
                            return sCurr + condC;
                        }

                    }
                }
            }
            return null;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:56,代码来源:DFAUtilities.cs

示例7: GetDFAEditScriptTimeout

        // looks for an edit at depth "depth" 
        // returns false and null in bestScript if no edit is found at depth "depth"
        // returns false and not null in bestScript if found
        // returns true if timeout
        internal static bool GetDFAEditScriptTimeout(
            Automaton<BDD> dfa1, Automaton<BDD> dfa2,
            HashSet<char> al, CharSetSolver solver,
            List<long> editScriptHash, List<DFAEdit> editList,
            int depth, long timeout, Stopwatch sw,
            Pair<IEnumerable<string>, IEnumerable<string>> tests,
            double dfa1density,
            int totalCost,
            DFAEditScript bestScript, Dictionary<int, int> stateNamesMapping)
        {
            // check timer
            if (sw.ElapsedMilliseconds > timeout)
                return true;

            //Compute worst case distance, call finalScript with this value?
            int dist = (dfa1.StateCount + dfa2.StateCount) * (al.Count + 1);

            //Stop if no more moves left
            if (depth == 0)
            {
                if (DFAUtilities.ApproximateMNEquivalent(tests, dfa1density, dfa2, al, solver) && dfa2.IsEquivalentWith(dfa1, solver))
                    //check if totalCost < finalScript cost and replace if needed
                    if (bestScript.script == null || totalCost < bestScript.GetCost())
                        bestScript.script = ObjectCopier.Clone<List<DFAEdit>>(editList);
                return false;
            }

            DFAEdit edit = null;

            #region Flip one move target state
            foreach (var move in dfa2.GetMoves())
            {
                //Creaty copy of the moves without current move
                var movesWithoutCurrMove = dfa2.GetMoves().ToList();
                movesWithoutCurrMove.Remove(move);

                //Redirect every ch belonging to move condition
                foreach (var c in solver.GenerateAllCharacters(move.Label, false))
                {
                    long hash = IntegerUtil.PairToInt(move.SourceState, c - 97) + dfa2.StateCount;

                    if (CanAdd(hash, editScriptHash))
                    {
                        editScriptHash.Insert(0, hash);

                        //Local copy of moves
                        var newMoves = movesWithoutCurrMove.ToList();
                        var newMoveCondition = solver.MkCharConstraint(false, c);

                        #region Remove ch from current move
                        var andCond = solver.MkAnd(move.Label, solver.MkNot(newMoveCondition));
                        //add back move without ch iff satisfiable
                        if (solver.IsSatisfiable(andCond))
                            newMoves.Add(new Move<BDD>(move.SourceState, move.TargetState, andCond));
                        #endregion

                        #region Redirect c to a different state
                        foreach (var state in dfa2.States)
                            if (state != move.TargetState)
                            {
                                var newMovesComplete = newMoves.ToList();
                                newMovesComplete.Add(new Move<BDD>(move.SourceState, state, newMoveCondition));
                                var dfa2new = Automaton<BDD>.Create(dfa2.InitialState, dfa2.GetFinalStates(), newMovesComplete);

                                edit = new DFAEditMove(stateNamesMapping[move.SourceState], stateNamesMapping[state], c);
                                editList.Insert(0, edit);
                                if (GetDFAEditScriptTimeout(dfa1, dfa2new, al, solver, editScriptHash, editList, depth - 1, timeout, sw, tests, dfa1density, totalCost + edit.GetCost(), bestScript, stateNamesMapping))
                                    return true;
                                editList.RemoveAt(0);
                            }
                        #endregion

                        editScriptHash.RemoveAt(0);

                    }
                }
            }
            #endregion

            #region Flip one state from fin to non fin
            foreach (var state in dfa2.States)
            {
                if (CanAdd(state, editScriptHash))
                {
                    //flip its final non final status
                    editScriptHash.Insert(0, state);

                    var newFinalStates = new HashSet<int>(dfa2.GetFinalStates());
                    Automaton<BDD> dfa2new = null;
                    if (dfa2.GetFinalStates().Contains(state))
                    {
                        edit = new DFAEditState(stateNamesMapping[state], false);
                        editList.Insert(0, edit);
                        newFinalStates.Remove(state);
                        dfa2new = Automaton<BDD>.Create(dfa2.InitialState, newFinalStates, dfa2.GetMoves());
                    }
//.........这里部分代码省略.........
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:101,代码来源:DFAEditDistance.cs

示例8: GetNFAEditScriptTimeout

        // looks for an edit at depth "depth" 
        // returns false and null in bestScript if no edit is found at depth "depth"
        // returns false and not null in bestScript if found
        // returns true if timeout
        internal bool GetNFAEditScriptTimeout(
            int depth, long lastEditHash, 
            Automaton<BDD> currentNfa2,
            List<NFAEdit> editList, int scriptCost,
            NFAEditScript bestScript)
        {
            // if timeout return true
            if (sw.ElapsedMilliseconds > timeout)
                return true;


            //Stop if no more moves left
            if (depth == 0)
            {
                if (DFAUtilities.ApproximateMNEquivalent(tests, nfa1density, currentNfa2, al, solver) && currentNfa2.IsEquivalentWith(nfa1, solver))
                    //check if totalCost < finalScript cost and replace if needed
                    if (bestScript.script == null || scriptCost < bestScript.GetCost())
                        bestScript.script = ObjectCopier.Clone<List<NFAEdit>>(editList);
                return false;
            }

            NFAEdit edit = null;

            long thisEditHash = 0;

            #region Flip one state from fin to non fin
            foreach (var state in currentNfa2.States)
            {
                thisEditHash = state;
                if (CanAdd(thisEditHash, lastEditHash))
                {
                    //flip its final non final status

                    var newFinalStates = new HashSet<int>(currentNfa2.GetFinalStates());
                    Automaton<BDD> nfa2new = null;
                    if (currentNfa2.GetFinalStates().Contains(state))
                    {
                        edit = new NFAEditState(state, false);
                        editList.Insert(0, edit);
                        newFinalStates.Remove(state);
                        nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, newFinalStates, currentNfa2.GetMoves());
                    }
                    else
                    {
                        edit = new NFAEditState(state, true);
                        editList.Insert(0, edit);
                        newFinalStates.Add(state);
                        nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, newFinalStates, currentNfa2.GetMoves());
                    }

                    if (GetNFAEditScriptTimeout(depth - 1, thisEditHash, nfa2new, editList, scriptCost + edit.GetCost(), bestScript))
                        return true;

                    editList.RemoveAt(0);
                }
            }
            #endregion

            #region Change transition from source state
            currentNfa2 = NFAUtilities.normalizeMoves(currentNfa2, solver);
            foreach (var sourceState in currentNfa2.States)
            {
                HashSet<int> unreachedStates = new HashSet<int>(currentNfa2.States);
                foreach (var moveFromSource in currentNfa2.GetMovesFrom(sourceState))
                {
                    // take all chars in alphabet
                    foreach (var c in al)
                    {
                        long moveHash =  currentNfa2.StateCount + IntegerUtil.TripleToInt(sourceState, moveFromSource.TargetState, alphabetMap[c]);
                        thisEditHash = currentNfa2.StateCount + moveHash;
                        if (CanAdd(thisEditHash, lastEditHash))
                        {
                            BDD cCond = solver.False;
                            BDD newCond = solver.False;

                            //skip epsilon moves
                            if (moveFromSource.Label != null)
                            {
                                // if c in move, remove it and recursion
                                if (solver.Contains(moveFromSource.Label, c))
                                {
                                    cCond = solver.MkNot(solver.MkCharConstraint(false, c));
                                    newCond = solver.MkAnd(moveFromSource.Label, cCond);
                                }
                                else // if c not in move, add it and recursion
                                {
                                    cCond = solver.MkCharConstraint(false, c);
                                    newCond = solver.MkOr(moveFromSource.Label, cCond);
                                }

                                var newMoves = new List<Move<BDD>>(currentNfa2.GetMoves());
                                newMoves.Remove(moveFromSource);
                                newMoves.Add(new Move<BDD>(sourceState, moveFromSource.TargetState, newCond));
                                var nfa2new = Automaton<BDD>.Create(currentNfa2.InitialState, currentNfa2.GetFinalStates(), newMoves);

                                edit = new NFAEditMove(sourceState, moveFromSource.TargetState, c);
//.........这里部分代码省略.........
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:101,代码来源:NFAEditDistance.cs

示例9: canRemoveState

        public static bool canRemoveState(Automaton<BDD> nfa, int state, CharSetSolver solver, Pair<IEnumerable<string>, IEnumerable<string>> tests, HashSet<char> al)
        {
            var newNfa = Automaton<BDD>.Create(nfa.InitialState, nfa.GetFinalStates(), nfa.GetMoves());
            newNfa.RemoveTheState(state);

            if (DFAUtilities.ApproximateMNEquivalent(tests, 0.5, newNfa, al, solver))
                return nfa.IsEquivalentWith(newNfa, solver);
            return false;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:9,代码来源:NFAUtilities.cs

示例10: canRemoveEdge

        public static bool canRemoveEdge(Automaton<BDD> nfa, int sourceState, int targetState, CharSetSolver solver, Pair<IEnumerable<string>, IEnumerable<string>> tests, HashSet<char> al)
        {
            List<Move<BDD>> newMoves = new List<Move<BDD>>();
            newMoves = nfa.GetMoves().ToList();
            bool moveExists = false;

            //goes through each move from state1 and remove it if it goes to state2 resp.
            foreach (var move in nfa.GetMovesFrom(sourceState))
                if (move.TargetState == targetState)
                {
                    newMoves.Remove(move);
                    moveExists = true;
                }

            var newNfa = Automaton<BDD>.Create(nfa.InitialState, nfa.GetFinalStates(), newMoves);

            if(moveExists)
                if (DFAUtilities.ApproximateMNEquivalent(tests, 0.5, newNfa, al, solver))
                    return nfa.IsEquivalentWith(newNfa, solver);
            return false;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:21,代码来源:NFAUtilities.cs

示例11: canCollapseStates

        public static bool canCollapseStates(Automaton<BDD> nfa, int state1, int state2, CharSetSolver solver, Pair<IEnumerable<string>, IEnumerable<string>> tests, HashSet<char> al)
        {
            
            var density =  DFADensity.GetDFADensity(nfa, al, solver);
 
            // collapses state2 to state1
            List<Move<BDD>> newMoves = new List<Move<BDD>>();

            foreach (var move in nfa.GetMoves())
            {
                var newSource = move.SourceState;
                var newTarget = move.TargetState;

                if (newSource == state2)
                    newSource = state1;
                if (newTarget == state2)
                    newTarget = state1;
                
                newMoves.Add(new Move<BDD>(newSource, newTarget, move.Label));
            }

            // replace state2 with state1 if initial state
            // no need to remove state2 from final state list, as it is unreachable
            int newInitialState = nfa.InitialState;
            if (nfa.InitialState == state2)
                newInitialState = state1;

            //makes new Nfa and returns collapse state edit if are equiv
            var newNfa = Automaton<BDD>.Create(newInitialState, nfa.GetFinalStates(), newMoves);
            
            if(DFAUtilities.ApproximateMNEquivalent(tests, density, newNfa, al, solver)) 
                return nfa.IsEquivalentWith(newNfa, solver);
            return false;
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:34,代码来源:NFAUtilities.cs

示例12: normalizeMoves

        /// <summary>
        /// Returns an automaton where transitions between states are collapsed to a single one
        /// </summary>
        /// <param name="automaton"></param>
        /// <param name="solver"></param>
        /// <returns></returns>
        public static Automaton<BDD> normalizeMoves(Automaton<BDD> automaton, CharSetSolver solver)
        {
            List<Move<BDD>> normMoves = new List<Move<BDD>>();
            foreach (var sourceState in automaton.States)
            {
                Dictionary<int, BDD> moveConditions = new Dictionary<int, BDD>();
                foreach (var moveFromSourceState in automaton.GetMovesFrom(sourceState))
                {
                    var target = moveFromSourceState.TargetState;
                    BDD oldCondition = null;
                    if (moveConditions.ContainsKey(target))                    
                        oldCondition = moveConditions[target];                    
                    else
                        oldCondition = solver.False;

                    if (!moveFromSourceState.IsEpsilon)
                        moveConditions[target] = solver.MkOr(oldCondition, moveFromSourceState.Label);
                    else
                        normMoves.Add(moveFromSourceState);
                }

                foreach (var targetState in moveConditions.Keys)             
                    normMoves.Add(new Move<BDD>(sourceState,targetState,moveConditions[targetState]));                
            }

            return Automaton<BDD>.Create(automaton.InitialState, automaton.GetFinalStates(), normMoves);
        }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:33,代码来源:NFAUtilities.cs

示例13: Accepts

 //returns true iff dfa accepts str
 private static bool Accepts(Automaton<BDD> dfa1,  string str, HashSet<char> al, CharSetSolver solver)
 {
     int currState = 0;
     for (int i = 0; i < str.Length; i++)
     {
         currState = GetNextState(currState, str[i], dfa1, solver);
         if (currState < 0)
             return false;
     }
     return dfa1.GetFinalStates().ToList().Contains(currState);
 }
开发者ID:AutomataTutor,项目名称:automatatutor-backend,代码行数:12,代码来源:NFAUtilities.cs


注:本文中的Automaton.GetFinalStates方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。