示例#1
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        ///   The number of bytes that should be reserved at the beginning of each state vector for the model checker tool.
        /// </param>
        internal LtmdpExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, AnalysisConfiguration configuration)
            : base(runtimeModelCreator, 0, configuration)
        {
            var formulas = RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray();

            _stepGraph = new LtmdpStepGraph();

            _cachedLabeledStates = new LtmdpCachedLabeledStates <TExecutableModel>(TemporaryStateStorage, configuration.SuccessorCapacity, _stepGraph, formulas);

            bool useForwardOptimization;

            switch (configuration.MomentOfIndependentFaultActivation)
            {
            case MomentOfIndependentFaultActivation.AtStepBeginning:
            case MomentOfIndependentFaultActivation.OnFirstMethodWithoutUndo:
                useForwardOptimization = false;
                break;

            case MomentOfIndependentFaultActivation.OnFirstMethodWithUndo:
                useForwardOptimization = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            _ltmdpChoiceResolver = new LtmdpChoiceResolver(_stepGraph, useForwardOptimization);
            ChoiceResolver       = _ltmdpChoiceResolver;
            RuntimeModel.SetChoiceResolver(ChoiceResolver);

            _allowFaultsOnInitialTransitions = configuration.AllowFaultsOnInitialTransitions;

            _activateIndependentFaultsAtStepBeginning =
                configuration.MomentOfIndependentFaultActivation == MomentOfIndependentFaultActivation.AtStepBeginning;
        }
            private void CheckIfStepGraphCanBeProcessed(LtmdpStepGraph stepGraph)
            {
                // Need to reserve the memory for the transitions
                var upperBoundaryForStepGraph = _ltmdp._continuationGraphElementCount + stepGraph.Size;

                if (upperBoundaryForStepGraph < 0 || upperBoundaryForStepGraph >= _ltmdp._maxNumberOfContinuationGraphElements)
                {
                    throw new OutOfMemoryException("Unable to store transitions. Try increasing the transition capacity.");
                }
            }
示例#3
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param>
        /// <param name="successorStateCapacity">The maximum number of successor states supported per state.</param>
        /// <param name="stateHeaderBytes">
        ///   The number of bytes that should be reserved at the beginning of each state vector for the model checker tool.
        /// </param>
        internal LtmdpExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, int stateHeaderBytes, long successorStateCapacity)
            : base(runtimeModelCreator, stateHeaderBytes)
        {
            var formulas = RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray();

            _stepGraph = new LtmdpStepGraph();

            _cachedLabeledStates = new LtmdpCachedLabeledStates <TExecutableModel>(RuntimeModel, successorStateCapacity, _stepGraph, formulas);

            _ltmdpChoiceResolver = new LtmdpChoiceResolver(_stepGraph);
            ChoiceResolver       = _ltmdpChoiceResolver;
            RuntimeModel.SetChoiceResolver(ChoiceResolver);
        }
            private void AddStepGraph(LtmdpStepGraph stepGraph, int sourceState, bool areInitialTransitions)
            {
                _stepGraphMapper.Clear();
                var place = _ltmdp.GetPlaceForNewContinuationGraphElements(1);

                if (areInitialTransitions)
                {
                    _ltmdp._indexOfInitialContinuationGraphRoot = place;
                }
                else
                {
                    _ltmdp.SourceStates.Add(sourceState);
                    _ltmdp._stateStorageStateToRootOfContinuationGraphMemory[sourceState] = place;
                }
                AddChoiceOfStepGraph(stepGraph, 0, place);
            }
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="temporalStateStorage">A storage where temporal states can be saved to.</param>
        /// <param name="capacity">The maximum number of successors that can be cached.</param>
        /// <param name="formulas">The formulas that should be checked for all successor states.</param>
        public LtmdpCachedLabeledStates(TemporaryStateStorage temporalStateStorage, long capacity, LtmdpStepGraph ltmdpStepGraph, params Func <bool>[] formulas)
        {
            Requires.NotNull(temporalStateStorage, nameof(temporalStateStorage));
            Requires.NotNull(formulas, nameof(formulas));
            Requires.That(formulas.Length < 32, "At most 32 formulas are supported.");
            Requires.That(capacity <= (1 << 30), nameof(capacity), $"Maximum supported capacity is {1 << 30}.");

            _temporalStateStorage = temporalStateStorage;
            _formulas             = formulas;
            _capacity             = capacity;

            LtmdpStepGraph = ltmdpStepGraph;

            _transitionsWithContinuationIdBuffer.Resize(capacity * sizeof(LtmdpTransition), zeroMemory: false);
            _transitionsWithContinuationIdMemory = (LtmdpTransition *)_transitionsWithContinuationIdBuffer.Pointer;
        }
            private void AddChoiceOfStepGraph(LtmdpStepGraph stepGraph, int continuationId, long locationForContinuationGraphElement)
            {
                BufferCidMapping(continuationId, locationForContinuationGraphElement);

                var choice = stepGraph.GetChoiceOfCid(continuationId);

                if (choice.IsChoiceTypeUnsplitOrFinal)
                {
                    AddFinalChoiceOfStepGraph(choice.To, locationForContinuationGraphElement, choice.Probability);
                    return;
                }
                if (choice.IsChoiceTypeForward)
                {
                    // no recursive descent here
                    var bufferedTargetCid = GetBufferedLtmdpCid(choice.To);
                    _ltmdp._continuationGraph[locationForContinuationGraphElement] =
                        new ContinuationGraphElement
                    {
                        ChoiceType  = choice.ChoiceType,
                        From        = bufferedTargetCid,
                        To          = bufferedTargetCid,
                        Probability = choice.Probability
                    };
                    return;
                }

                var offsetTo         = choice.To - choice.From;
                var numberOfChildren = offsetTo + 1;

                var placesForChildren = _ltmdp.GetPlaceForNewContinuationGraphElements(numberOfChildren);

                _ltmdp._continuationGraph[locationForContinuationGraphElement] =
                    new ContinuationGraphElement
                {
                    ChoiceType  = choice.ChoiceType,
                    From        = placesForChildren,
                    To          = placesForChildren + offsetTo,
                    Probability = choice.Probability
                };

                for (var currentChildNo = 0; currentChildNo < numberOfChildren; currentChildNo++)
                {
                    var originalContinuationId = choice.From + currentChildNo;
                    var newLocation            = placesForChildren + currentChildNo;
                    AddChoiceOfStepGraph(stepGraph, originalContinuationId, newLocation);
                }
            }
