/// <summary>
        ///   Generates a <see cref="LabeledTransitionMarkovDecisionProcess" /> for the model created by <paramref name="createModel" />.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        internal LabeledTransitionMarkovDecisionProcess GenerateLtmdp(AnalysisModelCreator createModel)
        {
            using (var modelTraverser = new ModelTraverser(createModel, Configuration, LabeledTransitionMarkovDecisionProcess.TransitionSize,
                                                           FormulaManager.NeedsStutteringState))
            {
                _mdp = new LabeledTransitionMarkovDecisionProcess(modelTraverser.Context.ModelCapacity.NumberOfStates, modelTraverser.Context.ModelCapacity.NumberOfTransitions);
                _mdp.StateFormulaLabels = FormulaManager.FinalStateFormulaLabels.ToArray();

                if (FormulaManager.NeedsStutteringState)
                {
                    _mdp.CreateStutteringState(modelTraverser.Context.StutteringStateIndex);
                }

                modelTraverser.Context.TraversalParameters.TransitionModifiers.AddRange(FormulaManager.TransitionModifierGenerators);
                modelTraverser.Context.TraversalParameters.BatchedTransitionActions.Add(() => new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal(_mdp));

                modelTraverser.Context.Output.WriteLine("Generating labeled transition markov decision process.");
                modelTraverser.TraverseModelAndReport();

                // StateStorage must be freed manually. Reason is that invariant checker does not free up the
                // space, because it might be necessary for other usages of the ModelTraversers (e.g. StateGraphGenerator
                // which keeps the States for the StateGraph)
                modelTraverser.Context.States.SafeDispose();
            }


            if (Configuration.WriteGraphvizModels)
            {
                FormulaManager.PrintStateFormulas(FormulaManager.FinalStateFormulas, Configuration.DefaultTraceOutput);
                Configuration.DefaultTraceOutput.WriteLine("Ltmdp Model");
                _mdp.ExportToGv(Configuration.DefaultTraceOutput);
            }

            return(_mdp);
        }
Beispiel #2
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        /// <param name="executableStateFormulas">The state formulas that can be evaluated over the generated state graph.</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 LtmdpGenerator(AnalysisModelCreator <TExecutableModel> createModel, Formula terminateEarlyCondition, Formula[] executableStateFormulas,
                                Action <string> output, AnalysisConfiguration configuration)
            : base(createModel, output, configuration, LabeledTransitionMarkovDecisionProcess.TransitionSize)
        {
            _mdp = new LabeledTransitionMarkovDecisionProcess(Context.ModelCapacity.NumberOfStates, Context.ModelCapacity.NumberOfTransitions);
            _mdp.StateFormulaLabels = executableStateFormulas.Select(stateFormula => stateFormula.Label).ToArray();

            Context.TraversalParameters.BatchedTransitionActions.Add(() => new LabeledTransitionMarkovDecisionProcess.LtmdpBuilderDuringTraversal <TExecutableModel>(_mdp, configuration));
            if (terminateEarlyCondition != null)
            {
                _mdp.CreateStutteringState(Context.StutteringStateIndex);
                var terminalteEarlyFunc = StateFormulaSetEvaluatorCompilationVisitor.Compile(_mdp.StateFormulaLabels, terminateEarlyCondition);
                Context.TraversalParameters.TransitionModifiers.Add(() => new EarlyTerminationModifier <TExecutableModel>(terminalteEarlyFunc));
            }
        }