Ejemplo n.º 1
0
 /// <summary>
 ///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
 ///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
 ///   actually new.
 /// </summary>
 /// <param name="context">The context of the model traversal.</param>
 /// <param name="worker">The worker that found the transition.</param>
 /// <param name="sourceState">The index of the transition's source state.</param>
 /// <param name="transitions">The new transitions that should be processed.</param>
 /// <param name="transitionCount">The actual number of valid transitions.</param>
 /// <param name="areInitialTransitions">
 ///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
 /// </param>
 public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState,
                                TransitionCollection transitions, int transitionCount, bool areInitialTransitions)
 {
     // Note, other threads might access _markovChain at the same time
     CheckIfTransitionsCanBeProcessed(transitionCount);
     AddTransitions(sourceState, areInitialTransitions, transitions);
 }
Ejemplo n.º 2
0
 public override TraversalBranch Next(PathExpander expander, TraversalContext context)
 {
     if (_relationships == null)
     {
         ExpandRelationships(expander);
     }
     while (_relationships.MoveNext())
     {
         Relationship relationship = _relationships.Current;
         if (relationship.Equals(_howIGotHere))
         {
             context.UnnecessaryRelationshipTraversed();
             continue;
         }
         _expandedCount++;
         Node node = relationship.GetOtherNode(_source);
         // TODO maybe an unnecessary instantiation. Instead pass in this+node+relationship to uniqueness check
         TraversalBranch next = NewNextBranch(node, relationship);
         if (context.IsUnique(next))
         {
             context.RelationshipTraversed();
             next.Initialize(expander, context);
             return(next);
         }
         else
         {
             context.UnnecessaryRelationshipTraversed();
         }
     }
     ResetRelationships();
     return(null);
 }
Ejemplo n.º 3
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="createModel">Creates the model that should be checked.</param>
		/// <param name="output">The callback that should be used to output messages.</param>
		/// <param name="configuration">The analysis configuration that should be used.</param>
		internal ModelTraverser(Func<AnalysisModel> createModel, Action<string> output, AnalysisConfiguration configuration)
		{
			Requires.NotNull(createModel, nameof(createModel));
			Requires.NotNull(output, nameof(output));
			TransitionCollection.ValidateTransitionSizes();

			var tasks = new Task[configuration.CpuCount];
			var stacks = new StateStack[configuration.CpuCount];

			_loadBalancer = new LoadBalancer(stacks);
			Context = new TraversalContext(_loadBalancer, configuration, output);
			_workers = new Worker[configuration.CpuCount];

			for (var i = 0; i < configuration.CpuCount; ++i)
			{
				var index = i;
				tasks[i] = Task.Factory.StartNew(() =>
				{
					stacks[index] = new StateStack(configuration.StackCapacity);
					_workers[index] = new Worker(index, Context, stacks[index], createModel());
				});
			}

			Task.WaitAll(tasks);

			_states = new StateStorage(_workers[0].Model.StateVectorSize, configuration.StateCapacity);
			Context.States = _states;
		}
Ejemplo n.º 4
0
 internal AsOneStartBranch(TraversalContext context, IEnumerable <Node> nodes, InitialBranchState initialState, UniquenessFactory uniqueness)
 {
     this._context      = context;
     this._initialState = initialState;
     this._uniqueness   = uniqueness;
     this._branches     = ToBranches(nodes);
 }
Ejemplo n.º 5
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch result = null;

            while (result == null)
            {
                if (_current == null)
                {
                    _current = _superNodes.RemoveFirst();
                    if (_current == null)
                    {
                        return(null);
                    }
                }
                else if (_current.expanded() > 0 && _current.expanded() % _threshold == 0)
                {
                    _superNodes.AddLast(_current);
                    _current = _current.parent();
                    continue;
                }

                TraversalBranch next = _current.next(_expander, metadata);
                if (next == null)
                {
                    _current = _current.parent();
                    continue;
                }
                _current = next;
                result   = _current;
            }
            return(result);
        }
