コード例 #1
0
        private void Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability probabilityOfFinally2;
            Probability probabilityOfFinally2b;

            var finally2  = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var finally2b = new BoundedUnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally, 2);

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(finally2);
            markovChainGenerator.AddFormulaToCheck(finally2b);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinally2  = modelChecker.CalculateProbability(finally2);
                probabilityOfFinally2b = modelChecker.CalculateProbability(finally2b);
            }

            probabilityOfFinally2.Between(0.33, 0.34).ShouldBe(true);
            probabilityOfFinally2b.Between(0.33, 0.34).ShouldBe(true);
        }
コード例 #2
0
        public void MailSanitisationShouldProceedThroughEntireWorkflowWhenMessagesAreCollected()
        {
            var testDependencies = new CoreDependencyInstances(_coreDependencies.DiagnosticLogging, new DummyEnvVariableReader());
            var result           = AnalysisConfiguration.PopulateConfigFromEnviromentVariables(testDependencies);

            Assert.Equal(LocationKeyIdentifier.WestUs, result.ApiLocation);
        }
コード例 #3
0
        /// <summary>
        /// Divide text into sentences, using separators like a dot
        /// </summary>
        /// <param name="text">Input text for processing</param>
        /// <returns>Sentences generated from text processing</returns>
        public IList <string> Process(string text)
        {
            AnalysisConfiguration  analysisConfiguration = TextAnalysisRepository.Instance.AnalysisConfiguration;
            AnalysisProcessContext processContext        = new AnalysisProcessContext();

            processContext.AnalysisConfiguration = analysisConfiguration;

            //If enter key (\n or \r\n) declared as seperator- We seperate input text to segments
            if (analysisConfiguration.EnableLinebreakSeperator)
            {
                IList <string> segments = GetTextSegments(text);

                //Processing all segments contained in the input text
                foreach (var segment in segments)
                {
                    if (!string.IsNullOrWhiteSpace(segment))
                    {
                        ProcessTextSegment(segment, processContext);
                    }
                }
            }
            else
            {
                //Process input text as one segmant
                ProcessTextSegment(text, processContext);
            }

            return(processContext.Output.SentenceListResult);
        }
コード例 #4
0
 public MailProcessingEngine(CoreDependencyInstances coreDependencies,
                             IMailProcessorRepository repository, AnalysisConfiguration config)
 {
     _coreDependencies = coreDependencies;
     _repository       = repository;
     _config           = config;
 }
コード例 #5
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;
		}
