コード例 #1
0
        /// <summary>
        /// Starts a new simulation based on the given parameters on the automata.
        /// </summary>
        /// <param name="stepMethod">The simulation step method.</param>
        /// <param name="input">The input symbols array.</param>
        /// <param name="resolver">The ambiguity resolver instance.</param>
        public void StartSimulation(SimulationStepMethod stepMethod, object[] input, IAmbiguityResolver resolver = null)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "The input symbols array can not be null!");
            }

            if (Simulation != null)
            {
                throw new Exception("You must stop the previous simulation!");
            }

            var filteredSymbols = new List <object>();

            foreach (var symbol in input)
            {
                if (Automata.Alphabet.ContainsSymbol(symbol))
                {
                    filteredSymbols.Add(symbol);
                }
            }

            Simulation = new SimpleSimulation(Automata, filteredSymbols.ToArray())
            {
                Resolver = resolver
            };

            switch (stepMethod)
            {
            case SimulationStepMethod.Manual:
            case SimulationStepMethod.Timed:
                Simulation.OnStep += OnSimulationStep;
                break;

            case SimulationStepMethod.Instant:
                Simulation.DoAllSteps();

                OnSimulationFinished?.Invoke();
                break;
            }

            ColorizeCurrentStateAndEdges();
        }
コード例 #2
0
        /// <summary>
        /// Does a step in the current simulation.
        /// </summary>
        /// <returns></returns>
        public SimulationStepResult StepSimulation()
        {
            if (Simulation == null)
            {
                throw new Exception("Can't step a non-existant simulation!");
            }

            var result = Simulation.Step();

            if (result == SimulationStepResult.Ambiguous)
            {
                var resolvedTransition = Simulation.Resolver.Resolve(Simulation);
                if (resolvedTransition != null)
                {
                    result = Simulation.SpecificStep(resolvedTransition);
                }
                else if (Simulation.GetApplicableTransitions().Count() >= 1)
                {
                    return(SimulationStepResult.Success);
                }
            }

            ClearColors();

            ColorizeCurrentStateAndEdges();

            if (result == SimulationStepResult.Success)
            {
                return(SimulationStepResult.Success);
            }

            if (Simulation.IsFinished)
            {
                OnSimulationFinished?.Invoke();

                return(SimulationStepResult.Finished);
            }

            return(result);
        }