Ejemplo n.º 6
0
 /// <summary>
 ///   Embed evaluated once formulas into the state as observers.
 /// </summary>
 /// <param name="context">The context of the model traversal.</param>
 /// <param name="worker">The worker that found the transition.</param>
 /// <param name="transitions">The transitions that should be checked.</param>
 /// <param name="sourceState">The source state of the transitions.</param>
 /// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
 /// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
 public void ModifyTransitions(TraversalContext context, Worker worker, TransitionCollection transitions, byte *sourceState,
                               int sourceStateIndex, bool isInitial)
 {
     foreach (CandidateTransition *transition in transitions)
     {
         ConvertTransition(transition);
     }
 }
Ejemplo n.º 7
0
 public override void PostProcess(TraversalContext context)
 {
     if (context.TranslucencyGrantor == this && !sPreviousFlagValue)
     {
         context.TranslucencyGrantor    = null;
         context.ExternalMaterialFlags &= ~TraversalContext.MaterialFlags.Translucent;
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 ///   Optionally modifies the <paramref name="transitions" />, changing any of their values. However, no new transitions can be
 ///   added; transitions can be removed by setting their <see cref="CandidateTransition.IsValid" /> flag to <c>false</c>.
 ///   During subsequent traversal steps, only valid transitions and target states reached by at least one valid transition
 ///   are considered.
 /// </summary>
 /// <param name="context">The context of the model traversal.</param>
 /// <param name="worker">The worker that found the transition.</param>
 /// <param name="transitions">The transitions that should be checked.</param>
 /// <param name="sourceState">The source state of the transitions.</param>
 /// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
 /// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
 public void ModifyTransitions(TraversalContext <TExecutableModel> context, Worker <TExecutableModel> worker, TransitionCollection transitions, byte *sourceState,
                               int sourceStateIndex, bool isInitial)
 {
     foreach (CandidateTransition *transition in transitions)
     {
         transition->Flags = TransitionFlags.SetIsValidIffCondition(transition->Flags, transition->ActivatedFaults.GetIntersection(_suppressedFaults).IsEmpty);
     }
 }
Ejemplo n.º 9
0
 public override void PostProcess(TraversalContext context)
 {
     if (context.TranslucencyGrantor == this && !sPreviousFlagValue)
     {
         context.TranslucencyGrantor = null;
         context.ExternalMaterialFlags &= ~TraversalContext.MaterialFlags.Translucent;
     }
 }
        /// <summary>
        ///   Optionally modifies the <paramref name="transitions" />, changing any of their values. However, no new transitions can be
        ///   added; transitions can be removed by setting their <see cref="CandidateTransition.IsValid" /> flag to <c>false</c>.
        ///   During subsequent traversal steps, only valid transitions and target states reached by at least one valid transition
        ///   are considered.
        /// </summary>
        /// <param name="context">The context of the model traversal.</param>
        /// <param name="worker">The worker that found the transition.</param>
        /// <param name="transitions">The transitions that should be checked.</param>
        /// <param name="sourceState">The source state of the transitions.</param>
        /// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
        /// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
        public void ModifyTransitions(TraversalContext context, Worker worker, TransitionCollection transitions, byte *sourceState, int sourceStateIndex, bool isInitial)
        {
            _transitions = transitions;
            _useHash     = transitions.Count >= UseHashLimit;

            CreateSortedTransitionIndexes();
            IterateThroughAllTransitionsInSortedOrder();
        }
Ejemplo n.º 11
0
 public override void Process(TraversalContext context)
 {
     if (context.TranslucencyGrantor == null)
     {
         sPreviousFlagValue = (context.ExternalMaterialFlags & TraversalContext.MaterialFlags.Translucent) > 0;
         context.TranslucencyGrantor = this;
         context.ExternalMaterialFlags |= TraversalContext.MaterialFlags.Translucent;
     }
 }
		/// <summary>
		///   Processes the new <paramref name="transition" /> discovered by the <paramref name="worker " /> within the traversal
		///   <paramref name="context" />.
		/// </summary>
		/// <param name="context">The context of the model traversal.</param>
		/// <param name="worker">The worker that found the transition.</param>
		/// <param name="transition">The new transition that should be processed.</param>
		/// <param name="isInitialTransition">
		///   Indicates whether the transition is an initial transition not starting in any valid source state.
		/// </param>
		public unsafe void ProcessTransition(TraversalContext context, Worker worker, Transition* transition, bool isInitialTransition)
		{
			if (transition->Formulas[_formulaIndex])
				return;

			context.FormulaIsValid = false;
			context.LoadBalancer.Terminate();
			worker.CreateCounterExample(endsWithException: false, addAdditionalState: false);
		}
        public override TraversalBranch Next(TraversalContext metadata)
        {
            if (_sourceIterator == null)
            {
                _sourceIterator = GatherSourceIterator(metadata);
            }
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            return(_sourceIterator.hasNext() ? _sourceIterator.next() : null);
        }
Ejemplo n.º 14
0
 public override void Process(TraversalContext context)
 {
     if (context.TranslucencyGrantor == null)
     {
         sPreviousFlagValue             = (context.ExternalMaterialFlags & TraversalContext.MaterialFlags.Translucent) > 0;
         context.TranslucencyGrantor    = this;
         context.ExternalMaterialFlags |= TraversalContext.MaterialFlags.Translucent;
     }
 }
Ejemplo n.º 15
0
 /// <summary>
 ///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
 ///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
 ///   actually new.
 /// </summary>
 /// <param name="context">The context of the model traversal.</param>
 /// <param name="worker">The worker that found the transition.</param>
 /// <param name="sourceState">The index of the transition's source state.</param>
 /// <param name="transitions">The new transitions that should be processed.</param>
 /// <param name="transitionCount">The actual number of valid transitions.</param>
 /// <param name="areInitialTransitions">
 ///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
 /// </param>
 public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState, TransitionCollection transitions,
                                int transitionCount, bool areInitialTransitions)
 {
     if (transitionCount == 0)
     {
         throw new InvalidOperationException(
                   "Deadlock state detected, i.e., there are no outgoing transitions for " +
                   "the last state in the generated counter example. Try relaxing state constraints.");
     }
 }
Ejemplo n.º 16
0
		/// <summary>
		///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
		///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
		///   actually new.
		/// </summary>
		/// <param name="context">The context of the model traversal.</param>
		/// <param name="worker">The worker that found the transition.</param>
		/// <param name="sourceState">The index of the transition's source state.</param>
		/// <param name="transitions">The new transitions that should be processed.</param>
		/// <param name="transitionCount">The actual number of valid transitions.</param>
		/// <param name="areInitialTransitions">
		///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
		/// </param>
		public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState, TransitionCollection transitions,
									   int transitionCount, bool areInitialTransitions)
		{
			if (transitionCount == 0)
			{
				throw new InvalidOperationException(
					"Deadlock state detected, i.e., there are no outgoing transitions for " +
					"the last state in the generated counter example. Try relaxing state constraints.");
			}
		}
