Skip to content

Commit

Permalink
Merge pull request #30 from pascalpfeil/master
Browse files Browse the repository at this point in the history
Bachelorarbeit Pascal Pfeil
  • Loading branch information
joleuger committed Jun 6, 2018
2 parents 19bfc48 + acbf6b5 commit 2d7824b
Show file tree
Hide file tree
Showing 73 changed files with 4,879 additions and 3,446 deletions.
10 changes: 9 additions & 1 deletion Models/Lustre Models/App.config
@@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
816 changes: 409 additions & 407 deletions Models/Lustre Models/EvaluationTests.cs

Large diffs are not rendered by default.

77 changes: 37 additions & 40 deletions Models/Lustre Models/HazardProbabilityRangeTests.cs
@@ -1,54 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ISSE.SafetyChecking.DiscreteTimeMarkovChain;
using ISSE.SafetyChecking.ExecutedModel;
using ISSE.SafetyChecking.Formula;
using ISSE.SafetyChecking.MarkovDecisionProcess.Unoptimized;
using ISSE.SafetyChecking.Modeling;
using NUnit.Framework;
using SafetyLustre;
using LtmcModelChecker = ISSE.SafetyChecking.LtmcModelChecker;
using System;
using System.Collections.Generic;
using System.IO;
using static Lustre_Models.TestUtil;
using LtmdpModelChecker = ISSE.SafetyChecking.LtmdpModelChecker;

namespace Lustre_Models
{
public class HazardProbabilityRangeTests
{
[Test]
public void TankRupture()
{
Program.ocExaplesPath = Directory.GetCurrentDirectory() + "\\";
Program.modelChecking = true;
public class HazardProbabilityRangeTests
{
[Test]
public void TankRupture()
{
Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant, UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faults = new List<Fault>
{
new TransientFault() { Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6) },
new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) },
new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = null },
new PermanentFault() { Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5) },
new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) }
};

Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant,UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faults = new List<Fault>();
faults.Add(new TransientFault() { Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6) });
faults.Add(new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) });
faults.Add(new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = null });
faults.Add(new PermanentFault() { Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5) });
faults.Add(new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) });
var createModel = LustreExecutableModel.CreateExecutedModelFromFormulasCreator(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults.ToArray());

var createModel = LustreExecutableModel.CreateExecutedModelFromFormulasCreator("pressureTank", faults.ToArray());
var markovChainGenerator = new MarkovDecisionProcessFromExecutableModelGenerator<LustreExecutableModel>(createModel);
markovChainGenerator.Configuration.ModelCapacity = new ModelCapacityByModelSize(10000, 1000000);
markovChainGenerator.Configuration.SuccessorCapacity *= 2;
markovChainGenerator.Configuration.EnableStaticPruningOptimization = true;
markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
markovChainGenerator.AddFormulaToCheck(hazard);
markovChainGenerator.Configuration.UseCompactStateStorage = true;
markovChainGenerator.Configuration.EnableEarlyTermination = false;
var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();

var markovChainGenerator = new MarkovDecisionProcessFromExecutableModelGenerator<LustreExecutableModel>(createModel);
markovChainGenerator.Configuration.SuccessorCapacity *= 2;
markovChainGenerator.Configuration.EnableStaticPruningOptimization = true;
markovChainGenerator.Configuration.LtmdpModelChecker = LtmdpModelChecker.BuiltInLtmdp;
markovChainGenerator.AddFormulaToCheck(hazard);
markovChainGenerator.Configuration.UseCompactStateStorage = true;
markovChainGenerator.Configuration.EnableEarlyTermination = false;
var markovChain = markovChainGenerator.GenerateLabeledTransitionMarkovDecisionProcess();
var ltmcModelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, Console.Out);
var finallyHazard = new BoundedUnaryFormula(hazard, UnaryOperator.Finally, 200);
var result = ltmcModelChecker.CalculateProbabilityRange(finallyHazard);