コード例 #6
0
        // Note: Should be used with using(var modelchecker = new ...)
        internal ConfigurationDependentLtmdpModelChecker(AnalysisConfiguration configuration, LabeledTransitionMarkovDecisionProcess markovChain, TextWriter output = null)
            : base(markovChain, output)
        {
            switch (configuration.LtmdpModelChecker)
            {
            case SafetyChecking.LtmdpModelChecker.BuiltInLtmdp:
                Requires.That(configuration.UseCompactStateStorage, "Need CompactStateStorage to use this algorithm");
                _ltmdpModelChecker = new BuiltinLtmdpModelChecker(Ltmdp, output);
                break;

            case SafetyChecking.LtmdpModelChecker.BuiltInNmdp:
                var nmdp = ConvertToNmdp(configuration, Ltmdp);
                _nmdpModelChecker = new BuiltinNmdpModelChecker(nmdp, output);
                break;

            case SafetyChecking.LtmdpModelChecker.BuildInMdpWithNewStates:
                nmdp = ConvertToNmdp(configuration, Ltmdp);
                var mdp = ConvertToMdpWithNewStates(configuration, nmdp);
                _mdpModelChecker = new BuiltinMdpModelChecker(mdp, output);
                break;

            case SafetyChecking.LtmdpModelChecker.BuildInMdpWithFlattening:
                nmdp             = ConvertToNmdp(configuration, Ltmdp);
                mdp              = ConvertToMdpWithFlattening(configuration, nmdp);
                _mdpModelChecker = new BuiltinMdpModelChecker(mdp, output);
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #7
0
        private void Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability minProbabilityOfFinal2;
            Probability minProbabilityOfFinal3;
            Probability maxProbabilityOfFinal2;
            Probability maxProbabilityOfFinal3;

            var final2 = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var final3 = new UnaryFormula(new SimpleStateInRangeFormula(3), UnaryOperator.Finally);

            var mdpGenerator = new SimpleMarkovDecisionProcessFromExecutableModelGenerator(m);

            mdpGenerator.Configuration = configuration;
            mdpGenerator.AddFormulaToCheck(final2);
            mdpGenerator.AddFormulaToCheck(final3);
            var mdp          = mdpGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
            var modelChecker = new ConfigurationDependentLtmdpModelChecker(configuration, mdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal2 = modelChecker.CalculateMinimalProbability(final2);
                minProbabilityOfFinal3 = modelChecker.CalculateMinimalProbability(final3);
                maxProbabilityOfFinal2 = modelChecker.CalculateMaximalProbability(final2);
                maxProbabilityOfFinal3 = modelChecker.CalculateMaximalProbability(final3);
            }

            minProbabilityOfFinal2.Is(0.3, tolerance: 0.0001).ShouldBe(true);
            minProbabilityOfFinal3.Is(0.6, tolerance: 0.0001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(0.3, tolerance: 0.0001).ShouldBe(true);
            maxProbabilityOfFinal3.Is(0.6, tolerance: 0.0001).ShouldBe(true);
        }
コード例 #8
0
        public async Task RunAnalysis_IncreaseOnWin_WinBet()
        {
            // Arrange
            var logger   = Substitute.For <ILogger <RunAnalysis> >();
            var playHand = Substitute.For <IPlayHand>();

            var runAnalysis = new RunAnalysis(logger, playHand);

            var analysisConfiguration = new AnalysisConfiguration()
            {
                StartingAnte     = 1,
                BettingStrategy  = BettingStrategy.IncreaseOnWin,
                DeckCountPerShoe = 4,
                PlayerFunds      = 10,
                TargetFunds      = 11,
                AvailableActions = TestHelper.BuildAvailableActionsAlwaysStand()
            };

            var updateProgress = Substitute.For <IUpdateProgress>();

            // Act
            decimal result = await runAnalysis.Run(analysisConfiguration, updateProgress);

            // Assert
        }
コード例 #9
0
        private void Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability probabilityOfFinal100;
            Probability probabilityOfFinal200;

            var final100Formula = new BoundedUnaryFormula(Model.StateIs100, UnaryOperator.Finally, 5);
            var final200Formula = new BoundedUnaryFormula(Model.StateIs200, UnaryOperator.Finally, 5);

            var mdpGenerator = new SimpleMarkovDecisionProcessFromExecutableModelGenerator(m);

            mdpGenerator.Configuration = configuration;
            mdpGenerator.AddFormulaToCheck(final100Formula);
            mdpGenerator.AddFormulaToCheck(final200Formula);
            var mdp          = mdpGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
            var modelChecker = new ConfigurationDependentLtmdpModelChecker(configuration, mdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal100 = modelChecker.CalculateMinimalProbability(final100Formula);
                probabilityOfFinal200 = modelChecker.CalculateMinimalProbability(final200Formula);
            }

            probabilityOfFinal100.Is(0.6 * 0.8, 0.000001).ShouldBe(true);
            probabilityOfFinal200.Is(0.4 + 0.6 * 0.2, 0.000001).ShouldBe(true);
        }
コード例 #10
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        /// <param name="stateFormula">The analyzed stateFormula.</param>
        internal InvariantChecker(AnalysisModelCreator createModel, AnalysisConfiguration configuration, Formula stateFormula)
        {
            ModelTraverser = new ModelTraverser(createModel, configuration, 0, false);
            var formulasToCheck = ModelTraverser.AnalyzedModels.First().Formulas;

            ModelTraverser.Context.TraversalParameters.TransitionActions.Add(() => new InvariantViolationAction(formulasToCheck, stateFormula));
        }
コード例 #11
0
 public JavaScriptCodeAnalyzer(AnalysisConfiguration configuration, ExecutableCodeFactory codeFactory,
                               ContainerConfiguration containerConfiguration, DockerContainerExecutor executor, IMapper mapper)
     : base(configuration,
            codeFactory, containerConfiguration, executor)
 {
     _mapper = mapper;
 }
コード例 #12
0
        private void Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability probabilityOfFinal1;
            Probability probabilityOfFinal2;
            Probability probabilityOfFinal3;

            var final1Formula = new UnaryFormula(new SimpleStateInRangeFormula(1), UnaryOperator.Finally);
            var final2Formula = new UnaryFormula(new SimpleStateInRangeFormula(2), UnaryOperator.Finally);
            var final3Formula = new UnaryFormula(new SimpleStateInRangeFormula(3), UnaryOperator.Finally);

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(final1Formula);
            markovChainGenerator.AddFormulaToCheck(final2Formula);
            markovChainGenerator.AddFormulaToCheck(final3Formula);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal1 = modelChecker.CalculateProbability(final1Formula);
                probabilityOfFinal2 = modelChecker.CalculateProbability(final2Formula);
                probabilityOfFinal3 = modelChecker.CalculateProbability(final3Formula);
            }

            probabilityOfFinal1.Is(0.7, 0.000001).ShouldBe(true);
            probabilityOfFinal2.Is(0.15, 0.000001).ShouldBe(true);
            probabilityOfFinal3.Is(0.15, 0.000001).ShouldBe(true);
        }
