public Transition GetTransitionLike(String stateFrom, String input, String stateTo) { return(Transitions.Find( x => x.From.Name == stateFrom && x.Input == input && x.To.Name == stateTo )); }
/// <summary> /// Finds corresponding transition of a Petri net to given activity (the search is not case-sensitive). /// If such transition does not exist, returns null. /// </summary> /// <param name="activity">Activity of transition to look for.</param> /// <returns>Transition with given activity.</returns> public ITransition GetTransition(string activity) { if (activity == null) { throw new ArgumentNullException("Activity string cannot be null"); } return(Transitions.Find(a => a.Activity.ToLower() == activity.ToLower())); }
public State GetNextState(State currentState, char a) { var tr = Transitions.Find(b => b.Symbol == a && b.CurrentState == currentState); if (tr != null) { return(tr.NextState); } return(null); }
protected override void PreAddTransitionCheck(Transition newTransition) { var foundTransition = Transitions.Find(transition => Equals(transition.StartState, newTransition.StartState) && transition.Token == newTransition.Token); if (foundTransition != null) { throw new DuplicateTransitionException(newTransition, this); } }
protected override bool DoStep(string text, State currentState) { if (text.Length == 0) { return(currentState.IsFinal); } var token = text[0].ToString(); var way = Transitions.Find(transition => Equals(currentState, transition.StartState) && token == transition.Token); return(way != null && DoStep(text.Substring(1), way.EndState)); }
public bool CheckWord(string word) { var currentState = StartState; for (int i = 0; i < word.Length; i++) { var currentLetter = word[i]; var tr = Transitions.Find(a => a.Symbol == currentLetter && a.CurrentState == currentState); if (tr != null) { currentState = tr.NextState; } else { return(false); } } return(FinalStates.Contains(currentState)); }
/// <summary> /// Find the transition model that represents a connection to the provided index /// </summary> /// <param name="destId">The index of the destination scene</param> /// <returns>The first matching transition, or null if none found</returns> public SceneTransition GetFirstTransitionTo(int destId) { return(Transitions.Find((x) => x.DestinationSceneId == destId)); }
private int GetNextState(int currentState, char currentSymbol) { var state = Transitions.Find(s => s.InputState == currentState && s.Symbol == currentSymbol); return(state == null ? -1 : state.OutputState); }
public override Machine Minimize() { var tokens = Transitions.Select(transition => transition.Token).Distinct().ToList(); tokens.Sort(); var currentSplitting = States.GroupBy(state => state.IsFinal ? "A0" : "B0").ToList(); for (int k = 1; k <= States.Count; ++k) { var newSplitting = new List <IGrouping <string, State> >(); foreach (var currentCategory in currentSplitting) { var subSplittingIntoCurrentCategory = currentCategory.GroupBy(checkedStartState => { var kLocal = k; var currentSplittingLocal = currentSplitting; var movementCategories = tokens.Select(checkedToken => { var endState = Transitions.Find(transition => Equals(transition.StartState, checkedStartState) && transition.Token == checkedToken) ?.EndState; if (endState == null) { return(""); } var endCategory = currentSplittingLocal.Find(suspectedCategory => suspectedCategory.Contains(endState)); var nameOfEndCategory = "{" + string.Join(",", endCategory) + "}" /* + "[" + kLocal + "]"*/; return(nameOfEndCategory); }); var movementsRow = string.Join("|", movementCategories); return(movementsRow); }).ToList(); newSplitting.AddRange(subSplittingIntoCurrentCategory); } currentSplitting = newSplitting; // If current splitting ans new splitting are equal // Then break; here [todo] } var minimizedStateMachine = new MachineDetermined(); var newStates = currentSplitting.Select(category => new { State = new State("{" + string.Join(",", category.Select(state => state.Id)) + "}", category.Any(state => state.IsFinal)), Category = category }).ToList(); minimizedStateMachine.AddStateRange(newStates.Select(state => state.State)); foreach (var startPoint in newStates) { var ways = startPoint.Category.Key.Split("|") .Zip(tokens, (endPoint, token) => new { Token = token, EndPoint = endPoint }) .Where(x => !string.IsNullOrEmpty(x.EndPoint)) .Select(x => { var endPointState = newStates.Find(state => state.State.Id == x.EndPoint); return(new Transition(startPoint.State, x.Token, endPointState.State)); // Null check?? }); minimizedStateMachine.AddTransitionRange(ways); } minimizedStateMachine.Init(newStates.Find(x => x.Category.Contains(InitialState))?.State.Id ?? throw new InitialStateIsNullException("null", minimizedStateMachine)); return(minimizedStateMachine); }