예제 #1
0
            bool dfs1(ITlaState q)
            {
                _hash.Add(q.Id);

                //for all последователей q' вершины q do
                //    if q' не содержится в хэш-таблице then dfsl (q');

                foreach (var q1 in q.Outgoings.Select(t => t.ToState))
                {
                    if (!_hash.Contains(q1.Id))
                    {
                        if (dfs1(q1))
                        {
                            return(true);
                        }
                    }
                }

                //if accept(q) then dfs2(q);
                if (q.IsAccepting)
                {
                    if (dfs2(q))
                    {
                        return(true);
                    }
                }

                return(false);
            }
예제 #2
0
        private PathItem RunAutomatonFrom(ITlaState initState, Func <PathItem, bool> finishCondition)
        {
            var handledStateIds = new SortedSet <int>();
            var stack           = new Stack <PathItem>();

            stack.Push(new PathItem(initState, null, null));

            while (stack.Count > 0)
            {
                var item    = stack.Pop();
                var stateId = item.State.Id;

                if (!handledStateIds.Contains(stateId))
                {
                    handledStateIds.Add(stateId);

                    foreach (var transition in item.State.Outgoings)
                    {
                        var newItem = new PathItem(transition.ToState, item, transition);
                        if (finishCondition(newItem))
                        {
                            return(newItem);
                        }

                        stack.Push(newItem);
                    }
                }
            }

            return(null);
        }
예제 #3
0
 public ParallelPathItem(ParallelPathItem prev, ITlaState state, ITlaTransition fromTransition, ITlaState checkerState, ITlaTransition checkerFromTransition)
     : base(state, prev, fromTransition)
 {
     this.Prev                  = prev;
     this.CheckerState          = checkerState;
     this.CheckerFromTransition = checkerFromTransition;
     this.Length                = prev == null ? 1 : prev.Length;
 }
예제 #4
0
        private bool TransitionConditionsIntersects(ITlaState modelState, TlaFormula modelCondition, TlaFormula ltlFormula)
        {
            var varNames = modelCondition.GetAllVars();

            // var result = ltlFormula.Evaluate(vname => varNames.Contains(vname));
            var result = ltlFormula.Evaluate(vname => vname == modelState.Name || modelState.Name.StartsWith(vname + "|") || varNames.Contains(vname));

            return(result);
        }
예제 #5
0
            public bool IsCheckersAny(ITlaState checkerState)
            {
                for (var s = this; s != null; s = s.Prev)
                {
                    if (s.CheckerState == checkerState)
                    {
                        return(true);
                    }
                }

                return(false);
            }
예제 #6
0
            public bool IsAny(ITlaState state)
            {
                for (var s = this; s != null; s = s.Prev)
                {
                    if (s.State == state)
                    {
                        return(true);
                    }
                }

                return(false);
            }
예제 #7
0
        private PathItem RunChecker(ITlaState from, ITlaState checker, int limit)
        {
            var stack = new Stack <ParallelPathItem>();

            stack.Push(new ParallelPathItem(null, from, null, checker, null));
            Console.WriteLine("Running checker from {0}", from.Name);

            while (stack.Count > 0)
            {
                var item = stack.Pop();
                if (item.CheckerState.IsAccepting && item.State.IsAccepting)
                {
                    return(item);
                }

                foreach (var modelTransition in item.State.Outgoings)
                {
                    foreach (var checkerTransition in item.CheckerState.Outgoings)
                    {
                        if (this.TransitionConditionsIntersects(item.State, modelTransition.Condition, checkerTransition.Condition))
                        {
                            if (!item.IsAny(modelTransition.ToState) && !item.IsCheckersAny(checkerTransition.ToState))
                            {
                                var newItem = new ParallelPathItem(item, modelTransition.ToState, modelTransition, checkerTransition.ToState, checkerTransition);
                                Console.WriteLine("\t{0}({1}) -> {2}({3})", item.State, item.CheckerState, newItem.State, newItem.CheckerState);

                                if (newItem.Length % limit == 0)
                                {
                                    Console.WriteLine("Traverse depth warning: {0}! Press any key to continue, B to break particular path, A to abort traversing.", newItem.Length);

                                    switch (Console.ReadKey().Key)
                                    {
                                    case ConsoleKey.B: continue;

                                    case ConsoleKey.A: return(null);
                                    }
                                }

                                stack.Push(newItem);
                            }
                        }
                    }
                }
            }

            return(null);
        }
예제 #8
0
        private int ComputeTransitionY(ITlaState modelTargetState, ITlaState ltlTargetState, int x)
        {
            int y;

            if (x == 0 && modelTargetState.IsAccepting)
            {
                y = 1;
            }
            else if (x == 1 && ltlTargetState.IsAccepting)
            {
                y = 2;
            }
            else if (x == 2)
            {
                y = 0;
            }
            else
            {
                y = x;
            }

            return(y);
        }
예제 #9
0
            bool dfs2(ITlaState q)
            {
                _flag.Add(q.Id);

                //for all последователей q' вершины q do
                //    if q' в стеке dfsl then terminate(True);
                //    else if q' не является помеченной then dfs2(q')',
                //    end if;

                foreach (var q1 in q.Outgoings.Select(t => t.ToState))
                {
                    if (_hash.Contains(q1.Id))
                    {
                        return(true);
                    }
                    else if (!_flag.Contains(q1.Id))
                    {
                        dfs2(q1);
                    }
                }

                return(false);
            }
예제 #10
0
 public PathItem(ITlaState state, PathItem prev, ITlaTransition fromTransition)
 {
     this.State          = state;
     this.Prev           = prev;
     this.FromTransition = fromTransition;
 }