コード例 #13
0
ファイル: OrderAnalysis.cs プロジェクト: pascalpfeil/ssharp
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="results">The result of the safety analysis the order analysis should be conducted for.</param>
        /// <param name="configuration">The model checker's configuration that determines certain model checker settings.</param>
        public OrderAnalysis(SafetyAnalysisResults <TExecutableModel> results, AnalysisConfiguration configuration)
        {
            Requires.NotNull(results, nameof(results));

            _results = results;
            _backend.InitializeModel(configuration, results.RuntimeModelCreator, results.Hazard);
        }
コード例 #14
0
        /// <summary>
        ///   Initializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            var invariant = new UnaryFormula(hazard, UnaryOperator.Not);

            var checker = new QualitativeChecker <TExecutableModel>(RuntimeModelCreator)
            {
                Configuration = configuration
            };

            checker.Configuration.ProgressReportsOnly = false;


            var stateGraph = checker.GenerateStateGraph();



            var stateCapacity    = Math.Max(1024, (int)(stateGraph.StateCount * 1.5));
            var newModelCapacity = new ModelCapacityByModelDensity(stateCapacity, ModelDensityLimit.High);

            configuration.ModelCapacity = newModelCapacity;
            Func <AnalysisModel> createAnalysisModelFunc = () => new StateGraphModel <TExecutableModel>(stateGraph, configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);

            _checker = new InvariantChecker(createAnalysisModel, configuration, invariant);
        }
コード例 #15
0
        private void Check(AnalysisConfiguration configuration)
        {
            var         m = new Model();
            Probability probabilityOfFinal100;
            Probability probabilityOfFinal200;

            var final100Formula = new UnaryFormula(Model.StateIs100, UnaryOperator.Finally);
            var final200Formula = new UnaryFormula(Model.StateIs200, UnaryOperator.Finally);

            var markovChainGenerator = new SimpleMarkovChainFromExecutableModelGenerator(m);

            markovChainGenerator.Configuration = configuration;
            markovChainGenerator.AddFormulaToCheck(final100Formula);
            markovChainGenerator.AddFormulaToCheck(final200Formula);
            var ltmc         = markovChainGenerator.GenerateLabeledMarkovChain();
            var modelChecker = new ConfigurationDependentLtmcModelChecker(configuration, ltmc, Output.TextWriterAdapter());

            using (modelChecker)
            {
                probabilityOfFinal100 = modelChecker.CalculateProbability(final100Formula);
                probabilityOfFinal200 = modelChecker.CalculateProbability(final200Formula);
            }

            probabilityOfFinal100.Is(0.0, 0.000001).ShouldBe(true);
            probabilityOfFinal200.Is(1.0, 0.000001).ShouldBe(true);
        }
コード例 #16
0
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="model">The model that should be analyzed.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		internal void InitializeModel(AnalysisConfiguration configuration, ModelBase model, Formula hazard)
		{
			Model = model;
			ForcedFaults = new FaultSet(Model.Faults.Where(fault => fault.Activation == Activation.Forced));
			SuppressedFaults = new FaultSet(Model.Faults.Where(fault => fault.Activation == Activation.Suppressed));

			InitializeModel(configuration, hazard);
		}
