/// <summary> /// Handles the start simulation button's click event. /// </summary> /// <param name="sender">The triggerer object.</param> /// <param name="e">The event arguments.</param> private void StartNewSimulation_Click(object sender, EventArgs e) { using (var simulationSettingsForm = new SimulationSettingsForm()) { if (simulationSettingsForm.ShowDialog() == DialogResult.Cancel) { return; } IAmbiguityResolver resolver = null; if (ManualResolver.Equals(AmbiguityResolverComboBox.SelectedItem)) { resolver = new ManualResolver(); } else if (RandomResolver.Equals(AmbiguityResolverComboBox.SelectedItem)) { resolver = new RandomResolver(); } var stepMethod = GetStepMethod(); Graph.OnSimulationFinished += OnSimulationFinished; Graph.StartSimulation(stepMethod, simulationSettingsForm.GetInputArray(), resolver); if (stepMethod == SimulationStepMethod.Timed) { TimedStepTimer.Interval = SimulationSpeedTrackBar.Value * 1000; TimedStepTimer.Start(); } } SetupUI(); }
public WordTree(IComparer <string> treeBuildingWordComparer, IComparer <string> closerWordComparer, IAmbiguityResolver <DictionaryWord> ambiguityResolver) { TreeBuildingWordComparer = treeBuildingWordComparer; CloserWordComparer = closerWordComparer; AmbiguityResolver = ambiguityResolver; DistanceThreshold = 1; }
/// <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(); }