var ltmcModelChecker = new ConfigurationDependentLtmdpModelChecker(markovChainGenerator.Configuration, markovChain, Console.Out);
var finallyHazard = new BoundedUnaryFormula(hazard,UnaryOperator.Finally, 200);
var result = ltmcModelChecker.CalculateProbabilityRange(finallyHazard);

Console.Write($"Probability of hazard: {result}");
}
}
Console.Write($"Probability of hazard: {result}");
}
}
}
141 changes: 70 additions & 71 deletions Models/Lustre Models/HazardProbabilityTests.cs
@@ -1,85 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ISSE.SafetyChecking;
using ISSE.SafetyChecking.DiscreteTimeMarkovChain;
using ISSE.SafetyChecking.DiscreteTimeMarkovChain;
using ISSE.SafetyChecking.Formula;
using ISSE.SafetyChecking.Modeling;
using NUnit.Framework;
using SafetyLustre;
using LtmcModelChecker = ISSE.SafetyChecking.LtmcModelChecker;
using System;
using System.Collections.Generic;
using System.IO;
using static Lustre_Models.TestUtil;
using static SafetyLustre.LustreSafetyAnalysis;

namespace Lustre_Models
{
public class HazardProbabilityTests
{
[Test]
public void TankRupture()
{
Program.ocExaplesPath = Directory.GetCurrentDirectory() + "\\";
public class HazardProbabilityTests
{
[Test]
public void TankRupture()
{
Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant, UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faults = new List<Fault>
{
new TransientFault() { Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6) },
new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) },
new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6) },
new PermanentFault() { Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5) },
new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) }
};
var modelChecker = new LustreMarkovChainFromExecutableModelGenerator(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults);
modelChecker.AddFormulaToCheck(hazard);
modelChecker.Configuration.UseCompactStateStorage = true;
var lmc = modelChecker.GenerateLabeledMarkovChain();

var ltmcModelChecker = new BuiltinLtmcModelChecker(lmc, Console.Out);
var finallyHazard = new BoundedUnaryFormula(hazard, UnaryOperator.Finally, 200);
var result = ltmcModelChecker.CalculateProbability(finallyHazard);

Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant,UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faults = new List<Fault>();
faults.Add(new TransientFault() { Name = "fault_switch", Identifier = 0, ProbabilityOfOccurrence = new Probability(3.0E-6) });
faults.Add(new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) });
faults.Add(new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6) });
faults.Add(new PermanentFault() { Name = "fault_timer", Identifier = 3, ProbabilityOfOccurrence = new Probability(1.0E-5) });
faults.Add(new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) });
var modelChecker = new LustreMarkovChainFromExecutableModelGenerator("pressureTank", faults);
modelChecker.AddFormulaToCheck(hazard);
modelChecker.Configuration.UseCompactStateStorage = true;
var lmc = modelChecker.GenerateLabeledMarkovChain();
Console.Write($"Probability of hazard: {result}");
}

var ltmcModelChecker = new BuiltinLtmcModelChecker(lmc, Console.Out);
var finallyHazard = new BoundedUnaryFormula(hazard,UnaryOperator.Finally, 200);
var result = ltmcModelChecker.CalculateProbability(finallyHazard);

Console.Write($"Probability of hazard: {result}");
}
[Test]
public void Parametric()
{
Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant, UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faultK1 = new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) };
var faultK2 = new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6) };
var faultSensor = new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) };
var faults = new[] { faultK1, faultK2, faultSensor };