コード例 #17
0
 public CodeAnalyzer(AnalysisConfiguration configuration, ExecutableCodeFactory codeFactory,
                     ContainerConfiguration containerConfiguration, DockerContainerExecutor executor)
 {
     Configuration          = configuration;
     _codeFactory           = codeFactory;
     ContainerConfiguration = containerConfiguration;
     _executor = executor;
 }
コード例 #18
0
ファイル: AnalysisBackend.cs プロジェクト: pascalpfeil/ssharp
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="createFreshModel">The creator for the model that should be checked.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        internal void InitializeModel(AnalysisConfiguration configuration, CoupledExecutableModelCreator <TExecutableModel> createFreshModel, Formula hazard)
        {
            RuntimeModelCreator = createFreshModel;
            ForcedFaults        = new FaultSet(createFreshModel.FaultsInBaseModel.Where(fault => fault.Activation == Activation.Forced));
            SuppressedFaults    = new FaultSet(createFreshModel.FaultsInBaseModel.Where(fault => fault.Activation == Activation.Suppressed));

            InitializeModel(configuration, hazard);
        }
コード例 #19
0
 public override void SetModelCheckerParameter(bool suppressCounterExampleGeneration, TextWriter output)
 {
     _suppressCounterExampleGeneration             = suppressCounterExampleGeneration;
     _analysisConfiguration                        = AnalysisConfiguration.Default;
     _analysisConfiguration.DefaultTraceOutput     = output;
     _analysisConfiguration.ModelCapacity          = ModelCapacityByMemorySize.Small;
     _analysisConfiguration.GenerateCounterExample = !suppressCounterExampleGeneration;
 }
コード例 #20
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel <TExecutableModel> > createAnalysisModelFunc = () =>
                                                                               new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, _stateHeaderBytes, configuration.SuccessorCapacity);
            var createAnalysisModel = new AnalysisModelCreator <TExecutableModel>(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker <TExecutableModel>(createAnalysisModel, OnOutputWritten, configuration, invariant);
        }
コード例 #21
0
        /// <summary>
        ///   Initizializes the model that should be analyzed.
        /// </summary>
        /// <param name="configuration">The configuration that should be used for the analyses.</param>
        /// <param name="hazard">The hazard that should be analyzed.</param>
        protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
        {
            Func <AnalysisModel> createAnalysisModelFunc = () =>
                                                           new ActivationMinimalExecutedModel <TExecutableModel>(RuntimeModelCreator, 0, configuration);
            var createAnalysisModel = new AnalysisModelCreator(createAnalysisModelFunc);
            var invariant           = new UnaryFormula(hazard, UnaryOperator.Not);

            _invariantChecker = new InvariantChecker(createAnalysisModel, configuration, invariant);
        }
コード例 #22
0
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
		{
			var serializer = new RuntimeModelSerializer();
			serializer.Serialize(Model, !hazard);

			Func<AnalysisModel> createModel = () =>
				new ActivationMinimalExecutedModel(CreateModel(hazard), configuration.SuccessorCapacity);

			_invariantChecker = new InvariantChecker(createModel, OnOutputWritten, configuration, formulaIndex: 0);
		}
コード例 #23
0
        /// <summary>
        /// Init Configuration
        /// </summary>
        /// <returns></returns>
        public AnalysisConfiguration Init()
        {
            var configuration          = new AnalysisConfiguration();
            var StopSignConfigurations = configuration.StopSignConfigurations;

            AddStopSignConfiguration(StopSignConfigurations, new DotConfigurationFactory());
            AddStopSignConfiguration(StopSignConfigurations, new QuestionMarkConfigurationFactory());
            StopSignConfigurations.Add(Consts.EXCLAMATION_MARK_SIGN, null);

            return(configuration);
        }
コード例 #24
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="createModel">Creates the model that should be checked.</param>
		/// <param name="stateFormulas">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 StateGraphGenerator(Func<AnalysisModel> createModel, Formula[] stateFormulas,
									 Action<string> output, AnalysisConfiguration configuration)
			: base(createModel, output, configuration)
		{
			var analyzedModel = AnalyzedModels.First();

			_stateGraph = new StateGraph(
				Context, stateFormulas, analyzedModel.TransitionSize,
				analyzedModel.RuntimeModel, analyzedModel.RuntimeModelCreator);

			Context.TraversalParameters.BatchedTransitionActions.Add(() => new StateGraphBuilder(_stateGraph));
		}
