/// <summary> /// Initializes a new instance of <see cref="Transition"/> /// </summary> /// <param name="graph">Parent graph of which the new edge is associated</param> /// <param name="source"></param> /// <param name="target"></param> /// <param name="value"></param> public Transition(Graph graph, IState source, IState target, ITransitionValue value) { Graph = graph; Source = source; Target = target; Value = value; }
public (IState State, ITransition Transition) AddState(IState source, ITransitionValue transitionValue) { if (source.Graph != this) { throw new InvalidOperationException("Source state is not part of the graph"); } var target = new State(this); states.Add(target); var transition = Connect(source, target, transitionValue); return(target, transition); }
public ITransition Connect(IState source, IState target, ITransitionValue value) { if (source.Graph != this) { throw new InvalidOperationException("Connecting source is not part of the graph"); } if (target.Graph != this) { throw new InvalidOperationException("Connecting target is not part of the graph"); } var existingTransitions = source.TransitionsTo(target); // Just return the exisitng transition when the states are already connected with the same value var equalTransition = existingTransitions.SingleOrDefault(t => t.Value.Equals(value)); if (!(equalTransition is null)) { return(equalTransition); } // Would only expect a single intersection var intersection = existingTransitions.SingleOrDefault(t => t.Value.AdjacentOrIntersecting(value)); if (!(intersection is null)) { var union = value.Union(intersection.Value); value = union; Remove(intersection); } var transition = new Transition(this, source, target, value); transitions.Add(transition); return(transition); }
public ITransitionValue Union(ITransitionValue other) { throw new NotImplementedException(); }
public bool Intersecting(ITransitionValue other) { throw new NotImplementedException(); }
public bool Equals(ITransitionValue other) { return(other is CharRange otherRange && Lower == otherRange.Lower && Upper == otherRange.Upper); }
public bool Adjactent(ITransitionValue other) { throw new NotImplementedException(); }
public bool AdjacentOrIntersecting(ITransitionValue other) => Adjactent(other) || Intersecting(other);
public bool Adjactent(ITransitionValue other) => Equals(other);
public bool AdjacentOrIntersecting(ITransitionValue other) => Equals(other);
public ITransitionValue Union(ITransitionValue other) => other is EmptyChar ? this : null;
public bool Intersecting(ITransitionValue other) => Equals(other);
public bool Equals(ITransitionValue other) => other is EmptyChar;
public bool Equals(ITransitionValue other) => other is SingleChar otherChar && Value == otherChar.Value;