[Test]
public void Parametric()
{
Program.ocExaplesPath = Directory.GetCurrentDirectory() + "\\";
var parameter = new QuantitativeParametricAnalysisParameter
{
StateFormula = hazard,
Bound = null,
From = 3.0E-7,
To = 3.0E-5,
Steps = 25,
};

Formula invariant = new LustrePressureBelowThreshold();
Formula hazard = new UnaryFormula(invariant, UnaryOperator.Not);
LustrePressureBelowThreshold.threshold = 60;
var faultK1 = new PermanentFault() { Name = "fault_k1", Identifier = 1, ProbabilityOfOccurrence = new Probability(3.0E-6) };
var faultK2 = new PermanentFault() { Name = "fault_k2", Identifier = 2, ProbabilityOfOccurrence = new Probability(3.0E-6) };
var faultSensor = new PermanentFault() { Name = "fault_sensor", Identifier = 4, ProbabilityOfOccurrence = new Probability(1.0E-5) };
var faults = new []{ faultK1, faultK2, faultSensor };

var parameter = new QuantitativeParametricAnalysisParameter
{
StateFormula = hazard,
Bound = null,
From = 3.0E-7,
To = 3.0E-5,
Steps = 25,
UpdateParameterInModel = value => { faultK1.ProbabilityOfOccurrence=new Probability(value); }
};
var result = LustreModelChecker.ConductQuantitativeParametricAnalysis("pressureTank", faults, parameter);
var fileWriter = new StreamWriter("pressureTank_varyK1.csv", append: false);
result.ToCsv(fileWriter);
fileWriter.Close();
using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varyK1.csv"), append: false))
{
parameter.UpdateParameterInModel = value => { faultK1.ProbabilityOfOccurrence = new Probability(value); };
var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
result.ToCsv(fileWriter);
}

parameter.UpdateParameterInModel = value => { faultK2.ProbabilityOfOccurrence = new Probability(value); };
result = LustreModelChecker.ConductQuantitativeParametricAnalysis("pressureTank", faults, parameter);
fileWriter = new StreamWriter("pressureTank_varyK2.csv", append: false);
result.ToCsv(fileWriter);
fileWriter.Close();
using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varyK2.csv"), append: false))
{
parameter.UpdateParameterInModel = value => { faultK2.ProbabilityOfOccurrence = new Probability(value); };
var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
result.ToCsv(fileWriter);
}

parameter.UpdateParameterInModel = value => { faultSensor.ProbabilityOfOccurrence = new Probability(value); };
result = LustreModelChecker.ConductQuantitativeParametricAnalysis("pressureTank", faults, parameter);
fileWriter = new StreamWriter("pressureTank_varySensor.csv", append: false);
result.ToCsv(fileWriter);
fileWriter.Close();
}
}
using (var fileWriter = new StreamWriter(Path.Combine(AssemblyDirectory, "pressureTank_varySensor.csv"), append: false))
{
parameter.UpdateParameterInModel = value => { faultSensor.ProbabilityOfOccurrence = new Probability(value); };
var result = LustreModelChecker.ConductQuantitativeParametricAnalysis(Path.Combine(AssemblyDirectory, "pressureTank.lus"), "TANK", faults, parameter);
result.ToCsv(fileWriter);
}
}
}
}
40 changes: 26 additions & 14 deletions Models/Lustre Models/Lustre Models.csproj
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\Dependencies\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\Dependencies\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" />
<Import Project="..\..\Dependencies\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\..\Dependencies\NUnit.3.10.1\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -12,9 +14,11 @@
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand All @@ -36,20 +40,17 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\FluentAssertions.4.1.1\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentAssertions.Core, Version=4.1.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\FluentAssertions.4.1.1\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
<Reference Include="FluentAssertions, Version=5.3.2.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\FluentAssertions.5.3.2\lib\net45\FluentAssertions.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\Dependencies\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -65,15 +66,16 @@
<Compile Include="SimulationTests.cs" />
<Compile Include="SafetyAnalysisTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TestUtil.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
<None Include="pressureTank.lus">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="pressureTank.oc">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
Expand All @@ -82,11 +84,21 @@
<Name>SafetyChecking</Name>
</ProjectReference>
<ProjectReference Include="..\..\Source\SafetyLustre\SafetyLustre.csproj">
<Project>{cc928659-8ccf-4357-bd4f-224f80c5c79a}</Project>
<Project>{CC928659-8CCF-4357-BD4F-224F80C5C79A}</Project>
<Name>SafetyLustre</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\Dependencies\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\Dependencies\NUnit.3.10.1\build\NUnit.props'))" />
<Error Condition="!Exists('..\..\Dependencies\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\Dependencies\NUnit3TestAdapter.3.10.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down

0 comments on commit 2d7824b

Please sign in to comment.