Exemplo n.º 1
0
 /// <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;
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public ITransitionValue Union(ITransitionValue other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
 public bool Intersecting(ITransitionValue other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public bool Equals(ITransitionValue other)
 {
     return(other is CharRange otherRange &&
            Lower == otherRange.Lower &&
            Upper == otherRange.Upper);
 }
Exemplo n.º 7
0
 public bool Adjactent(ITransitionValue other)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 8
0
 public bool AdjacentOrIntersecting(ITransitionValue other)
 => Adjactent(other) || Intersecting(other);
Exemplo n.º 9
0
 public bool Adjactent(ITransitionValue other)
 => Equals(other);
Exemplo n.º 10
0
 public bool AdjacentOrIntersecting(ITransitionValue other)
 => Equals(other);
Exemplo n.º 11
0
 public ITransitionValue Union(ITransitionValue other)
 => other is EmptyChar ? this : null;
Exemplo n.º 12
0
 public bool Intersecting(ITransitionValue other)
 => Equals(other);
Exemplo n.º 13
0
 public bool Equals(ITransitionValue other)
 => other is EmptyChar;
Exemplo n.º 14
0
 public bool Equals(ITransitionValue other) =>
 other is SingleChar otherChar && Value == otherChar.Value;