Ejemplo n.º 17
0
        /// <summary>
        ///   Embed evaluated once formulas into the state as observers.
        /// </summary>
        /// <param name="context">The context of the model traversal.</param>
        /// <param name="worker">The worker that found the transition.</param>
        /// <param name="transitions">The transitions that should be checked.</param>
        /// <param name="sourceState">The source state of the transitions.</param>
        /// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
        /// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
        public void ModifyTransitions(TraversalContext context, Worker worker, TransitionCollection transitions, byte *sourceState,
                                      int sourceStateIndex, bool isInitial)
        {
            var currentEnrichment = isInitial ? 0 : *(int *)(sourceState + ExtraBytesOffset);

            foreach (CandidateTransition *transition in transitions)
            {
                ConvertTransition(currentEnrichment, transition);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        ///   Processes the new <paramref name="transition" /> discovered by the <paramref name="worker " /> within the traversal
        ///   <paramref name="context" />.
        /// </summary>
        /// <param name="context">The context of the model traversal.</param>
        /// <param name="worker">The worker that found the transition.</param>
        /// <param name="transition">The new transition that should be processed.</param>
        /// <param name="isInitialTransition">
        ///   Indicates whether the transition is an initial transition not starting in any valid source state.
        /// </param>
        public unsafe void ProcessTransition(TraversalContext context, Worker worker, Transition *transition, bool isInitialTransition)
        {
            if (_evaluator(transition->Formulas))
            {
                return;
            }

            context.FormulaIsValid = false;
            context.LoadBalancer.Terminate();
            worker.CreateCounterExample(endsWithException: false, addAdditionalState: false);
        }
Ejemplo n.º 19
0
        public override TraversalBranch Next(PathExpander expander, TraversalContext metadata)
        {
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
            if (_branches.hasNext())
            {
                _expanded++;
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                return(_branches.next().next(expander, metadata));
            }
            return(null);
        }
Ejemplo n.º 20
0
            public override TraversalBranch Next(TraversalContext metadata)
            {
                // Exhaust current if not already exhausted
                while (true)
                {
                    TraversalBranch next = Current.next(Expander, metadata);
                    if (next == null)
                    {
                        break;
                    }

                    long      endNodeId = next.EndNode().Id;
                    Visit <P> stay      = Visits[endNodeId];

                    D cost        = outerInstance.CalculateValue(next);
                    P newPriority = outerInstance.AddPriority(next, CurrentAggregatedValue, cost);

                    bool newStay = stay == null;
                    if (newStay)
                    {
                        stay = new Visit <P>(newPriority);
                        Visits[endNodeId] = stay;
                    }
                    if (newStay || !outerInstance.interest.CanBeRuledOut(stay.VisitCount, newPriority, stay.Cost))
                    {
                        if (outerInstance.interest.Comparator().Compare(newPriority, stay.Cost) < 0)
                        {
                            stay.Cost = newPriority;
                        }
                        Queue.put(next, newPriority);
                    }
                }

                do
                {
                    // Pop the top from priorityMap
                    Entry <TraversalBranch, P> entry = Queue.pop();
                    if (entry != null)
                    {
                        Current = entry.Entity;
                        Visit <P> stay = Visits[Current.endNode().Id];
                        stay.VisitCount++;
                        if (outerInstance.interest.StillInteresting(stay.VisitCount))
                        {
                            CurrentAggregatedValue = entry.Priority;
                            return(Current);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                } while (true);
            }
Ejemplo n.º 21
0
        /// <summary>
        ///   Processes the new <paramref name="transition" /> discovered by the <paramref name="worker " /> within the traversal
        ///   <paramref name="context" />.
        /// </summary>
        /// <param name="context">The context of the model traversal.</param>
        /// <param name="worker">The worker that found the transition.</param>
        /// <param name="transition">The new transition that should be processed.</param>
        /// <param name="isInitialTransition">
        ///   Indicates whether the transition is an initial transition not starting in any valid source state.
        /// </param>
        public unsafe void ProcessTransition(TraversalContext <TExecutableModel> context, Worker <TExecutableModel> worker, Transition *transition, bool isInitialTransition)
        {
            if (transition->Formulas[_formulaIndex])
            {
                return;
            }

            context.FormulaIsValid = false;
            context.LoadBalancer.Terminate();
            worker.CreateCounterExample(endsWithException: false, addAdditionalState: false);
        }
            /// <summary>
            ///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
            ///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
            ///   actually new.
            /// </summary>
            /// <param name="context">The context of the model traversal.</param>
            /// <param name="worker">The worker that found the transition.</param>
            /// <param name="sourceState">The index of the transition's source state.</param>
            /// <param name="transitions">The new transitions that should be processed.</param>
            /// <param name="transitionCount">The actual number of valid transitions.</param>
            /// <param name="areInitialTransitions">
            ///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
            /// </param>
            public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState,
                                           TransitionCollection transitions, int transitionCount, bool areInitialTransitions)
            {
                // Note, other threads might access _ltmdp at the same time
                CheckIfTransitionsCanBeProcessed(transitionCount);

                AddTransitions(transitions);
                var stepgraph = (LtmdpStepGraph)transitions.StructuralInformation;

                CheckIfStepGraphCanBeProcessed(stepgraph);
                AddStepGraph(stepgraph, sourceState, areInitialTransitions);
            }
Ejemplo n.º 23
0
            /// <summary>
            ///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
            ///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
            ///   actually new.
            /// </summary>
            /// <param name="context">The context of the model traversal.</param>
            /// <param name="worker">The worker that found the transition.</param>
            /// <param name="sourceState">The index of the transition's source state.</param>
            /// <param name="transitions">The new transitions that should be processed.</param>
            /// <param name="transitionCount">The actual number of valid transitions.</param>
            /// <param name="areInitialTransitions">
            ///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
            /// </param>
            public void ProcessTransitions(TraversalContext <TExecutableModel> context, Worker <TExecutableModel> worker, int sourceState,
                                           TransitionCollection transitions, int transitionCount, bool areInitialTransitions)
            {
                // Note, other threads might access _markovChain at the same time
                CheckIfTransitionsCanBeProcessed(transitionCount);
                foreach (var transition in transitions)
                {
                    var probTransition = (LtmcTransition *)transition;

                    CheckIfTransitionIsValid(probTransition);

                    AddTransitionToTransitionChain(sourceState, areInitialTransitions, probTransition);
                }
            }
Ejemplo n.º 24
0
		/// <summary>
		///   Optionally modifies the <paramref name="transitions" />, changing any of their values. However, no new transitions can be
		///   added; transitions can be removed by setting their <see cref="CandidateTransition.IsValid" /> flag to <c>false</c>.
		///   During subsequent traversal steps, only valid transitions and target states reached by at least one valid transition
		///   are considered.
		/// </summary>
		/// <param name="context">The context of the model traversal.</param>
		/// <param name="transitions">The transitions that should be checked.</param>
		/// <param name="sourceState">The source state of the transitions.</param>
		/// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
		/// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
		public void ModifyTransitions(TraversalContext context, TransitionCollection transitions, byte* sourceState,
									  int sourceStateIndex, bool isInitial)
		{
			// The fault order state is encoded into the first four bytes of the state vector (must be four bytes as required by 
			// RuntimeModel's state header field)
			var state = isInitial ? State.NeitherFaultActivated : *(State*)sourceState;

			foreach (CandidateTransition* transition in transitions)
			{
				var activatedFaults = transition->ActivatedFaults;
				var isValid = true;
				var nextState = state;

				switch (state)
				{
					case State.NeitherFaultActivated:
						if (activatedFaults.Contains(_firstFault) && activatedFaults.Contains(_secondFault))
						{
							if (_forceSimultaneous)
								nextState = State.BothFaultsActivated;
							else
								isValid = false;
						}
						else if (activatedFaults.Contains(_firstFault))
						{
							if (_forceSimultaneous)
								isValid = false;
							else
								nextState = State.FirstFaultActivated;
						}
						else if (activatedFaults.Contains(_secondFault))
							isValid = false;
						break;
					case State.FirstFaultActivated:
						if (activatedFaults.Contains(_secondFault))
							nextState = State.BothFaultsActivated;
						break;
					case State.BothFaultsActivated:
						break;
					default:
						Assert.NotReached("Unexpected state value.");
						break;
				}

				transition->IsValid = isValid;
				*(State*)transition->TargetState = nextState;
			}
		}
        private IEnumerator <TraversalBranch> GatherSourceIterator(TraversalContext metadata)
        {
            LinkedList <TraversalBranch> queue = new LinkedList <TraversalBranch>();

            queue.AddLast(_current.next(_expander, metadata));
            while (true)
            {
                IList <TraversalBranch> level = GatherOneLevel(queue, metadata);
                if (level.Count == 0)
                {
                    break;
                }
                queue.addAll(0, level);
            }
            return(queue.GetEnumerator());
        }
Ejemplo n.º 26
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch branch        = NextBranchFromCurrentSelector(metadata, false);
            Entry           state         = StateForCurrentSelector;
            AtomicInteger   previousDepth = state.Depth;

            if (branch != null && branch.Length() == previousDepth.get())
            {               // Same depth as previous branch returned from this side.
                return(branch);
            }

            if (branch != null)
            {
                _totalDepth.set(CurrentSide(), branch.Length());
            }
            if ((_stopDescentOnResult && (metadata.NumberOfPathsReturned > 0)) || (_totalDepth.get() > (_maxDepth + 1)))
            {
                NextSelector();
                return(null);
            }

            if (branch != null)
            {
                previousDepth.set(branch.Length());
                state.Branch = branch;
            }
            BranchSelector  otherSelector = NextSelector();
            Entry           otherState    = StateForCurrentSelector;
            TraversalBranch otherBranch   = otherState.Branch;

            if (otherBranch != null)
            {
                otherState.Branch = null;
                return(otherBranch);
            }

            otherBranch = otherSelector.Next(metadata);
            if (otherBranch != null)
            {
                return(otherBranch);
            }
            else
            {
                return(branch);
            }
        }
Ejemplo n.º 27
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch branch        = NextBranchFromNextSelector(metadata, true);
            int?            previousDepth = StateForCurrentSelector;

            if (branch != null && branch.Length() == previousDepth.Value)
            {
                return(branch);
            }
            else
            {
                if (branch != null)
                {
                    StateForCurrentSelector = branch.Length();
                }
            }
            return(branch);
        }
Ejemplo n.º 28
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="context">The context of the traversal process.</param>
        /// <param name="transitionSizeInBytes">The size of a transition in bytes.</param>
        /// <param name="model">The runtime model the state graph is generated for.</param>
        /// <param name="createModel">
        ///   The factory function that should be used to create instances of the <see cref="RuntimeModel" />
        ///   the state graph is generated for.
        /// </param>
        internal StateGraph(TraversalContext context, int transitionSizeInBytes,
                            TExecutableModel model, CoupledExecutableModelCreator <TExecutableModel> createModel)
        {
            Requires.NotNull(context, nameof(context));

            TransitionSize      = transitionSizeInBytes;
            RuntimeModel        = model;
            RuntimeModelCreator = createModel;

            _stateStorage       = context.States;
            _transitionCapacity = context.ModelCapacity.MemoryLimitTransitions.Value;

            _transitionsBuffer.Resize(_transitionCapacity, zeroMemory: false);
            _stateMapBuffer.Resize(context.ModelCapacity.NumberOfStates * sizeof(TransitionRange), zeroMemory: false);

            _transitions = _transitionsBuffer.Pointer;
            _stateMap    = (TransitionRange *)_stateMapBuffer.Pointer;
        }
Ejemplo n.º 29
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="context">The context of the traversal process.</param>
		/// <param name="stateFormulas">The state formulas that can be evaluated over the generated state graph.</param>
		/// <param name="transitionSizeInBytes">The size of a transition in bytes.</param>
		/// <param name="model">The runtime model the state graph is generated for.</param>
		/// <param name="createModel">
		///   The factory function that should be used to create instances of the <see cref="RuntimeModel" />
		///   the state graph is generated for.
		/// </param>
		internal StateGraph(TraversalContext context, Formula[] stateFormulas, int transitionSizeInBytes,
							RuntimeModel model, Func<RuntimeModel> createModel)
		{
			Requires.NotNull(context, nameof(context));

			StateFormulas = stateFormulas;
			TransitionSize = transitionSizeInBytes;
			RuntimeModel = model;
			RuntimeModelCreator = createModel;

			_stateStorage = context.States;
			_transitionCapacity = context.Configuration.TransitionCapacity;

			_transitionsBuffer.Resize(TransitionSize * _transitionCapacity, zeroMemory: false);
			_stateMapBuffer.Resize(context.Configuration.StateCapacity * sizeof(TransitionRange), zeroMemory: false);

			_transitions = _transitionsBuffer.Pointer;
			_stateMap = (TransitionRange*)_stateMapBuffer.Pointer;
		}
Ejemplo n.º 30
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch result = null;

            while (result == null)
            {
                if (_current == null)
                {
                    return(null);
                }
                TraversalBranch next = _current.next(_expander, metadata);
                if (next == null)
                {
                    _current = _current.parent();
                    continue;
                }
                _current = next;
                result   = _current;
            }
            return(result);
        }