コード例 #25
0
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		protected override void InitializeModel(AnalysisConfiguration configuration, Formula hazard)
		{
			var checker = new SSharpChecker { Configuration = configuration };
			checker.Configuration.ProgressReportsOnly = false;
			checker.OutputWritten += OnOutputWritten;

			var stateGraph = checker.GenerateStateGraph(Model, !hazard);

			configuration.StateCapacity = Math.Max(1024, (int)(stateGraph.StateCount * 1.5));
			_checker = new InvariantChecker(() => new StateGraphModel(stateGraph, configuration.SuccessorCapacity), OnOutputWritten,
				configuration, formulaIndex: 0);
		}
コード例 #26
0
        private void CheckBounded(AnalysisConfiguration configuration)
        {
            var         m = new SharedModels.SimpleExample2a();
            Probability minProbabilityOfFinal0;
            Probability minProbabilityOfFinal0Lt;
            Probability minProbabilityOfFinal1;
            Probability minProbabilityOfFinal2;
            Probability maxProbabilityOfFinal0;
            Probability maxProbabilityOfFinal0Lt;
            Probability maxProbabilityOfFinal1;
            Probability maxProbabilityOfFinal2;

            var final0Formula   = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs0, UnaryOperator.Finally, 4);
            var final0LtFormula =
                new BoundedUnaryFormula(
                    new BinaryFormula(SharedModels.SimpleExample2a.StateIs0, BinaryOperator.And, SharedModels.SimpleExample2a.LocalVarIsTrue),
                    UnaryOperator.Finally, 4);
            var final1Formula = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs1, UnaryOperator.Finally, 4);
            var final2Formula = new BoundedUnaryFormula(SharedModels.SimpleExample2a.StateIs2, UnaryOperator.Finally, 4);

            var mdpGenerator = new SimpleMarkovDecisionProcessFromExecutableModelGenerator(m);

            mdpGenerator.Configuration = configuration;
            mdpGenerator.AddFormulaToCheck(final0Formula);
            mdpGenerator.AddFormulaToCheck(final0LtFormula);
            mdpGenerator.AddFormulaToCheck(final1Formula);
            mdpGenerator.AddFormulaToCheck(final2Formula);
            var mdp          = mdpGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
            var modelChecker = new ConfigurationDependentLtmdpModelChecker(configuration, mdp, Output.TextWriterAdapter());

            using (modelChecker)
            {
                minProbabilityOfFinal0   = modelChecker.CalculateMinimalProbability(final0Formula);
                minProbabilityOfFinal0Lt = modelChecker.CalculateMinimalProbability(final0LtFormula);
                minProbabilityOfFinal1   = modelChecker.CalculateMinimalProbability(final1Formula);
                minProbabilityOfFinal2   = modelChecker.CalculateMinimalProbability(final2Formula);
                maxProbabilityOfFinal0   = modelChecker.CalculateMaximalProbability(final0Formula);
                maxProbabilityOfFinal0Lt = modelChecker.CalculateMaximalProbability(final0LtFormula);
                maxProbabilityOfFinal1   = modelChecker.CalculateMaximalProbability(final1Formula);
                maxProbabilityOfFinal2   = modelChecker.CalculateMaximalProbability(final2Formula);
            }

            minProbabilityOfFinal0.Is(1.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal0Lt.Is(0.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal1.Is(0.0, 0.000001).ShouldBe(true);
            minProbabilityOfFinal2.Is(0.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal0.Is(1.0, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal0Lt.Is(1.0, 0.000001).ShouldBe(true);
            var maxProbabilityOf1And2Calculated = 1.0 - Math.Pow(0.6, 4);

            maxProbabilityOfFinal1.Is(maxProbabilityOf1And2Calculated, 0.000001).ShouldBe(true);
            maxProbabilityOfFinal2.Is(maxProbabilityOf1And2Calculated, 0.000001).ShouldBe(true);
        }
コード例 #27
0
        internal DiscreteTimeMarkovChain ConvertToMarkovChain(AnalysisConfiguration configuration, LabeledTransitionMarkovChain labeledTransitionMarkovChain)
        {
            var ltmcToMc    = new LtmcToDtmc(labeledTransitionMarkovChain);
            var markovChain = ltmcToMc.MarkovChain;

            if (configuration.WriteGraphvizModels)
            {
                configuration.DefaultTraceOutput.WriteLine("Dtmc Model");
                markovChain.ExportToGv(configuration.DefaultTraceOutput);
            }
            return(markovChain);
        }
コード例 #28
0
        private MarkovDecisionProcess ConvertToMdpWithFlattening(AnalysisConfiguration configuration, NestedMarkovDecisionProcess nmdp)
        {
            var nmdpToMpd = new NmdpToMdpByFlattening(nmdp);
            var mdp       = nmdpToMpd.MarkovDecisionProcess;

            if (configuration.WriteGraphvizModels)
            {
                configuration.DefaultTraceOutput.WriteLine("Mdp Model");
                mdp.ExportToGv(configuration.DefaultTraceOutput);
            }
            return(mdp);
        }
コード例 #29
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 StateGraphGenerator(AnalysisModelCreator <TExecutableModel> createModel,
                                     Action <string> output, AnalysisConfiguration configuration)
            : base(createModel, output, configuration, DeriveTransitionSizeFromModel)
        {
            var analyzedModel = AnalyzedModels.First();

            _stateGraph = new StateGraph <TExecutableModel>(
                Context, analyzedModel.TransitionSize,
                analyzedModel.RuntimeModel, analyzedModel.RuntimeModelCreator);

            Context.TraversalParameters.BatchedTransitionActions.Add(() => new StateGraphBuilder <TExecutableModel>(_stateGraph));
        }
コード例 #30
0
        private MarkovDecisionProcess ConvertToMdpWithNewStates(AnalysisConfiguration configuration, NestedMarkovDecisionProcess nmdp, bool makeConstantDistanceBetweenStates)
        {
            var nmdpToMpd = new NmdpToMdpByNewStates(nmdp, configuration.DefaultTraceOutput, makeConstantDistanceBetweenStates);
            var mdp       = nmdpToMpd.MarkovDecisionProcess;

            if (configuration.WriteGraphvizModels)
            {
                configuration.DefaultTraceOutput.WriteLine("Mdp Model");
                mdp.ExportToGv(configuration.DefaultTraceOutput);
            }
            return(mdp);
        }
コード例 #31
0
        private NestedMarkovDecisionProcess ConvertToNmdp(AnalysisConfiguration configuration, LabeledTransitionMarkovDecisionProcess ltmdp)
        {
            var ltmdpToNmdp = new LtmdpToNmdp(ltmdp);
            var nmdp        = ltmdpToNmdp.NestedMarkovDecisionProcess;

            if (configuration.WriteGraphvizModels)
            {
                configuration.DefaultTraceOutput.WriteLine("Nmdp Model");
                nmdp.ExportToGv(configuration.DefaultTraceOutput);
            }
            return(nmdp);
        }
コード例 #32
0
        /// <summary>
        ///   Initializes a new instance.
        /// </summary>
        /// <param name="createModel">Creates the model that should be checked.</param>
        /// <param name="configuration">The analysis configuration that should be used.</param>
        internal StateGraphGenerator(AnalysisModelCreator createModel,
                                     AnalysisConfiguration configuration)
        {
            _modelTraverser = new ModelTraverser(createModel, configuration, ModelTraverser.DeriveTransitionSizeFromModel, false);

            var analyzedModel = _modelTraverser.AnalyzedModels.OfType <ExecutedModel <TExecutableModel> >().First();

            _stateGraph = new StateGraph <TExecutableModel>(
                _modelTraverser.Context, analyzedModel.TransitionSize,
                analyzedModel.RuntimeModel, analyzedModel.RuntimeModelCreator);

            _modelTraverser.Context.TraversalParameters.BatchedTransitionActions.Add(() => new StateGraphBuilder <TExecutableModel>(_stateGraph));
        }
コード例 #33
0
        private void btnAnalyzeFile_Click(object sender, RoutedEventArgs e)
        {
            AnalysisConfiguration analysisConfiguration;

            // Validate input
            if (string.IsNullOrEmpty(this.txtFilePath.Text))
            {
                MessageBox.Show("You must specify a file to analyze.", Constants.Application.Name + " " + Constants.Application.Version, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (this.IndexDefinitions.Count < 1)
            {
                MessageBox.Show("You must specify atleast one index to analyze.", Constants.Application.Name + " " + Constants.Application.Version, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            foreach (IndexDefinition indexDefinition in this.IndexDefinitions)
            {
                if (string.IsNullOrWhiteSpace(indexDefinition.Name) || indexDefinition.Position == null || indexDefinition.Length == null)
                {
                    MessageBox.Show("You must provide atleast the name, position, and length for all index definitions.", Constants.Application.Name + " " + Constants.Application.Version, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            // Prep config
            analysisConfiguration = new AnalysisConfiguration()
            {
                File = new FileInfo(this.txtFilePath.Text),
                ShouldIgnoreHeaderRow    = this.chkIgnoreHeader.IsChecked,
                ShouldIgnoreTrailerRow   = this.chkIgnoreFooter.IsChecked,
                ShouldIncludeRowIdColumn = this.chkIncludeRowIdColumn.IsChecked,
                ShouldIncludeFlagColumn  = this.chkIncludeFlagColumn.IsChecked,
                IndexDefinitions         = this.IndexDefinitions.ToList <IndexDefinition>()
            }.SortIndexDefinitionsByPosition();

            if (analysisConfiguration.IndexDefinitions[0].Position == 1)
            {
                analysisConfiguration.IndexOffset = IndexOffset.One;
            }
            else
            {
                analysisConfiguration.IndexOffset = IndexOffset.Zero;
            }

            // Start analysis
            AnalysisWindow analysisWindow = new AnalysisWindow(analysisConfiguration);

            analysisWindow.Show();
        }
コード例 #34
0
        public async static Task Run([QueueTrigger(DataStores.Queues.QueueNameProcessEmail)] string myQueueItem, ILogger log)
        //public async static Task Run([HttpTrigger("GET")]string myQueueItem, ILogger log)
        {
            var dependencies    = CoreDependencies.Setup(log);
            var receivedMessage = GenericActionMessage.FromString(myQueueItem);
            var analysisConfig  = AnalysisConfiguration.PopulateConfigFromEnviromentVariables(dependencies);

            var now = DateTime.UtcNow;

            dependencies.DiagnosticLogging.Verbose("MailProcessor: Timer trigger function executed at: {now} UTC", now);

            var repo   = new MailProcessorRepository(dependencies);
            var engine = new MailProcessingEngine(dependencies, repo, analysisConfig);
            await engine.AnalyseAllMailAsync(receivedMessage);
        }
コード例 #35
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));
            }
        }
コード例 #36
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>
		/// <param name="formulaIndex">The zero-based index of the analyzed formula.</param>
		internal InvariantChecker(Func<AnalysisModel> createModel, Action<string> output, AnalysisConfiguration configuration, int formulaIndex)
			: base(createModel, output, configuration)
		{
			Context.TraversalParameters.TransitionActions.Add(() => new InvariantViolationAction(formulaIndex));
		}
コード例 #37
0
		/// <summary>
		///   Initizializes the model that should be analyzed.
		/// </summary>
		/// <param name="configuration">The configuration that should be used for the analyses.</param>
		/// <param name="hazard">The hazard that should be analyzed.</param>
		protected abstract void InitializeModel(AnalysisConfiguration configuration, Formula hazard);
コード例 #38
0
		/// <summary>
		///   Initializes a new instance.
		/// </summary>
		/// <param name="loadBalancer">The load balancer that balances the work of multiple <see cref="Worker" /> instances.</param>
		/// <param name="configuration">The configuration values for the analysis.</param>
		/// <param name="output">The action that should be invoked when output is generated.</param>
		public TraversalContext(LoadBalancer loadBalancer, AnalysisConfiguration configuration, Action<string> output)
		{
			Requires.NotNull(loadBalancer, nameof(loadBalancer));
			Requires.NotNull(output, nameof(output));

			LoadBalancer = loadBalancer;
			Configuration = configuration;
			Output = output;

			Reset();
		}