示例#7
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="runtimeModelCreator">A factory function that creates the model instance that should be executed.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        ///   The number of bytes that should be reserved at the beginning of each state vector for the model checker tool.
        /// </param>
        internal LtmdpExecutedModel(CoupledExecutableModelCreator <TExecutableModel> runtimeModelCreator, AnalysisConfiguration configuration)
            : base(runtimeModelCreator, 0, configuration)
        {
            var formulas = RuntimeModel.Formulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray();

            _stepGraph = new LtmdpStepGraph();

            _cachedLabeledStates = new LtmdpCachedLabeledStates <TExecutableModel>(TemporaryStateStorage, configuration.SuccessorCapacity, _stepGraph, formulas);

            var useForwardOptimization = configuration.EnableStaticPruningOptimization;

            _ltmdpChoiceResolver = new LtmdpChoiceResolver(_stepGraph, useForwardOptimization);
            ChoiceResolver       = _ltmdpChoiceResolver;
            RuntimeModel.SetChoiceResolver(ChoiceResolver);

            _allowFaultsOnInitialTransitions = configuration.AllowFaultsOnInitialTransitions;
        }
示例#8
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="model">The model the successors are computed for.</param>
        /// <param name="capacity">The maximum number of successors that can be cached.</param>
        /// <param name="formulas">The formulas that should be checked for all successor states.</param>
        public LtmdpCachedLabeledStates(ExecutableModel <TExecutableModel> model, long capacity, LtmdpStepGraph ltmdpStepGraph, params Func <bool>[] formulas)
        {
            Requires.NotNull(model, nameof(model));
            Requires.NotNull(formulas, nameof(formulas));
            Requires.That(formulas.Length < 32, "At most 32 formulas are supported.");
            Requires.That(capacity <= (1 << 30), nameof(capacity), $"Maximum supported capacity is {1 << 30}.");

            _stateVectorSize = model.StateVectorSize;
            _formulas        = formulas;
            _capacity        = capacity;

            LtmdpStepGraph = ltmdpStepGraph;

            _transitionsWithContinuationIdBuffer.Resize(capacity * sizeof(LtmdpTransition), zeroMemory: false);
            _transitionsWithContinuationIdMemory = (LtmdpTransition *)_transitionsWithContinuationIdBuffer.Pointer;

            _targetStateBuffer.Resize(capacity * model.StateVectorSize, zeroMemory: true);
            _targetStateMemory = _targetStateBuffer.Pointer;
        }
示例#9
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 public LtmdpChoiceResolver(LtmdpStepGraph ltmdpStepGraph)
     : base()
 {
     LtmdpStepGraph = ltmdpStepGraph;
 }
示例#10
0
 /// <summary>
 ///   Initializes a new instance.
 /// </summary>
 /// <param name="useForwardOptimization">Use Forward Optimization.</param>
 public LtmdpChoiceResolver(LtmdpStepGraph ltmdpStepGraph, bool useForwardOptimization)
     : base(useForwardOptimization)
 {
     LtmdpStepGraph = ltmdpStepGraph;
 }
示例#11
0
 public DirectChildrenEnumerator(LtmdpStepGraph ltmdpStepGraph, int parentContinuationId)
 {
     Choice = ltmdpStepGraph.GetChoiceOfCid(parentContinuationId);
     CurrentChildContinuationId = Choice.From - 1;
     ParentContinuationId       = parentContinuationId;
 }