Exemple #1
0
        public DFA Determinize()
        {
            if (IsDeterministic())
            {
                return(new DFA(states, sigma, initialState, transitions));
            }
            States         pStates       = new States();
            State          pInitialState = new State("{" + initialState.Name + "}", initialState.IsFinal);
            Transitions    pTransitions  = new Transitions();
            Queue <States> queue         = new Queue <States>();

            queue.Enqueue(new States {
                initialState
            });
            State sink         = new State("{}");
            bool  sinkRequired = false;

            while (queue.Count > 0)
            {
                States current = queue.Dequeue();
                if (pStates.Any(s => s.ToString().Equals(current.ToString())))
                {
                    continue;
                }
                State curr = new State(current.ToString(), current.Any(s => s.IsFinal));
                pStates.Add(curr);
                foreach (string letter in sigma)
                {
                    States next = new States();
                    foreach (State s in current)
                    {
                        try
                        {
                            foreach (State rState in transitions[(s, letter)])
 public IEnumerable <FTPEntry> GetByFileState(int Skip, int Take, bool HasParents = false, params StateFile[] States)
 {
     return(Entities
            .Find(f => f.IsActive && States.Any(i => i == f.State) && ((HasParents && f.Parent != null) || (!HasParents && f.Parent == null)))
            .Skip(Skip)
            .Limit(Take)
            .ToEnumerable());
 }
Exemple #3
0
            public void Tick()
            {
                CurrentTaskTimeout--;
                switch (CurrentState)
                {
                case CurrentStateType.WaitingInCenter:
                {
                    if (States.Any(s => s.CurrentState == CurrentStateType.MovingTowardCenter) && CurrentTaskTimeout > 0)
                    {
                        break;
                    }

                    StartMovingTowardExplosion();
                    break;
                }

                case CurrentStateType.MovingToExplosionPoint:
                    if (!DestinationsFulfilled && CurrentTaskTimeout > 0)
                    {
                        break;
                    }

                    StartExploding();
                    break;

                case CurrentStateType.Exploding:
                    if (!DestinationsFulfilled && CurrentTaskTimeout > 0)
                    {
                        break;
                    }
                    CurrentState       = CurrentStateType.WaitingInCircle;
                    CurrentTaskTimeout = 3000;

                    break;

                case CurrentStateType.WaitingInCircle:
                    if (States.Any(s => s.CurrentState == CurrentStateType.Exploding || s.CurrentState == CurrentStateType.MovingToExplosionPoint) && CurrentTaskTimeout > 0)
                    {
                        break;
                    }

                    StartMovingTowardCenter();
                    break;

                case CurrentStateType.MovingTowardCenter:
                    if (!DestinationsFulfilled && CurrentTaskTimeout > 0)
                    {
                        break;
                    }

                    CurrentState       = CurrentStateType.WaitingInCenter;
                    CurrentTaskTimeout = 2000;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        public override JsonObject ExportStatusToJsonObject()
        {
            var status = base.ExportStatusToJsonObject();

            if (States.Any())
            {
                status.SetNamedValue("state", States[_index].Id.ToJsonValue());
            }

            return(status);
        }
Exemple #5
0
 public NFA(States states, Alphabet sigma, State initialState, Transitions transitions)
 {
     this.states       = states;
     this.sigma        = sigma;
     this.initialState = initialState;
     this.transitions  = transitions;
     if (!states.Any(s => s.Name.Equals(initialState.Name)))
     {
         throw new ArgumentException("Initial state must be contained in states!");
     }
 }
        private string FormatStates()
        {
            if( States == null || !States.Any() )
                return String.Empty;

            string output = String.Empty;
            foreach( var scriptState in States )
            {
                output += "\r\n" + scriptState.Decompile() + "\r\n";
            }
            return output;
        }
Exemple #7
0
 private bool ProceedBackward()
 {
     if (States.Any())
     {
         // Есть куда возвращаться
         CurrentState = States.Pop();
         return(true);
     }
     else
     {
         // Некуда возвращаться, решения нет
         return(false);
     }
 }
Exemple #8
0
        public List <ValidationError> ValidateWorkflow()
        {
            List <ValidationError> errors = new List <ValidationError> ();

            if (!States.Any(s => s.Name == CurrentState))
            {
                errors.Add(new ValidationError("Invalid current state"));
            }

            foreach (var state in States)
            {
                foreach (var t in state.Transitions)
                {
                    if (!States.Any(s => s.Name == t.StateName))
                    {
                        String message = "Invalid transition to state " + t.StateName + " from state " + state.Name;
                        errors.Add(new ValidationError(message));
                    }



                    foreach (var r in t.Rules)
                    {
                        var rule = CommandManager.GetCommand <IRule> (r.Name);
                        if (rule == null)
                        {
                            errors.Add(new ValidationError("Invalid rule: " + r.Name));
                        }
                    }

                    foreach (var a in t.Actions)
                    {
                        var rule = CommandManager.GetCommand <IAction> (a.Name);
                        if (rule == null)
                        {
                            errors.Add(new ValidationError("Invalid action: " + a.Name));
                        }
                    }


                    if (!AuthManager.PermissionIsValid(t.Permission))
                    {
                        errors.Add(new ValidationError("Invalid permission " + t.Permission));
                    }
                }
            }

            return(errors);
        }
        public int GetCategoryIndex(string category)
        {
            if (States.Any(x => x.Category == category))
            {
                return(States.First(x => x.Category == category).CategoryIndex);
            }
            if (States.Count == 0)
            {
                return(1);
            }

            int highestCatIndex = States.Max(x => x.CategoryIndex);

            return(highestCatIndex + 1);
        }
Exemple #10
0
        void OnValidate()
        {
            if (Application.isPlaying)
            {
                return;
            }

            AnimatorController preview = Animator.runtimeAnimatorController as AnimatorController;

            if (!preview || preview.name != "UIPlayable Preview")
            {
                preview           = new AnimatorController();
                preview.name      = "UIPlayable Preview";
                preview.hideFlags = HideFlags.DontSave;
                preview.AddLayer("Base Layer");
                preview.AddLayer("Preview Layer");
                preview.layers[1].defaultWeight = 0;

                Animator.runtimeAnimatorController = preview;
            }

            foreach (var childAnimatorState in preview.layers[1].stateMachine.states)
            {
                var  animatorState = childAnimatorState.state;
                bool exist         = States.Any(state => state.Animation == animatorState.motion || state.LoopAnimation == animatorState.motion);
                if (!exist)
                {
                    preview.RemoveLayer(1);
                    preview.AddLayer("Preview Layer");
                    preview.layers[1].defaultWeight = 0;
                    break;
                }
            }
            foreach (State state in States)
            {
                if (state.Animation)
                {
                    AddMotionIfNotExist(preview, state.Animation);
                }
                if (state.LoopAnimation)
                {
                    AddMotionIfNotExist(preview, state.LoopAnimation);
                }
            }
        }
 public IState <TIn, TOut> AddState(IState <TIn, TOut> state)
 {
     if (state == null)
     {
         return(null);
     }
     if (States.Any(s => s.GUID == state.GUID))
     {
         // We already have this state registered
         return(state);
     }
     if (RootState.Value == null)
     {
         // Set this to be the root state if none exists
         RootState = new Reference <IState <TIn, TOut> >(state);
     }
     state.Definition = this;
     States.Add(state);
     return(state);
 }
Exemple #12
0
        public Order InTransit()
        {
            if (!States.Any())
            {
                throw new OrderStatesNotFoundBusinessException();
            }

            var stateName = States.OrderByDescending(x => x.CreatedDate).FirstOrDefault().StateName;

            if (stateName != Consts.Order.Collecting)
            {
                throw new OrderStateIsNotValidBusinessException();
            }

            States.Add(new State {
                CreatedDate = DateTime.Now, StateName = Consts.Order.InTransit
            });

            return(this);
        }
Exemple #13
0
        private FA(State start, State final, IEnumerable <State> states)
        {
            Start  = start;
            Final  = final;
            States = states.Select((state, i) => { state.Id = i; return(state); }).ToList();

            if (final == null)
            {
                if (!States.Any(state => state.IsFinal))
                {
                    Debug.Assert(false, "no final state in DFA");
                }
            }
            else
            {
                if (States.Any(state => state.IsFinal))
                {
                    Debug.Assert(false, "final state in NFA");
                }
            }
        }
Exemple #14
0
        public bool Validate()
        {
            if (States == null)
            {
                throw new ArgumentException("StateMachine: States are not defined");
            }

            if (!States.Any(_ => _.StartPoint))
            {
                throw new ArgumentException("StateMachine: initial state is not defined");
            }

            if (States.Count(_ => _.StartPoint) > 1)
            {
                throw new ArgumentException("StateMachine: too many initial states");
            }

            if (!States.Any(_ => _.EndPoint))
            {
                throw new ArgumentException("StateMachine: final state is not defined");
            }

            return(true);
        }
Exemple #15
0
 public bool IsCurrent(T applicationState)
 {
     return(States.Any() && States.Last().Equals(applicationState));
 }