Ejemplo n.º 31
0
        public override TraversalBranch Next(TraversalContext metadata)
        {
            TraversalBranch result = null;

            while (result == null)
            {
                TraversalBranch next = _current.next(_expander, metadata);
                if (next != null)
                {
                    _queue.AddLast(next);
                    result = next;
                }
                else
                {
                    _current = _queue.RemoveFirst();
                    if (_current == null)
                    {
                        return(null);
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 32
0
        /// <summary>
        ///   Optionally modifies the <paramref name="transitions" />, changing any of their values. However, no new transitions can be
        ///   added; transitions can be removed by setting their <see cref="CandidateTransition.IsValid" /> flag to <c>false</c>.
        ///   During subsequent traversal steps, only valid transitions and target states reached by at least one valid transition
        ///   are considered.
        /// </summary>
        /// <param name="context">The context of the model traversal.</param>
        /// <param name="worker">The worker that found the transition.</param>
        /// <param name="transitions">The transitions that should be checked.</param>
        /// <param name="sourceState">The source state of the transitions.</param>
        /// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
        /// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
        public void ModifyTransitions(TraversalContext <TExecutableModel> context, Worker <TExecutableModel> worker, TransitionCollection transitions, byte *sourceState,
                                      int sourceStateIndex, bool isInitial)
        {
            // The fault order state is encoded into the first four bytes of the state vector (must be four bytes as required by
            // RuntimeModel's state header field)
            var state = isInitial ? State.NeitherFaultActivated : *(State *)sourceState;

            foreach (CandidateTransition *transition in transitions)
            {
                var activatedFaults = transition->ActivatedFaults;
                var isValid         = true;
                var nextState       = state;

                switch (state)
                {
                case State.NeitherFaultActivated:
                    if (activatedFaults.Contains(_firstFault) && activatedFaults.Contains(_secondFault))
                    {
                        if (_forceSimultaneous)
                        {
                            nextState = State.BothFaultsActivated;
                        }
                        else
                        {
                            isValid = false;
                        }
                    }
                    else if (activatedFaults.Contains(_firstFault))
                    {
                        if (_forceSimultaneous)
                        {
                            isValid = false;
                        }
                        else
                        {
                            nextState = State.FirstFaultActivated;
                        }
                    }
                    else if (activatedFaults.Contains(_secondFault))
                    {
                        isValid = false;
                    }
                    break;

                case State.FirstFaultActivated:
                    if (activatedFaults.Contains(_secondFault))
                    {
                        nextState = State.BothFaultsActivated;
                    }
                    break;

                case State.BothFaultsActivated:
                    break;

                default:
                    Assert.NotReached("Unexpected state value.");
                    break;
                }

                transition->Flags = TransitionFlags.SetIsValidIffCondition(transition->Flags, isValid);
                *(State *)transition->TargetStatePointer = nextState;
            }
        }
Ejemplo n.º 33
0
 protected internal virtual void Evaluate(TraversalContext context)
 {
     Evaluation = context.Evaluate(this, null);
 }
Ejemplo n.º 34
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected:
//ORIGINAL LINE: public void initialize(final org.neo4j.graphdb.PathExpander expander, org.neo4j.graphdb.traversal.TraversalContext metadata)
        public override void Initialize(PathExpander expander, TraversalContext metadata)
        {
            Evaluate(metadata);
        }
Ejemplo n.º 35
0
		/// <summary>
		///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
		///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
		///   actually new.
		/// </summary>
		/// <param name="context">The context of the model traversal.</param>
		/// <param name="worker">The worker that found the transition.</param>
		/// <param name="sourceState">The index of the transition's source state.</param>
		/// <param name="transitions">The new transitions that should be processed.</param>
		/// <param name="transitionCount">The actual number of valid transitions.</param>
		/// <param name="areInitialTransitions">
		///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
		/// </param>
		public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState,
									   TransitionCollection transitions, int transitionCount, bool areInitialTransitions)
		{
			_stateGraph.AddStateInfo(sourceState, areInitialTransitions, transitions, transitionCount);
		}
		/// <summary>
		///   Optionally modifies the <paramref name="transitions" />, changing any of their values. However, no new transitions can be
		///   added; transitions can be removed by setting their <see cref="CandidateTransition.IsValid" /> flag to <c>false</c>.
		///   During subsequent traversal steps, only valid transitions and target states reached by at least one valid transition
		///   are considered.
		/// </summary>
		/// <param name="context">The context of the model traversal.</param>
		/// <param name="transitions">The transitions that should be checked.</param>
		/// <param name="sourceState">The source state of the transitions.</param>
		/// <param name="sourceStateIndex">The unique index of the transition's source state.</param>
		/// <param name="isInitial">Indicates whether the transitions are initial transitions not starting in any valid source state.</param>
		public void ModifyTransitions(TraversalContext context, TransitionCollection transitions, byte* sourceState,
									  int sourceStateIndex, bool isInitial)
		{
			foreach (CandidateTransition* transition in transitions)
				transition->IsValid = transition->ActivatedFaults.GetIntersection(_suppressedFaults).IsEmpty;
		}
 public TraversalBranch next(TraversalContext metadata)
 {
     throw new System.NotSupportedException();
 }
Ejemplo n.º 38
0
 /// <summary>
 ///   Processes the new <paramref name="transitions" /> discovered by the <paramref name="worker " /> within the traversal
 ///   <paramref name="context" />. Only transitions with <see cref="CandidateTransition.IsValid" /> set to <c>true</c> are
 ///   actually new.
 /// </summary>
 /// <param name="context">The context of the model traversal.</param>
 /// <param name="worker">The worker that found the transition.</param>
 /// <param name="sourceState">The index of the transition's source state.</param>
 /// <param name="transitions">The new transitions that should be processed.</param>
 /// <param name="transitionCount">The actual number of valid transitions.</param>
 /// <param name="areInitialTransitions">
 ///   Indicates whether the transitions are an initial transitions not starting in any valid source state.
 /// </param>
 public void ProcessTransitions(TraversalContext context, Worker worker, int sourceState,
                                TransitionCollection transitions, int transitionCount, bool areInitialTransitions)
 {
     _stateGraph.AddStateInfo(sourceState, areInitialTransitions, transitions, transitionCount);
 }
        private IList <TraversalBranch> GatherOneLevel(IList <TraversalBranch> queue, TraversalContext metadata)
        {
            IList <TraversalBranch> level = new LinkedList <TraversalBranch>();
            int?depth = null;

            foreach (TraversalBranch source in queue)
            {
                if (depth == null)
                {
                    depth = source.Length();
                }
                else if (source.Length() != depth.Value)
                {
                    break;
                }

                while (true)
                {
                    TraversalBranch next = source.Next(_expander, metadata);
                    if (next == null)
                    {
                        break;
                    }
                    level.Add(next);
                }
            }
            return(level);
        }