예제 #1
0
 public CompoundState(AbstractState s1, AbstractState s2, int count)
 {
     S1 = s1;
     S2 = s2;
     Marking = (s1.Marking == s2.Marking) ? s1.Marking : Marking.Unmarked;
     _hashcode = s1.GetHashCode()*count + s2.GetHashCode();
 }
예제 #2
0
 public CompoundState(AbstractState s1, AbstractState s2, Marking marking)
 {
     S1 = s1;
     S2 = s2;
     Marking = marking;
     _hashcode = s1.GetHashCode() ^ s2.GetHashCode();
 }
예제 #3
0
        public CompoundExpandedState(AbstractState s1, AbstractState s2, int count)
            : base(s1, s2, count)
        {
            var i = s1 is ExpandedState
                ? ((ExpandedState)s1).Tasks
                : s1 is CompoundExpandedState ? ((CompoundExpandedState)s1).Tasks : 0;
            var j = s2 is ExpandedState
                ? ((ExpandedState)s2).Tasks
                : s2 is CompoundExpandedState ? ((CompoundExpandedState)s2).Tasks : 0;

            Tasks = i + j;
        }
예제 #4
0
        public CompoundExpandedState(AbstractState s1, AbstractState s2, Marking marking)
            : base(s1, s2, marking)
        {
            var i = s1 is ExpandedState
                ? ((ExpandedState)s1).Tasks
                : s1 is CompoundExpandedState ? ((CompoundExpandedState)s1).Tasks : 0;
            var j = s2 is ExpandedState
                ? ((ExpandedState)s2).Tasks
                : s2 is CompoundExpandedState ? ((CompoundExpandedState)s2).Tasks : 0;

            Tasks = i + j;
        }
예제 #5
0
 public override AbstractCompoundState MergeWith(AbstractState s2, int count = 0, bool allMarked = true)
 {
     return ((IsMarked || s2.IsMarked) && !allMarked)
         ? (AbstractCompoundState)(new CompoundState(this, s2, count)).ToMarked
         : (new CompoundState(this, s2, count));
 }
예제 #6
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Constructor. </summary>
 /// <remarks>   Lucas Alves, 05/01/2016. </remarks>
 /// <param name="origin">       The origin. </param>
 /// <param name="trigger">      The trigger. </param>
 /// <param name="destination">  The destination. </param>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public Transition(AbstractState origin, AbstractEvent trigger, AbstractState destination)
 {
     Origin      = origin;
     Destination = destination;
     Trigger     = trigger;
 }
예제 #7
0
 public override AbstractCompoundState MergeWith(AbstractState s2, int count, bool allMarked)
 {
     return ((IsMarked || s2.IsMarked) && !allMarked)
         ? (AbstractCompoundState)new CompoundExpandedState(this, s2, count).ToMarked
         : new CompoundExpandedState(this, s2, count);
 }
예제 #8
0
파일: State.cs 프로젝트: lacsed/UltraDES
 /// <summary>
 /// Merges the with.
 /// </summary>
 /// <param name="s2">The s2.</param>
 /// <param name="allMarked">if set to <c>true</c> [all marked].</param>
 /// <returns>AbstractCompoundState.</returns>
 //public override AbstractCompoundState MergeWith(AbstractState s2, bool allMarked) => new CompoundState(new[] { this, s2 }, allMarked);
 public override AbstractCompoundState MergeWith(AbstractState s2, bool allMarked) => new CompoundState(S.Concat(s2.S).ToArray(), allMarked);
예제 #9
0
 public abstract AbstractCompoundState MergeWith(AbstractState s2, int count = 0, bool allMarked = true);
