コード例 #1
0
        /// <summary>
        ///   Generates a <see cref="MarkovDecisionProcess" /> for the model created by <paramref name="createModel" />.
        /// </summary>
        public NestedMarkovDecisionProcess GenerateMarkovDecisionProcess(Formula terminateEarlyCondition = null)
        {
            Requires.That(IntPtr.Size == 8, "Model checking is only supported in 64bit processes.");

            ProbabilityMatrixCreationStarted = true;

            CollectStateFormulasVisitor stateFormulaCollector;

            if (Configuration.UseAtomarPropositionsAsStateLabels)
            {
                stateFormulaCollector = new CollectAtomarPropositionFormulasVisitor();
            }
            else
            {
                stateFormulaCollector = new CollectMaximalCompilableFormulasVisitor();
            }

            foreach (var stateFormula in _formulasToCheck)
            {
                stateFormulaCollector.VisitNewTopLevelFormula(stateFormula);
            }
            if (terminateEarlyCondition)
            {
                stateFormulaCollector.VisitNewTopLevelFormula(terminateEarlyCondition);
            }
            var stateFormulas = stateFormulaCollector.CollectedStateFormulas.ToArray();

            ExecutedModel <TExecutableModel> model = null;
            var modelCreator = _runtimeModelCreator.CreateCoupledModelCreator(stateFormulas);
            Func <AnalysisModel <TExecutableModel> > createAnalysisModelFunc = () =>
                                                                               model = new LtmdpExecutedModel <TExecutableModel>(modelCreator, 0, Configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator <TExecutableModel>(createAnalysisModelFunc);

            return(GenerateMarkovDecisionProcess(createAnalysisModel, terminateEarlyCondition, stateFormulas));
        }
        /// <summary>
        ///   Generates a <see cref="MarkovDecisionProcess" /> for the model created by <paramref name="createModel" />.
        /// </summary>
        public LabeledTransitionMarkovDecisionProcess GenerateLabeledTransitionMarkovDecisionProcess()
        {
            Requires.That(IntPtr.Size == 8, "Model checking is only supported in 64bit processes.");

            ProbabilityMatrixCreationStarted = true;

            FormulaManager.Calculate(Configuration);
            var stateFormulasToCheckInBaseModel = FormulaManager.StateFormulasToCheckInBaseModel.ToArray();

            ExecutedModel <TExecutableModel> model = null;
            var modelCreator = _runtimeModelCreator.CreateCoupledModelCreator(stateFormulasToCheckInBaseModel);
            Func <AnalysisModel> createAnalysisModelFunc = () =>
                                                           model = new LtmdpExecutedModel <TExecutableModel>(modelCreator, Configuration);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);

            var ltmdp = GenerateLtmdp(createAnalysisModel);

            return(ltmdp);
        }
コード例 #3
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        public ProbabilisticSimulator(ExecutableModelCreator <TExecutableModel> modelCreator, IEnumerable <Formula> formulas, AnalysisConfiguration configuration)
        {
            // TODO: Set Mode WithCustomSeed (each thread must have its own seed) or RealRandom
            Requires.NotNull(modelCreator, nameof(modelCreator));

            RuntimeModel = modelCreator.CreateCoupledModelCreator(formulas.ToArray()).Create(0);

            NormalizedFormulas                 = RuntimeModel.Formulas.ToArray();
            NormalizedFormulaLabels            = NormalizedFormulas.Select(stateFormula => stateFormula.Label).ToArray();
            NormalizedFormulaSatisfactionCount = new int[NormalizedFormulas.Length];
            _compiledNormalizedFormulas        = NormalizedFormulas.Select(formula => FormulaCompilationVisitor <TExecutableModel> .Compile(RuntimeModel, formula)).ToArray();

            _allowFaultsOnInitialTransitions = configuration.AllowFaultsOnInitialTransitions;

            _choiceResolver = new ProbabilisticSimulatorChoiceResolver(configuration.UseOptionProbabilitiesInSimulation, (int)DateTime.Now.Ticks);

            RuntimeModel.SetChoiceResolver(_choiceResolver);
            SavedActivations = RuntimeModel.NondeterministicFaults.Select(fault => fault.Activation).ToArray();
        }