예제 #10
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>   Merge with. </summary>
 /// <remarks>   Lucas Alves, 05/01/2016. </remarks>
 /// <param name="s2">           The second AbstractState. </param>
 /// <param name="allMarked">    true if all marked. </param>
 /// <returns>   A CompoundState. </returns>
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 public abstract AbstractCompoundState MergeWith(AbstractState s2, bool allMarked = true);
예제 #11
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Merge with. </summary>
        ///
        /// <remarks>   Lucas Alves, 11/01/2016. </remarks>
        ///
        /// <param name="s2">           The second AbstractState. </param>
        /// <param name="allMarked">    true if all marked. </param>
        ///
        /// <returns>   A CompoundState. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        public override AbstractCompoundState MergeWith(AbstractState s2, bool allMarked)
        {
            return(new CompoundState(new[] { this, s2 }, allMarked));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="NondeterministicFiniteAutomaton"/> class.
 /// </summary>
 /// <param name="transitions">The transitions.</param>
 /// <param name="initial">The initial.</param>
 /// <param name="name">The name.</param>
 public NondeterministicFiniteAutomaton(IEnumerable <Transition> transitions, AbstractState initial, string name)
 {
     Transitions  = transitions;
     InitialState = initial;
     Name         = name;
 }
예제 #13
0
        /// <summary>
        /// Merges the with.
        /// </summary>
        /// <param name="s2">The s2.</param>
        /// <param name="allMarked">if set to <c>true</c> [all marked].</param>
        /// <returns>AbstractCompoundState.</returns>
        public override AbstractCompoundState MergeWith(AbstractState s2, bool allMarked = true)
        {
            var marked = allMarked ? IsMarked && s2.IsMarked : IsMarked || s2.IsMarked;

            return(new CompoundState(S.Concat(s2.S).ToArray(), marked ? Marking.Marked : Marking.Unmarked));
        }
예제 #14
0
 public Transition(AbstractState origin, AbstractEvent trigger, AbstractState destination)
 {
     Origin = origin;
     Destination = destination;
     Trigger = trigger;
 }
예제 #15
0
        private static IEnumerable<AbstractEvent> MaxParallelPath(DeterministicFiniteAutomaton g, int depth,
            AbstractState target)
        {
            var transitions = g.Transitions.AsParallel().GroupBy(t => t.Origin).ToDictionary(gr => gr.Key, gr => gr.ToArray());

            var distance = new ConcurrentDictionary<AbstractState, Tuple<uint, ImmutableList<AbstractEvent>>>();
            distance.TryAdd(g.InitialState, Tuple.Create(0u, ImmutableList<AbstractEvent>.Empty));

            for (var i = 0; i < depth; i++)
            {
                var nextDistance = new ConcurrentDictionary<AbstractState, Tuple<uint, ImmutableList<AbstractEvent>>>();

                if (distance.Count < 100)
                {
                    foreach (var kvp in distance)
                    {
                        var s1 = kvp.Key;
                        var d = kvp.Value;

                        foreach (var t in transitions[s1])
                        {
                            var s2 = t.Destination;
                            var e = t.Trigger;

                            var w = d.Item1;
                            if (s2 is ExpandedState) w += ((ExpandedState)s2).Tasks;
                            else if (s2 is CompoundExpandedState) w += ((CompoundExpandedState)s2).Tasks;

                            var lst = d.Item2.Add(e);

                            nextDistance.AddOrUpdate(s2, Tuple.Create(w, lst),
                                (key, old) => w > old.Item1 ? Tuple.Create(w, lst) : old);
                        }
                    }
                }
                else
                {

                    Parallel.ForEach(distance, kvp =>
                    {
                        var s1 = kvp.Key;
                        var d = kvp.Value;

                        //Parallel.ForEach(transitions[s1], t =>
                        foreach (var t in transitions[s1])
                        {
                            var s2 = t.Destination;
                            var e = t.Trigger;

                            var w = d.Item1;
                            if (s2 is ExpandedState) w += ((ExpandedState)s2).Tasks;
                            else if (s2 is CompoundExpandedState) w += ((CompoundExpandedState)s2).Tasks;

                            var lst = d.Item2.Add(e);

                            nextDistance.AddOrUpdate(s2, Tuple.Create(w, lst),
                                (key, old) => w > old.Item1 ? Tuple.Create(w, lst) : old);
                        } //);
                    });
                }

                distance = nextDistance;
            }

            return !distance.ContainsKey(target) ? ImmutableList<AbstractEvent>.Empty : distance[target].Item2;
        }
예제 #16
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Merge with. </summary>
        /// <remarks>   Lucas Alves, 05/01/2016. </remarks>
        /// <param name="s2">           The second AbstractState. </param>
        /// <param name="allMarked">    true if all marked. </param>
        /// <returns>   A CompoundState. </returns>
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public override AbstractCompoundState MergeWith(AbstractState s2, bool allMarked = true)
        {
            var marked = allMarked ? IsMarked && s2.IsMarked : IsMarked || s2.IsMarked;

            return(new CompoundState(new[] { this, s2 }, marked ? Marking.Marked : Marking.Unmarked));
        }