Browse Source
Merge pull request 'Introducing Unit Tests for SMG Extensions' (#46) from smg_unit_tests into main
Merge pull request 'Introducing Unit Tests for SMG Extensions' (#46) from smg_unit_tests into main
Reviewed-on: https://git.pranger.xyz/TEMPEST/tempest-devel/pulls/46 ``` ... 100% tests passed, 0 tests failed out of 31 Total Test time (real) = 1144.27 sec ```tempestpy_adaptions
Stefan Pranger
3 years ago
51 changed files with 1903 additions and 270 deletions
-
1resources/examples/testfiles/rpatl/probabilisticFormula.rpatl
-
5resources/examples/testfiles/shields/mdp-shields/dieSelectionPostSafetygamma07Pmax.shield
-
8resources/examples/testfiles/shields/mdp-shields/dieSelectionPostSafetygamma07Pmin.shield
-
8resources/examples/testfiles/shields/mdp-shields/dieSelectionPostSafetylambda07Pmax.shield
-
8resources/examples/testfiles/shields/mdp-shields/dieSelectionPostSafetylambda07Pmin.shield
-
11resources/examples/testfiles/shields/mdp-shields/dieSelectionPreSafetygamma08Pmax.shield
-
6resources/examples/testfiles/shields/mdp-shields/dieSelectionPreSafetygamma08Pmin.shield
-
11resources/examples/testfiles/shields/mdp-shields/dieSelectionPreSafetylambda08Pmax.shield
-
4resources/examples/testfiles/shields/mdp-shields/dieSelectionPreSafetylambda08Pmin.shield
-
7resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyGamma05PmaxF5.shield
-
6resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyGamma05PminF5.shield
-
7resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyGamma09PmaxF3.shield
-
6resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyGamma09PminF3.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyLambda05PmaxF5.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyLambda05PminF5.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyLambda09PmaxF3.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPostSafetyLambda09PminF3.shield
-
7resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyGamma05PmaxF5.shield
-
6resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyGamma05PminF5.shield
-
7resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyGamma09PmaxF3.shield
-
6resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyGamma09PminF3.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyLambda05PmaxF5.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyLambda05PminF5.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyLambda09PmaxF3.shield
-
8resources/examples/testfiles/shields/smg-shields/rightDecisionPreSafetyLambda09PminF3.shield
-
52resources/examples/testfiles/smg/messageHack.nm
-
42resources/examples/testfiles/smg/rightDecision.nm
-
61resources/examples/testfiles/smg/robotCircle.nm
-
29resources/examples/testfiles/smg/walker.nm
-
127src/storm-parsers/parser/FormulaParserGrammar.cpp
-
11src/storm-parsers/parser/FormulaParserGrammar.h
-
7src/storm/generator/PrismNextStateGenerator.cpp
-
5src/storm/modelchecker/helper/finitehorizon/SparseNondeterministicStepBoundedHorizonHelper.cpp
-
2src/storm/modelchecker/rpatl/SparseSmgRpatlModelChecker.cpp
-
27src/storm/modelchecker/rpatl/helper/SparseSmgRpatlHelper.cpp
-
67src/storm/modelchecker/rpatl/helper/internal/GameViHelper.cpp
-
14src/storm/modelchecker/rpatl/helper/internal/GameViHelper.h
-
9src/storm/solver/Multiplier.cpp
-
1src/storm/storage/PostScheduler.cpp
-
51src/storm/storage/Scheduler.cpp
-
7src/storm/storage/SparseMatrix.cpp
-
8src/test/storm/CMakeLists.txt
-
43src/test/storm/logic/FragmentCheckerTest.cpp
-
198src/test/storm/modelchecker/prctl/mdp/ShieldGenerationMdpPrctlModelCheckerTest.cpp
-
280src/test/storm/modelchecker/rpatl/smg/ShieldGenerationSmgRpatlModelCheckerTest.cpp
-
351src/test/storm/modelchecker/rpatl/smg/SmgRpatlModelCheckerTest.cpp
-
204src/test/storm/parser/GameFormulaParserTest.cpp
-
81src/test/storm/parser/GameShieldingParserTest.cpp
-
72src/test/storm/parser/MdpShieldingParserTest.cpp
-
38src/test/storm/parser/PrismParserTest.cpp
@ -0,0 +1 @@ |
|||
<<player>> Pmax=? [ F "goal" ] |
@ -0,0 +1,5 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.700000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
4 0: 2; 1: 2; 2: 2 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.700000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1; 2: 2 |
|||
1 0: 0; 1: 1; 2: 2 |
|||
3 0: 0; 1: 1; 2: 2 |
|||
4 0: 0; 1: 1; 2: 2 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.700000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1; 2: 2 |
|||
1 0: 0; 1: 1; 2: 2 |
|||
3 0: 0; 1: 1; 2: 2 |
|||
4 0: 0; 1: 1; 2: 2 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.700000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 2; 1: 2; 2: 2 |
|||
1 0: 0; 1: 0; 2: 0 |
|||
3 0: 2; 1: 2; 2: 2 |
|||
4 0: 2; 1: 2; 2: 2 |
|||
___________________________________________________________________ |
@ -0,0 +1,11 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.800000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.8: (0) |
|||
1 0.9375: (0); 0.925: (1); 0.9125: (2) |
|||
2 0.9625: (0); 0.97: (1); 0.9775: (2) |
|||
3 0.875: (0); 0.85: (1); 0.825: (2) |
|||
4 1: (0); 1: (1); 1: (2) |
|||
5 1: (0); 1: (1); 1: (2) |
|||
6 0.925: (0); 0.91: (1); 0.895: (2) |
|||
___________________________________________________________________ |
@ -0,0 +1,6 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.800000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.58: (0); 0.566: (1); 0.552: (2) |
|||
3 0.755: (0); 0.706: (1); 0.657: (2) |
|||
___________________________________________________________________ |
@ -0,0 +1,11 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.800000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.8: (0); 0.79: (1); 0.78: (2) |
|||
1 0.9375: (0); 0.925: (1); 0.9125: (2) |
|||
2 0.9625: (0); 0.97: (1); 0.9775: (2) |
|||
3 0.875: (0); 0.85: (1); 0.825: (2) |
|||
4 1: (0); 1: (1); 1: (2) |
|||
5 1: (0); 1: (1); 1: (2) |
|||
6 0.925: (0); 0.91: (1); 0.895: (2) |
|||
___________________________________________________________________ |
@ -0,0 +1,4 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.800000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
___________________________________________________________________ |
@ -0,0 +1,7 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.500000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1 |
|||
5 0: 0 |
|||
9 0: 0; 1: 1 |
|||
___________________________________________________________________ |
@ -0,0 +1,6 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.500000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
4 0: 0 |
|||
5 0: 0 |
|||
___________________________________________________________________ |
@ -0,0 +1,7 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.900000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 0 |
|||
5 0: 0 |
|||
9 0: 0; 1: 0 |
|||
___________________________________________________________________ |
@ -0,0 +1,6 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with absolute comparison (gamma = 0.900000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
4 0: 0 |
|||
5 0: 0 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.500000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1 |
|||
4 0: 0 |
|||
5 0: 0 |
|||
9 0: 0; 1: 1 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.500000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1 |
|||
4 0: 0 |
|||
5 0: 0 |
|||
9 0: 0; 1: 1 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.900000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 0 |
|||
4 0: 0 |
|||
5 0: 0 |
|||
9 0: 0; 1: 0 |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Post-Safety-Shield with relative comparison (lambda = 0.900000): |
|||
model state: correction [<action>: (<corrected action>)}: |
|||
0 0: 0; 1: 1 |
|||
4 0: 0 |
|||
5 0: 0 |
|||
9 0: 0; 1: 1 |
|||
___________________________________________________________________ |
@ -0,0 +1,7 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.500000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.9: (0); 1: (1) |
|||
5 1: (0) |
|||
9 1: (0); 0.9: (1) |
|||
___________________________________________________________________ |
@ -0,0 +1,6 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.500000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
4 0: (0) |
|||
5 0: (0) |
|||
___________________________________________________________________ |
@ -0,0 +1,7 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.900000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.9: (0) |
|||
5 1: (0) |
|||
9 1: (0) |
|||
___________________________________________________________________ |
@ -0,0 +1,6 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with absolute comparison (gamma = 0.900000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
4 0: (0) |
|||
5 0: (0) |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.500000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.9: (0); 1: (1) |
|||
4 0: (0) |
|||
5 1: (0) |
|||
9 1: (0); 0.9: (1) |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.500000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0: (1) |
|||
4 0: (0) |
|||
5 0: (0) |
|||
9 0: (1) |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.900000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0.9: (0) |
|||
4 0: (0) |
|||
5 1: (0) |
|||
9 1: (0) |
|||
___________________________________________________________________ |
@ -0,0 +1,8 @@ |
|||
___________________________________________________________________ |
|||
Pre-Safety-Shield with relative comparison (lambda = 0.900000): |
|||
model state: choice(s) [<value>: (<action>)}: |
|||
0 0: (1) |
|||
4 0: (0) |
|||
5 0: (0) |
|||
9 0: (1) |
|||
___________________________________________________________________ |
@ -0,0 +1,52 @@ |
|||
// PRISM Model of hacking a communication |
|||
// - Bob and Alice are chatting. |
|||
// - Eve wants to hack the messages from Bob. |
|||
// - The propability of successfull hacking is 0.05. |
|||
|
|||
smg |
|||
|
|||
player bob |
|||
[receiveB], [readWriteB], [sendB], [waitB] |
|||
endplayer |
|||
|
|||
player alice |
|||
[receiveA], [readWriteA], [sendA], [waitA] |
|||
endplayer |
|||
|
|||
player eve |
|||
[hackE], [waitE] |
|||
endplayer |
|||
|
|||
// 0 bob, 1 eve, 2 alice |
|||
global move : [0..2] init 0; |
|||
// |
|||
global bobSent : [0..1] init 0; |
|||
global hacked : [0..1] init 0; |
|||
|
|||
label "hacked" = hacked=1; |
|||
|
|||
module communication |
|||
bobReceived : [0..1] init 0; |
|||
bobWroteMessage : [0..1] init 1; |
|||
aliceReceived : [0..1] init 0; |
|||
aliceWroteMessage : [0..1] init 0; |
|||
aliceSent : [0..1] init 0; |
|||
|
|||
// bob's communication part |
|||
[receiveB] move=0 & aliceSent=1 -> (bobReceived'=1) & (aliceSent'=0) & (move'=1); |
|||
[readWriteB] move=0 & bobReceived=1 -> (bobWroteMessage'=1) & (bobReceived'=0) & (move'=1); |
|||
[sendB] move=0 & bobWroteMessage=1 -> (bobSent'=1) & (bobWroteMessage'=0) & (move'=1); |
|||
[waitB] move=0 & !(aliceSent=1 | bobReceived=1 | bobWroteMessage=1) -> (move'=1); |
|||
|
|||
// alice's communication part |
|||
[receiveA] move=2 & bobSent=1 -> (aliceReceived'=1) & (bobSent'=0) & (move'=0); |
|||
[readWriteA] move=2 & aliceReceived=1 -> (aliceWroteMessage'=1) & (aliceReceived'=0) & (move'=0); |
|||
[sendA] move=2 & aliceWroteMessage=1 -> (aliceSent'=1) & (aliceWroteMessage'=0) & (move'=0); |
|||
[waitA] move=2 & !(bobSent=1 | aliceReceived=1 | aliceWroteMessage=1) -> (move'=0); |
|||
|
|||
endmodule |
|||
|
|||
module hacking |
|||
[hackE] move=1 & bobSent=1 -> 0.05: (hacked'=1) & (move'=2) + 0.95: (move'=2); |
|||
[waitE] move=1 & !(bobSent=1) -> (move'=2); |
|||
endmodule |
@ -0,0 +1,42 @@ |
|||
// PRISM Model of a decision for a shortcut |
|||
// - A hiker has to make a decision of taking a shortcut. |
|||
// - On the shortcut a native can be asked for getting to the target waypoint. |
|||
// - The native can lead the hiker to the goal or can give a proposal for getting to 0.9 to the target. |
|||
|
|||
smg |
|||
|
|||
player hiker |
|||
[startShortcut], [startWay], [waypoint1], [waypoint2target], [waypoint2start], [target], [lost] |
|||
endplayer |
|||
|
|||
player native |
|||
[wait], [shortcutBad], [shortcutGood] |
|||
endplayer |
|||
|
|||
// 0 bob, 1 native, |
|||
global move : [0..1] init 0; |
|||
|
|||
global shortcut : [0..1] init 0; |
|||
global target : [0..1] init 0; |
|||
global lost : [0..1] init 0; |
|||
|
|||
label "target" = target=1; |
|||
|
|||
module hikerModule |
|||
startpoint : [0..1] init 1; |
|||
waypoints : [0..2] init 0; |
|||
|
|||
[startShortcut] move=0 & startpoint=1 -> (shortcut'=1) & (startpoint'=0) & (move'=1); |
|||
[startWay] move=0 & startpoint=1 -> (waypoints'=1) & (startpoint'=0) & (move'=1); |
|||
[waypoint1] move=0 & waypoints=1 -> (waypoints'=2) & (move'=1); |
|||
[waypoint2target] move=0 & waypoints=2 -> (waypoints'=0) & (target'=1) & (move'=1); |
|||
[waypoint2start] move=0 & waypoints=2 -> (waypoints'=0) & (startpoint'=1) & (move'=1); |
|||
[target] move=0 & target=1 -> (move'=1); |
|||
[lost] move=0 & lost=1 -> (move'=1); |
|||
endmodule |
|||
|
|||
module nativeModule |
|||
[wait] move=1 & !(shortcut=1) -> (move'=0); |
|||
[shortcutBad] move=1 & shortcut=1 -> 0.9: (shortcut'=0) & (target'=1) & (move'=0) + 0.1: (shortcut'=0) & (lost'=1) & (move'=0); |
|||
[shortcutGood] move=1 & shortcut=1 -> (shortcut'=0) & (target'=1) & (move'=0); |
|||
endmodule |
@ -0,0 +1,61 @@ |
|||
// PRISM Model of a simple robot game |
|||
// - A player - friendlyRobot - moves around and tries not to "crash" with another player - adversary Robot. |
|||
// - friendlyRobot can choose the direction of movement. |
|||
// - adversaryRobot should move in a circle counterclockwise on the grid, but has a probabilty to fail and move into the wrong direction. |
|||
// - The movement of adversaryRobot is defined as a pseudo random movement with probabilty = 1/4 into one of the 4 possible directions. |
|||
|
|||
smg |
|||
|
|||
player friendlyRobot |
|||
[e1], [w1], [n1], [s1] |
|||
endplayer |
|||
|
|||
player adversaryRobot |
|||
[e2], [w2], [n2], [s2], [middle] |
|||
endplayer |
|||
|
|||
// 3x3 grid |
|||
const int width = 2; |
|||
const int height = 2; |
|||
|
|||
const int xmin = 0; |
|||
const int xmax = width; |
|||
const int ymin = 0; |
|||
const int ymax = height; |
|||
|
|||
// probabilty to fail |
|||
const double failProb = 1/10; |
|||
const double notFailProb = 1-failProb; |
|||
|
|||
// definition of randomProb, this has to be 0.25 since it is the prob of go into one direction from the middle for the adverseryRobot |
|||
const double randomProb = 1/4; |
|||
|
|||
global move : [0..1] init 0; |
|||
|
|||
//F__ |
|||
//___ |
|||
//__R |
|||
|
|||
label "crash" = x1=x2 & y1=y2; |
|||
|
|||
module robot1 |
|||
x1 : [0..width] init 0; |
|||
y1 : [0..height] init 0; |
|||
|
|||
[e1] move=0 & x1<xmax -> (x1'=x1+1) & (move'=1); |
|||
[w1] move=0 & x1>0 -> (x1'=x1-1) & (move'=1); |
|||
[n1] move=0 & y1>0 -> (y1'=y1-1) & (move'=1); |
|||
[s1] move=0 & y1<ymax -> (y1'=y1+1) & (move'=1); |
|||
endmodule |
|||
|
|||
module robot2 |
|||
x2 : [0..width] init width; |
|||
y2 : [0..height] init height; |
|||
|
|||
[e2] move=1 & x2<xmax & y2=ymax -> notFailProb : (x2'=x2+1) & (move'=0) + failProb : (y2'=y2-1) & (move'=0); |
|||
[w2] move=1 & x2>0 & y2=0 -> notFailProb : (x2'=x2-1) & (move'=0) + failProb : (y2'=y2+1) & (move'=0); |
|||
[n2] move=1 & x2=xmax & y2>0 -> notFailProb : (y2'=y2-1) & (move'=0) + failProb : (x2'=x2-1) & (move'=0); |
|||
[s2] move=1 & x2=0 & y2<ymax -> notFailProb : (y2'=y2+1) & (move'=0) + failProb : (x2'=x2+1) & (move'=0); |
|||
|
|||
[middle] move=1 & x2=1 & y2=1 -> randomProb : (x2'=x2+1) & (move'=0) + randomProb : (x2'=x2-1) & (move'=0) + randomProb : (y2'=y2-1) & (move'=0) + randomProb : (y2'=y2+1) & (move'=0); |
|||
endmodule |
@ -0,0 +1,29 @@ |
|||
smg |
|||
|
|||
player walker |
|||
[a0], [a00], [a1], [a2], [a3] |
|||
endplayer |
|||
|
|||
player blocker |
|||
[a40], [a41] |
|||
endplayer |
|||
|
|||
label "s0" = c=0 & b=0 & a=0; |
|||
label "s1" = c=0 & b=0 & a=1; |
|||
label "s2" = c=0 & b=1 & a=0; |
|||
label "s3" = c=0 & b=1 & a=1; |
|||
label "s4" = c=1 & b=0 & a=0; |
|||
|
|||
module transitions |
|||
a : [0..1] init 0; |
|||
b : [0..1] init 0; |
|||
c : [0..1] init 0; |
|||
|
|||
[a0] a=0 & b=0 & c=0 -> 4/10 : (a'=1) + 6/10 : (b'=1); |
|||
[a00] a=0 & b=0 & c=0 -> true; |
|||
[a1] a=1 & b=0 & c=0 -> 3/10 : (a'=0) + 3/10 : (a'=0) & (b'=1) + 4/10 : (b'=1); |
|||
[a2] a=0 & b=1 & c=0 -> 2/10 : (a'=1) + 8/10 : (b'=0) & (c'=1); |
|||
[a3] a=1 & b=1 & c=0 -> true; |
|||
[a40] a=0 & b=0 & c=1 -> 3/10 : (c'=0) + 7/10 : (a'=1) & (b'=1) & (c'=0); |
|||
[a41] a=0 & b=0 & c=1 -> true; |
|||
endmodule |
@ -0,0 +1,198 @@ |
|||
#include <io/file.h>
|
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/api/builder.h"
|
|||
#include "storm-parsers/api/model_descriptions.h"
|
|||
#include "storm/api/properties.h"
|
|||
#include "storm-parsers/api/properties.h"
|
|||
|
|||
#include "storm/models/sparse/Smg.h"
|
|||
#include "storm/modelchecker/prctl/SparseMdpPrctlModelChecker.h"
|
|||
#include "storm/modelchecker/results/QuantitativeCheckResult.h"
|
|||
#include "storm/modelchecker/results/QualitativeCheckResult.h"
|
|||
#include "storm/environment/solver/MinMaxSolverEnvironment.h"
|
|||
#include "storm/environment/solver/TopologicalSolverEnvironment.h"
|
|||
#include "storm/environment/solver/MultiplierEnvironment.h"
|
|||
#include "storm/settings/modules/CoreSettings.h"
|
|||
#include "storm/logic/Formulas.h"
|
|||
#include "storm/exceptions/UncheckedRequirementException.h"
|
|||
|
|||
namespace { |
|||
class DoubleViEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-8)); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
template<typename TestType> |
|||
class ShieldGenerationMdpPrctlModelCheckerTest : public ::testing::Test { |
|||
public: |
|||
typedef typename TestType::ValueType ValueType; |
|||
ShieldGenerationMdpPrctlModelCheckerTest() : _environment(TestType::createEnvironment()) {} |
|||
storm::Environment const& env() const { return _environment; } |
|||
|
|||
std::pair<std::shared_ptr<storm::models::sparse::Mdp<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>> buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const { |
|||
std::pair<std::shared_ptr<storm::models::sparse::Mdp<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result; |
|||
storm::prism::Program program = storm::api::parseProgram(pathToPrismFile); |
|||
program = storm::utility::prism::preprocess(program, constantDefinitionString); |
|||
result.second = storm::api::extractFormulasFromProperties(storm::api::parsePropertiesForPrismProgram(formulasAsString, program)); |
|||
result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<storm::models::sparse::Mdp<ValueType>>(); |
|||
return result; |
|||
} |
|||
|
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) const { |
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result; |
|||
for (auto const& f : formulas) { |
|||
result.emplace_back(*f); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
ValueType parseNumber(std::string const& input) const { return storm::utility::convertNumber<ValueType>(input);} |
|||
|
|||
void convertShieldingFileToString(std::string filename, std::string &shieldingString) { |
|||
filename += shieldFiletype; |
|||
std::ifstream resultFile(filename); |
|||
std::stringstream resultBuffer; |
|||
resultBuffer << resultFile.rdbuf(); |
|||
shieldingString = resultBuffer.str(); |
|||
} |
|||
|
|||
void getStringsToCompare(std::string filename, std::string &shieldingString, std::string &compareFileString) { |
|||
this->convertShieldingFileToString(filename, shieldingString); |
|||
std::string compareFileName = STORM_TEST_RESOURCES_DIR "/shields/mdp-shields/" + filename; |
|||
this->convertShieldingFileToString(compareFileName, compareFileString); |
|||
filename += shieldFiletype; |
|||
std::remove(filename.c_str()); |
|||
} |
|||
|
|||
private: |
|||
storm::Environment _environment; |
|||
std::string shieldFiletype = ".shield"; |
|||
}; |
|||
|
|||
typedef ::testing::Types< |
|||
DoubleViEnvironment |
|||
> TestingTypes; |
|||
|
|||
TYPED_TEST_SUITE(ShieldGenerationMdpPrctlModelCheckerTest, TestingTypes,); |
|||
|
|||
TYPED_TEST(ShieldGenerationMdpPrctlModelCheckerTest, DieSelection) { |
|||
typedef typename TestFixture::ValueType ValueType; |
|||
|
|||
// definition of shield file names
|
|||
std::vector<std::string> fileNames; |
|||
fileNames.push_back("dieSelectionPreSafetylambda08Pmax"); |
|||
fileNames.push_back("dieSelectionPreSafetygamma08Pmax"); |
|||
fileNames.push_back("dieSelectionPreSafetylambda08Pmin"); |
|||
fileNames.push_back("dieSelectionPreSafetygamma08Pmin"); |
|||
|
|||
fileNames.push_back("dieSelectionPostSafetylambda07Pmax"); |
|||
fileNames.push_back("dieSelectionPostSafetygamma07Pmax"); |
|||
fileNames.push_back("dieSelectionPostSafetylambda07Pmin"); |
|||
fileNames.push_back("dieSelectionPostSafetygamma07Pmin"); |
|||
|
|||
// testing create shielding expressions
|
|||
std::string formulasString = "<" + fileNames[0] + ", PreSafety, lambda=0.8> Pmax=? [ F <5 \"done\" ]"; |
|||
formulasString += "; <" + fileNames[1] + ", PreSafety, gamma=0.8> Pmax=? [ F <5 \"done\" ]"; |
|||
formulasString += "; <" + fileNames[2] + ", PreSafety, lambda=0.8> Pmin=? [ F <5 \"done\" ]"; |
|||
formulasString += "; <" + fileNames[3] + ", PreSafety, gamma=0.8> Pmin=? [ F <5 \"done\" ]"; |
|||
|
|||
formulasString += "; <" + fileNames[4] + ", PostSafety, lambda=0.7> Pmax=? [ F <6 \"two\" ]"; |
|||
formulasString += "; <" + fileNames[5] + ", PostSafety, gamma=0.7> Pmax=? [ F <6 \"two\" ]"; |
|||
formulasString += "; <" + fileNames[6] + ", PostSafety, lambda=0.7> Pmin=? [ F <6 \"two\" ]"; |
|||
formulasString += "; <" + fileNames[7] + ", PostSafety, gamma=0.7> Pmin=? [ F <6 \"two\" ]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/mdp/die_selection.nm", formulasString); |
|||
auto mdp = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(13ul, mdp->getNumberOfStates()); |
|||
EXPECT_EQ(48ul, mdp->getNumberOfTransitions()); |
|||
ASSERT_EQ(mdp->getType(), storm::models::ModelType::Mdp); |
|||
EXPECT_EQ(27ul, mdp->getNumberOfChoices()); |
|||
|
|||
storm::modelchecker::SparseMdpPrctlModelChecker<storm::models::sparse::Mdp<ValueType>> checker(*mdp); |
|||
|
|||
// definitions
|
|||
storm::logic::ShieldingType typePreSafety = storm::logic::ShieldingType::PreSafety; |
|||
storm::logic::ShieldingType typePostSafety = storm::logic::ShieldingType::PostSafety; |
|||
storm::logic::ShieldComparison comparisonRelative = storm::logic::ShieldComparison::Relative; |
|||
storm::logic::ShieldComparison comparisonAbsolute = storm::logic::ShieldComparison::Absolute; |
|||
double value08 = 0.8; |
|||
double value07 = 0.7; |
|||
std::string filename, shieldingString, compareFileString; |
|||
|
|||
// shielding results
|
|||
filename = fileNames[0]; |
|||
auto preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value08)); |
|||
tasks[0].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[0].isShieldingTask()); |
|||
auto result = checker.check(this->env(), tasks[0]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[1]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value08)); |
|||
tasks[1].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[1].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[1]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[2]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value08)); |
|||
tasks[2].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[2].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[2]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[3]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value08)); |
|||
tasks[3].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[3].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[3]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[4]; |
|||
auto postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value07)); |
|||
tasks[4].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[4].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[4]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[5]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value07)); |
|||
tasks[5].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[5].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[5]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[6]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value07)); |
|||
tasks[6].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[6].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[6]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[7]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value07)); |
|||
tasks[7].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[7].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[7]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
} |
|||
|
|||
// TODO: create more test cases (files)
|
|||
} |
@ -0,0 +1,280 @@ |
|||
#include <io/file.h>
|
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/api/builder.h"
|
|||
#include "storm-parsers/api/model_descriptions.h"
|
|||
#include "storm/api/properties.h"
|
|||
#include "storm-parsers/api/properties.h"
|
|||
|
|||
#include "storm/models/sparse/Smg.h"
|
|||
#include "storm/modelchecker/rpatl/SparseSmgRpatlModelChecker.h"
|
|||
#include "storm/modelchecker/results/QuantitativeCheckResult.h"
|
|||
#include "storm/modelchecker/results/QualitativeCheckResult.h"
|
|||
#include "storm/environment/solver/MinMaxSolverEnvironment.h"
|
|||
#include "storm/environment/solver/TopologicalSolverEnvironment.h"
|
|||
#include "storm/environment/solver/MultiplierEnvironment.h"
|
|||
#include "storm/settings/modules/CoreSettings.h"
|
|||
#include "storm/logic/Formulas.h"
|
|||
#include "storm/exceptions/UncheckedRequirementException.h"
|
|||
|
|||
namespace { |
|||
class DoubleViEnvironment { |
|||
public: |
|||
typedef double ValueType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-8)); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
template<typename TestType> |
|||
class ShieldGenerationSmgRpatlModelCheckerTest : public ::testing::Test { |
|||
public: |
|||
typedef typename TestType::ValueType ValueType; |
|||
ShieldGenerationSmgRpatlModelCheckerTest() : _environment(TestType::createEnvironment()) {} |
|||
storm::Environment const& env() const { return _environment; } |
|||
|
|||
std::pair<std::shared_ptr<storm::models::sparse::Smg<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>> buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const { |
|||
std::pair<std::shared_ptr<storm::models::sparse::Smg<ValueType>>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result; |
|||
storm::prism::Program program = storm::api::parseProgram(pathToPrismFile); |
|||
program = storm::utility::prism::preprocess(program, constantDefinitionString); |
|||
result.second = storm::api::extractFormulasFromProperties(storm::api::parsePropertiesForPrismProgram(formulasAsString, program)); |
|||
result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<storm::models::sparse::Smg<ValueType>>(); |
|||
return result; |
|||
} |
|||
|
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) const { |
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result; |
|||
for (auto const& f : formulas) { |
|||
result.emplace_back(*f); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
ValueType parseNumber(std::string const& input) const { return storm::utility::convertNumber<ValueType>(input);} |
|||
|
|||
void convertShieldingFileToString(std::string filename, std::string &shieldingString) { |
|||
filename += shieldFiletype; |
|||
std::ifstream resultFile(filename); |
|||
std::stringstream resultBuffer; |
|||
resultBuffer << resultFile.rdbuf(); |
|||
shieldingString = resultBuffer.str(); |
|||
} |
|||
|
|||
void getStringsToCompare(std::string filename, std::string &shieldingString, std::string &compareFileString) { |
|||
this->convertShieldingFileToString(filename, shieldingString); |
|||
std::string compareFileName = STORM_TEST_RESOURCES_DIR "/shields/smg-shields/" + filename; |
|||
this->convertShieldingFileToString(compareFileName, compareFileString); |
|||
filename += shieldFiletype; |
|||
std::remove(filename.c_str()); |
|||
} |
|||
|
|||
|
|||
private: |
|||
storm::Environment _environment; |
|||
std::string shieldFiletype = ".shield"; |
|||
}; |
|||
|
|||
typedef ::testing::Types< |
|||
DoubleViEnvironment |
|||
> TestingTypes; |
|||
|
|||
TYPED_TEST_SUITE(ShieldGenerationSmgRpatlModelCheckerTest, TestingTypes,); |
|||
|
|||
TYPED_TEST(ShieldGenerationSmgRpatlModelCheckerTest, RightDecision) { |
|||
typedef typename TestFixture::ValueType ValueType; |
|||
|
|||
// definition of shield file names
|
|||
std::vector<std::string> fileNames; |
|||
fileNames.push_back("rightDecisionPreSafetyLambda09PmaxF3"); |
|||
fileNames.push_back("rightDecisionPreSafetyLambda09PminF3"); |
|||
fileNames.push_back("rightDecisionPreSafetyGamma09PmaxF3"); |
|||
fileNames.push_back("rightDecisionPreSafetyGamma09PminF3"); |
|||
fileNames.push_back("rightDecisionPostSafetyLambda09PmaxF3"); |
|||
fileNames.push_back("rightDecisionPostSafetyLambda09PminF3"); |
|||
fileNames.push_back("rightDecisionPostSafetyGamma09PmaxF3"); |
|||
fileNames.push_back("rightDecisionPostSafetyGamma09PminF3"); |
|||
fileNames.push_back("rightDecisionPreSafetyLambda05PmaxF5"); |
|||
fileNames.push_back("rightDecisionPreSafetyLambda05PminF5"); |
|||
fileNames.push_back("rightDecisionPreSafetyGamma05PmaxF5"); |
|||
fileNames.push_back("rightDecisionPreSafetyGamma05PminF5"); |
|||
fileNames.push_back("rightDecisionPostSafetyLambda05PmaxF5"); |
|||
fileNames.push_back("rightDecisionPostSafetyLambda05PminF5"); |
|||
fileNames.push_back("rightDecisionPostSafetyGamma05PmaxF5"); |
|||
fileNames.push_back("rightDecisionPostSafetyGamma05PminF5"); |
|||
|
|||
// testing create shielding expressions
|
|||
std::string formulasString = "<" + fileNames[0] + ", PreSafety, lambda=0.9> <<hiker>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[1] + ", PreSafety, lambda=0.9> <<hiker>> Pmin=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[2] + ", PreSafety, gamma=0.9> <<hiker>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[3] + ", PreSafety, gamma=0.9> <<hiker>> Pmin=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[4] + ", PostSafety, lambda=0.9> <<hiker>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[5] + ", PostSafety, lambda=0.9> <<hiker>> Pmin=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[6] + ", PostSafety, gamma=0.9> <<hiker>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[7] + ", PostSafety, gamma=0.9> <<hiker>> Pmin=? [ F <=3 \"target\" ]"; |
|||
|
|||
formulasString += "; <" + fileNames[8] + ", PreSafety, lambda=0.5> <<hiker>> Pmax=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[9] + ", PreSafety, lambda=0.5> <<hiker>> Pmin=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[10] + ", PreSafety, gamma=0.5> <<hiker>> Pmax=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[11] + ", PreSafety, gamma=0.5> <<hiker>> Pmin=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[12] + ", PostSafety, lambda=0.5> <<hiker>> Pmax=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[13] + ", PostSafety, lambda=0.5> <<hiker>> Pmin=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[14] + ", PostSafety, gamma=0.5> <<hiker>> Pmax=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <" + fileNames[15] + ", PostSafety, gamma=0.5> <<hiker>> Pmin=? [ F <=5 \"target\" ]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/smg/rightDecision.nm", formulasString); |
|||
auto smg = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(11ul, smg->getNumberOfStates()); |
|||
EXPECT_EQ(15ul, smg->getNumberOfTransitions()); |
|||
ASSERT_EQ(smg->getType(), storm::models::ModelType::Smg); |
|||
EXPECT_EQ(14ull, smg->getNumberOfChoices()); |
|||
|
|||
//std::unique_ptr<storm::modelchecker::CheckResult> result;
|
|||
storm::modelchecker::SparseSmgRpatlModelChecker<storm::models::sparse::Smg<ValueType>> checker(*smg); |
|||
|
|||
// definitions
|
|||
storm::logic::ShieldingType typePreSafety = storm::logic::ShieldingType::PreSafety; |
|||
storm::logic::ShieldingType typePostSafety = storm::logic::ShieldingType::PostSafety; |
|||
storm::logic::ShieldComparison comparisonRelative = storm::logic::ShieldComparison::Relative; |
|||
storm::logic::ShieldComparison comparisonAbsolute = storm::logic::ShieldComparison::Absolute; |
|||
double value09 = 0.9; |
|||
double value05 = 0.5; |
|||
std::string filename, shieldingString, compareFileString; |
|||
|
|||
// shielding results
|
|||
filename = fileNames[0]; |
|||
auto preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value09)); |
|||
tasks[0].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[0].isShieldingTask()); |
|||
auto result = checker.check(this->env(), tasks[0]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[1]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value09)); |
|||
tasks[1].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[1].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[1]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[2]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value09)); |
|||
tasks[2].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[2].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[2]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[3]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value09)); |
|||
tasks[3].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[3].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[3]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[4]; |
|||
auto postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value09)); |
|||
tasks[4].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[4].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[4]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[5]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value09)); |
|||
tasks[5].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[5].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[5]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[6]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value09)); |
|||
tasks[6].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[6].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[6]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[7]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value09)); |
|||
tasks[7].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[7].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[7]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
|
|||
filename = fileNames[8]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value05)); |
|||
tasks[8].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[8].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[8]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[9]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonRelative, value05)); |
|||
tasks[9].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[9].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[9]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[10]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value05)); |
|||
tasks[10].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[10].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[10]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[11]; |
|||
preSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePreSafety, filename, comparisonAbsolute, value05)); |
|||
tasks[11].setShieldingExpression(preSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[11].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[11]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[12]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value05)); |
|||
tasks[12].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[12].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[12]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[13]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonRelative, value05)); |
|||
tasks[13].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[13].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[13]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[14]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value05)); |
|||
tasks[14].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[14].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[14]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
|
|||
filename = fileNames[15]; |
|||
postSafetyShieldingExpression = std::shared_ptr<storm::logic::ShieldExpression>(new storm::logic::ShieldExpression(typePostSafety, filename, comparisonAbsolute, value05)); |
|||
tasks[15].setShieldingExpression(postSafetyShieldingExpression); |
|||
EXPECT_TRUE(tasks[15].isShieldingTask()); |
|||
result = checker.check(this->env(), tasks[15]); |
|||
this->getStringsToCompare(filename, shieldingString, compareFileString); |
|||
EXPECT_EQ(shieldingString, compareFileString); |
|||
} |
|||
|
|||
// TODO: create more test cases (files)
|
|||
} |
@ -0,0 +1,351 @@ |
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-config.h"
|
|||
|
|||
#include "storm/api/builder.h"
|
|||
#include "storm-parsers/api/model_descriptions.h"
|
|||
#include "storm/api/properties.h"
|
|||
#include "storm-parsers/api/properties.h"
|
|||
|
|||
#include "storm/models/sparse/Smg.h"
|
|||
#include "storm/modelchecker/rpatl/SparseSmgRpatlModelChecker.h"
|
|||
#include "storm/modelchecker/results/QuantitativeCheckResult.h"
|
|||
#include "storm/modelchecker/results/ExplicitQualitativeCheckResult.h"
|
|||
#include "storm/modelchecker/results/QualitativeCheckResult.h"
|
|||
#include "storm/environment/solver/MinMaxSolverEnvironment.h"
|
|||
#include "storm/environment/solver/TopologicalSolverEnvironment.h"
|
|||
#include "storm/environment/solver/MultiplierEnvironment.h"
|
|||
#include "storm/settings/modules/CoreSettings.h"
|
|||
#include "storm/logic/Formulas.h"
|
|||
#include "storm/exceptions/UncheckedRequirementException.h"
|
|||
|
|||
namespace { |
|||
|
|||
enum class SmgEngine {PrismSparse}; |
|||
|
|||
class SparseDoubleValueIterationGmmxxGaussSeidelMultEnvironment { |
|||
public: |
|||
static const SmgEngine engine = SmgEngine::PrismSparse; |
|||
static const bool isExact = false; |
|||
typedef double ValueType; |
|||
typedef storm::models::sparse::Smg<ValueType> ModelType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-10)); |
|||
env.solver().minMax().setMultiplicationStyle(storm::solver::MultiplicationStyle::GaussSeidel); |
|||
env.solver().multiplier().setType(storm::solver::MultiplierType::Gmmxx); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
class SparseDoubleValueIterationGmmxxRegularMultEnvironment { |
|||
public: |
|||
static const SmgEngine engine = SmgEngine::PrismSparse; |
|||
static const bool isExact = false; |
|||
typedef double ValueType; |
|||
typedef storm::models::sparse::Smg<ValueType> ModelType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-10)); |
|||
env.solver().minMax().setMultiplicationStyle(storm::solver::MultiplicationStyle::Regular); |
|||
env.solver().multiplier().setType(storm::solver::MultiplierType::Gmmxx); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
class SparseDoubleValueIterationNativeGaussSeidelMultEnvironment { |
|||
public: |
|||
static const SmgEngine engine = SmgEngine::PrismSparse; |
|||
static const bool isExact = false; |
|||
typedef double ValueType; |
|||
typedef storm::models::sparse::Smg<ValueType> ModelType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-10)); |
|||
env.solver().minMax().setMultiplicationStyle(storm::solver::MultiplicationStyle::GaussSeidel); |
|||
env.solver().multiplier().setType(storm::solver::MultiplierType::Native); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
class SparseDoubleValueIterationNativeRegularMultEnvironment { |
|||
public: |
|||
static const SmgEngine engine = SmgEngine::PrismSparse; |
|||
static const bool isExact = false; |
|||
typedef double ValueType; |
|||
typedef storm::models::sparse::Smg<ValueType> ModelType; |
|||
static storm::Environment createEnvironment() { |
|||
storm::Environment env; |
|||
env.solver().minMax().setMethod(storm::solver::MinMaxMethod::ValueIteration); |
|||
env.solver().minMax().setPrecision(storm::utility::convertNumber<storm::RationalNumber>(1e-10)); |
|||
env.solver().minMax().setMultiplicationStyle(storm::solver::MultiplicationStyle::Regular); |
|||
env.solver().multiplier().setType(storm::solver::MultiplierType::Native); |
|||
return env; |
|||
} |
|||
}; |
|||
|
|||
template<typename TestType> |
|||
class SmgRpatlModelCheckerTest : public ::testing::Test { |
|||
public: |
|||
typedef typename TestType::ValueType ValueType; |
|||
typedef typename storm::models::sparse::Smg<ValueType> SparseModelType; |
|||
|
|||
SmgRpatlModelCheckerTest() : _environment(TestType::createEnvironment()) {} |
|||
storm::Environment const& env() const { return _environment; } |
|||
ValueType parseNumber(std::string const& input) const { return storm::utility::convertNumber<ValueType>(input);} |
|||
ValueType precision() const { return TestType::isExact ? parseNumber("0") : parseNumber("1e-6");} |
|||
bool isSparseModel() const { return std::is_same<typename TestType::ModelType, SparseModelType>::value; } |
|||
|
|||
template <typename MT = typename TestType::ModelType> |
|||
typename std::enable_if<std::is_same<MT, SparseModelType>::value, std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>>>::type |
|||
buildModelFormulas(std::string const& pathToPrismFile, std::string const& formulasAsString, std::string const& constantDefinitionString = "") const { |
|||
std::pair<std::shared_ptr<MT>, std::vector<std::shared_ptr<storm::logic::Formula const>>> result; |
|||
storm::prism::Program program = storm::api::parseProgram(pathToPrismFile); |
|||
program = storm::utility::prism::preprocess(program, constantDefinitionString); |
|||
if (TestType::engine == SmgEngine::PrismSparse) { |
|||
result.second = storm::api::extractFormulasFromProperties(storm::api::parsePropertiesForPrismProgram(formulasAsString, program)); |
|||
result.first = storm::api::buildSparseModel<ValueType>(program, result.second)->template as<MT>(); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> getTasks(std::vector<std::shared_ptr<storm::logic::Formula const>> const& formulas) const { |
|||
std::vector<storm::modelchecker::CheckTask<storm::logic::Formula, ValueType>> result; |
|||
for (auto const& f : formulas) { |
|||
result.emplace_back(*f); |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
template <typename MT = typename TestType::ModelType> |
|||
typename std::enable_if<std::is_same<MT, SparseModelType>::value, std::shared_ptr<storm::modelchecker::AbstractModelChecker<MT>>>::type |
|||
createModelChecker(std::shared_ptr<MT> const& model) const { |
|||
if (TestType::engine == SmgEngine::PrismSparse) { |
|||
return std::make_shared<storm::modelchecker::SparseSmgRpatlModelChecker<SparseModelType>>(*model); |
|||
} else { |
|||
STORM_LOG_ERROR("TestType::engine must be PrismSparse!"); |
|||
return nullptr; |
|||
} |
|||
} |
|||
|
|||
ValueType getQuantitativeResultAtInitialState(std::shared_ptr<storm::models::Model<ValueType>> const& model, std::unique_ptr<storm::modelchecker::CheckResult>& result) { |
|||
auto filter = getInitialStateFilter(model); |
|||
result->filter(*filter); |
|||
return result->asQuantitativeCheckResult<ValueType>().getMin(); |
|||
} |
|||
|
|||
private: |
|||
storm::Environment _environment; |
|||
|
|||
std::unique_ptr<storm::modelchecker::QualitativeCheckResult> getInitialStateFilter(std::shared_ptr<storm::models::Model<ValueType>> const& model) const { |
|||
if (isSparseModel()) { |
|||
return std::make_unique<storm::modelchecker::ExplicitQualitativeCheckResult>(model->template as<SparseModelType>()->getInitialStates()); |
|||
} else { |
|||
STORM_LOG_ERROR("Smg Rpatl Model must be a Sparse Model!"); |
|||
return nullptr; |
|||
} |
|||
} |
|||
}; |
|||
|
|||
typedef ::testing::Types< |
|||
SparseDoubleValueIterationGmmxxGaussSeidelMultEnvironment, |
|||
SparseDoubleValueIterationGmmxxRegularMultEnvironment, |
|||
SparseDoubleValueIterationNativeGaussSeidelMultEnvironment, |
|||
SparseDoubleValueIterationNativeRegularMultEnvironment |
|||
> TestingTypes; |
|||
|
|||
TYPED_TEST_SUITE(SmgRpatlModelCheckerTest, TestingTypes,); |
|||
|
|||
TYPED_TEST(SmgRpatlModelCheckerTest, Walker) { |
|||
// NEXT tests
|
|||
std::string formulasString = "<<walker>> Pmax=? [X \"s2\"]"; |
|||
formulasString += "; <<walker>> Pmin=? [X \"s2\"]"; |
|||
formulasString += "; <<walker>> Pmax=? [X !\"s1\"]"; |
|||
formulasString += "; <<walker>> Pmin=? [X !\"s1\"]"; |
|||
// UNTIL tests
|
|||
formulasString += "; <<walker>> Pmax=? [ a=0 U a=1 ]"; |
|||
formulasString += "; <<walker>> Pmin=? [ a=0 U a=1 ]"; |
|||
formulasString += "; <<walker>> Pmax=? [ b=0 U b=1 ]"; |
|||
formulasString += "; <<walker>> Pmin=? [ b=0 U b=1 ]"; |
|||
// GLOBALLY tests
|
|||
formulasString += "; <<walker>> Pmax=? [G !\"s3\"]"; |
|||
formulasString += "; <<walker>> Pmin=? [G !\"s3\"]"; |
|||
formulasString += "; <<walker>> Pmax=? [G a=0 ]"; |
|||
formulasString += "; <<walker>> Pmin=? [G a=0 ]"; |
|||
// EVENTUALLY tests
|
|||
formulasString += "; <<walker>> Pmax=? [F \"s3\"]"; |
|||
formulasString += "; <<walker>> Pmin=? [F \"s3\"]"; |
|||
formulasString += "; <<walker>> Pmax=? [F [3,4] \"s4\"]"; |
|||
formulasString += "; <<walker>> Pmax=? [F [3,5] \"s4\"]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/smg/walker.nm", formulasString); |
|||
auto model = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(5ul, model->getNumberOfStates()); |
|||
EXPECT_EQ(12ul, model->getNumberOfTransitions()); |
|||
ASSERT_EQ(model->getType(), storm::models::ModelType::Smg); |
|||
auto checker = this->createModelChecker(model); |
|||
std::unique_ptr<storm::modelchecker::CheckResult> result; |
|||
|
|||
// NEXT results
|
|||
result = checker->check(this->env(), tasks[0]); |
|||
EXPECT_NEAR(this->parseNumber("0.6"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[1]); |
|||
EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[2]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[3]); |
|||
EXPECT_NEAR(this->parseNumber("0.6"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
|
|||
// UNTIL results
|
|||
result = checker->check(this->env(), tasks[4]); |
|||
EXPECT_NEAR(this->parseNumber("0.52"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[5]); |
|||
EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[6]); |
|||
EXPECT_NEAR(this->parseNumber("0.9999996417"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[7]); |
|||
EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
|
|||
// GLOBALLY tests
|
|||
result = checker->check(this->env(), tasks[8]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[9]); |
|||
EXPECT_NEAR(this->parseNumber("0.65454565"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[10]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[11]); |
|||
EXPECT_NEAR(this->parseNumber("0.48"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
|
|||
// EVENTUALLY tests
|
|||
result = checker->check(this->env(), tasks[12]); |
|||
EXPECT_NEAR(this->parseNumber("0.34545435"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[13]); |
|||
EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[14]); |
|||
EXPECT_NEAR(this->parseNumber("0.576"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[15]); |
|||
EXPECT_NEAR(this->parseNumber("0.6336"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
} |
|||
|
|||
TYPED_TEST(SmgRpatlModelCheckerTest, MessageHack) { |
|||
// This test is for borders of bounded U with conversations from G and F
|
|||
// G
|
|||
std::string formulasString = "<<bob, alice>> Pmax=? [ G !\"hacked\" ]"; |
|||
|
|||
// bounded F
|
|||
formulasString += "; <<bob, alice>> Pmin=? [ F \"hacked\" ]"; |
|||
formulasString += "; <<bob, alice>> Pmin=? [ F [1,2] \"hacked\" ]"; |
|||
formulasString += "; <<bob, alice>> Pmin=? [ F [3,16] \"hacked\" ]"; |
|||
formulasString += "; <<bob, alice>> Pmin=? [ F [0,17] \"hacked\" ]"; |
|||
formulasString += "; <<bob, alice>> Pmin=? [ F [17,31] \"hacked\" ]"; |
|||
formulasString += "; <<bob, alice>> Pmin=? [ F [17,32] \"hacked\" ]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/smg/messageHack.nm", formulasString); |
|||
auto model = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(30ul, model->getNumberOfStates()); |
|||
EXPECT_EQ(31ul, model->getNumberOfTransitions()); |
|||
ASSERT_EQ(model->getType(), storm::models::ModelType::Smg); |
|||
auto checker = this->createModelChecker(model); |
|||
std::unique_ptr<storm::modelchecker::CheckResult> result; |
|||
|
|||
// G results
|
|||
result = checker->check(this->env(), tasks[0]); |
|||
EXPECT_NEAR(this->parseNumber("1.99379598e-05"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
|
|||
// bounded F results
|
|||
result = checker->check(this->env(), tasks[1]); |
|||
EXPECT_NEAR(this->parseNumber("0.999980062"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[2]); |
|||
EXPECT_NEAR(this->parseNumber("0.05"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[3]); |
|||
EXPECT_NEAR(this->parseNumber("0.05"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[4]); |
|||
EXPECT_NEAR(this->parseNumber("0.0975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[5]); |
|||
EXPECT_NEAR(this->parseNumber("0.0975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[6]); |
|||
EXPECT_NEAR(this->parseNumber("0.142625"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
} |
|||
|
|||
TYPED_TEST(SmgRpatlModelCheckerTest, RightDecision) { |
|||
// This test is for making decisions
|
|||
// testing probabilities for decisions
|
|||
std::string formulasString = "<<hiker>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <<hiker>> Pmax=? [ F <=5 \"target\" ]"; |
|||
formulasString += "; <<hiker, native>> Pmax=? [ F <=3 \"target\" ]"; |
|||
formulasString += "; <<hiker>> Pmin=? [ F \"target\" ]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/smg/rightDecision.nm", formulasString); |
|||
auto model = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(11ul, model->getNumberOfStates()); |
|||
EXPECT_EQ(15ul, model->getNumberOfTransitions()); |
|||
ASSERT_EQ(model->getType(), storm::models::ModelType::Smg); |
|||
auto checker = this->createModelChecker(model); |
|||
std::unique_ptr<storm::modelchecker::CheckResult> result; |
|||
|
|||
// probability results
|
|||
result = checker->check(this->env(), tasks[0]); |
|||
EXPECT_NEAR(this->parseNumber("0.9"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[1]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[2]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[3]); |
|||
EXPECT_NEAR(this->parseNumber("0"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
} |
|||
|
|||
/*
|
|||
TYPED_TEST(SmgRpatlModelCheckerTest, RobotCircle) { |
|||
// This test is for testing bounded globally with upper bound and in an interval (with upper and lower bound)
|
|||
std::string formulasString = " <<friendlyRobot>> Pmax=? [ G<1 !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G<=1 !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G<=5 !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G<=6 !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G<=7 !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G<=8 !\"crash\" ]"; |
|||
|
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G[1,5] !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G[5,6] !\"crash\" ]"; |
|||
formulasString += "; <<friendlyRobot>> Pmax=? [ G[7,8] !\"crash\" ]"; |
|||
|
|||
auto modelFormulas = this->buildModelFormulas(STORM_TEST_RESOURCES_DIR "/smg/robotCircle.nm", formulasString); |
|||
auto model = std::move(modelFormulas.first); |
|||
auto tasks = this->getTasks(modelFormulas.second); |
|||
EXPECT_EQ(81ul, model->getNumberOfStates()); |
|||
EXPECT_EQ(196ul, model->getNumberOfTransitions()); |
|||
EXPECT_EQ(148ul, model->getNumberOfChoices()); |
|||
ASSERT_EQ(model->getType(), storm::models::ModelType::Smg); |
|||
auto checker = this->createModelChecker(model); |
|||
std::unique_ptr<storm::modelchecker::CheckResult> result; |
|||
|
|||
// results for bounded globally with upper bound
|
|||
result = checker->check(this->env(), tasks[0]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[1]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[2]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[3]); |
|||
EXPECT_NEAR(this->parseNumber("0.975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[4]); |
|||
EXPECT_NEAR(this->parseNumber("0.975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[5]); |
|||
EXPECT_NEAR(this->parseNumber("0.975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
|
|||
// results for bounded globally with upper and lower bound
|
|||
result = checker->check(this->env(), tasks[6]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[7]); |
|||
EXPECT_NEAR(this->parseNumber("0.975"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
result = checker->check(this->env(), tasks[8]); |
|||
EXPECT_NEAR(this->parseNumber("1"), this->getQuantitativeResultAtInitialState(model, result), this->precision()); |
|||
} |
|||
*/ |
|||
|
|||
// TODO: create more test cases (files)
|
|||
} |
@ -0,0 +1,204 @@ |
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-parsers/parser/FormulaParser.h"
|
|||
#include "storm/logic/FragmentSpecification.h"
|
|||
#include "storm/storage/expressions/ExpressionManager.h"
|
|||
|
|||
TEST(GameFormulaParserTest, OnePlayerCoalitionTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string player = "p1"; |
|||
std::string input = "<<" + player + ">>" + " Pmax=? [F \"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
|
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
auto const& playerCoalition = formula->asGameFormula().getCoalition(); |
|||
std::ostringstream stream; |
|||
stream << playerCoalition; |
|||
std::string playerCoalitionString = stream.str(); |
|||
|
|||
EXPECT_EQ(player, playerCoalitionString); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, PlayersCoalitionTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string player = "p1, p2, p3, p4, p5"; |
|||
std::string input = "<<" + player + ">>" + " Pmin=? [X \"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
|
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
auto const& playerCoalition = formula->asGameFormula().getCoalition(); |
|||
EXPECT_EQ(5ul, playerCoalition.getPlayers().size()); |
|||
|
|||
std::ostringstream stream; |
|||
stream << playerCoalition; |
|||
std::string playerCoalitionString = stream.str(); |
|||
std::string playerWithoutWhiteSpace = "p1,p2,p3,p4,p5"; |
|||
EXPECT_EQ(playerWithoutWhiteSpace, playerCoalitionString); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, ProbabilityOperatorTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "<<player>> Pmax=? [\"a\" U \"b\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
|
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().hasBound()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().hasOptimalityType()); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, NextOperatorTest) { |
|||
std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager()); |
|||
manager->declareBooleanVariable("x"); |
|||
manager->declareIntegerVariable("a"); |
|||
storm::parser::FormulaParser formulaParser(manager); |
|||
|
|||
std::string input = "<<p>> Pmax=? [X \"a\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isNextFormula()); |
|||
|
|||
input = "<<p1, p2, p3>> Pmin=? [X !x ]"; |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isNextFormula()); |
|||
|
|||
input = "<<player1, player2, 3,4,5>> Pmax=? [ X a>5 ]"; |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isNextFormula()); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, UntilOperatorTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "<<p>> Pmax=? [\"a\" U \"b\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isUntilFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isBoundedUntilFormula()); |
|||
|
|||
input = "<<p>> Pmax=? [ \"a\" U <= 4 \"b\" ]"; |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isBoundedUntilFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().getTimeBoundReference().isTimeBound()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().hasLowerBound()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().hasUpperBound()); |
|||
EXPECT_EQ(4, formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().getUpperBound().evaluateAsInt()); |
|||
|
|||
input = "<<p1, p2>> Pmin=? [ \"a\" & \"b\" U [5,9] \"c\" ] "; |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isBoundedUntilFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().getTimeBoundReference().isTimeBound()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().hasLowerBound()); |
|||
EXPECT_EQ(5, formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().getLowerBound().evaluateAsInt()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().hasUpperBound()); |
|||
EXPECT_EQ(9, formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asBoundedUntilFormula().getUpperBound().evaluateAsInt()); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, RewardOperatorTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "<<p1, p2>> Rmin<0.9 [F \"a\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isRewardOperatorFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asRewardOperatorFormula().hasBound()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asRewardOperatorFormula().hasOptimalityType()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
|
|||
input = "<<p1, p2>> R=? [I=10]"; |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isRewardOperatorFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().asRewardOperatorFormula().hasBound()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().asRewardOperatorFormula().hasOptimalityType()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().asRewardOperatorFormula().getSubformula().isInstantaneousRewardFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, ConditionalProbabilityTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "<<p1, p2>> P<0.9 [F \"a\" || F \"b\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
storm::logic::ProbabilityOperatorFormula const& probFormula = formula->asGameFormula().getSubformula().asProbabilityOperatorFormula(); |
|||
EXPECT_TRUE(probFormula.getSubformula().isConditionalProbabilityFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, NestedPathFormulaTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "<<p1, p2, p3>> P<0.9 [F X \"a\"]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
ASSERT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isEventuallyFormula()); |
|||
ASSERT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asEventuallyFormula().getSubformula().isNextFormula()); |
|||
EXPECT_FALSE(formula->asGameFormula().getSubformula().isInFragment(storm::logic::rpatl())); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, CommentTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string input = "// This is a comment. And this is a commented out formula: <<p>> P<=0.5 [ F \"a\" ] The next line contains the actual formula. \n<<p>> P<=0.5 [ X \"b\" ] // Another comment \n // And again: another comment."; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
EXPECT_TRUE(formula->asGameFormula().getSubformula().isProbabilityOperatorFormula()); |
|||
ASSERT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().isNextFormula()); |
|||
ASSERT_TRUE(formula->asGameFormula().getSubformula().asProbabilityOperatorFormula().getSubformula().asNextFormula().getSubformula().isAtomicLabelFormula()); |
|||
} |
|||
|
|||
TEST(GameFormulaParserTest, WrongFormatTest) { |
|||
std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager()); |
|||
manager->declareBooleanVariable("x"); |
|||
manager->declareIntegerVariable("y"); |
|||
|
|||
storm::parser::FormulaParser formulaParser(manager); |
|||
std::string input = "<<p1,p2>> P>0.5 [ a ]"; |
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
STORM_SILENT_EXPECT_THROW(formula = formulaParser.parseSingleFormulaFromString(input), storm::exceptions::WrongFormatException); |
|||
|
|||
input = "<<p>> P=0.5 [F \"a\"]"; |
|||
STORM_SILENT_EXPECT_THROW(formula = formulaParser.parseSingleFormulaFromString(input), storm::exceptions::WrongFormatException); |
|||
|
|||
input = "<<p1, p2>> P>0.5 [F !(x = 0)]"; |
|||
STORM_SILENT_EXPECT_THROW(formula = formulaParser.parseSingleFormulaFromString(input), storm::exceptions::WrongFormatException); |
|||
|
|||
input = "<< p1, p2 >> P>0.5 [F !y]"; |
|||
STORM_SILENT_EXPECT_THROW(formula = formulaParser.parseSingleFormulaFromString(input), storm::exceptions::WrongFormatException); |
|||
|
|||
input = "<< 1,2,3 >> P>0.5 [F y!=0)]"; |
|||
STORM_SILENT_EXPECT_THROW(formula = formulaParser.parseSingleFormulaFromString(input), storm::exceptions::WrongFormatException); |
|||
} |
@ -0,0 +1,81 @@ |
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-parsers/parser/FormulaParser.h"
|
|||
#include "storm/logic/FragmentSpecification.h"
|
|||
#include "storm/storage/expressions/ExpressionManager.h"
|
|||
|
|||
TEST(GameShieldingParserTest, PreSafetyShieldTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string filename = "preSafetyShieldFileName"; |
|||
std::string value = "0.9"; |
|||
std::string input = "<" + filename + ", PreSafety, lambda=" + value + "> <<p1,p2>> Pmax=? [F \"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
|
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_TRUE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isOptimalShield()); |
|||
EXPECT_TRUE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(std::stod(value), shieldExpression->getValue()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
|||
|
|||
TEST(GameShieldingParserTest, PostSafetyShieldTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string filename = "postSafetyShieldFileName"; |
|||
std::string value = "0.7569"; |
|||
std::string input = "<" + filename + ", PostSafety, gamma=" + value + "> <<p1,p2,p3>> Pmin=? [X !\"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
|
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_FALSE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_TRUE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isOptimalShield()); |
|||
EXPECT_FALSE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(std::stod(value), shieldExpression->getValue()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
|||
|
|||
TEST(GameShieldingParserTest, OptimalShieldTest) { |
|||
std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager()); |
|||
manager->declareIntegerVariable("x"); |
|||
manager->declareIntegerVariable("y"); |
|||
|
|||
storm::parser::FormulaParser formulaParser(manager); |
|||
|
|||
std::string filename = "optimalShieldFileName"; |
|||
std::string input = "<" + filename + ", Optimal> <<p1,p2,p3>> Pmax=? [G x>y]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
ASSERT_NO_THROW(formula = formulaParser.parseSingleFormulaFromString(input)); |
|||
EXPECT_TRUE(formula->isGameFormula()); |
|||
|
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_FALSE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_TRUE(shieldExpression->isOptimalShield()); |
|||
EXPECT_FALSE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
@ -0,0 +1,72 @@ |
|||
#include "test/storm_gtest.h"
|
|||
#include "storm-parsers/parser/FormulaParser.h"
|
|||
#include "storm/logic/FragmentSpecification.h"
|
|||
#include "storm/storage/expressions/ExpressionManager.h"
|
|||
|
|||
TEST(MdpShieldingParserTest, PreSafetyShieldTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string filename = "preSafetyShieldFileName"; |
|||
std::string value = "0.6667"; |
|||
std::string input = "<" + filename + ", PreSafety, gamma=" + value + "> Pmax=? [F \"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_TRUE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isOptimalShield()); |
|||
EXPECT_FALSE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(std::stod(value), shieldExpression->getValue()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
|||
|
|||
TEST(MdpShieldingParserTest, PostSafetyShieldTest) { |
|||
storm::parser::FormulaParser formulaParser; |
|||
|
|||
std::string filename = "postSafetyShieldFileName"; |
|||
std::string value = "0.95"; |
|||
std::string input = "<" + filename + ", PostSafety, lambda=" + value + "> Pmin=? [X !\"label\"]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_FALSE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_TRUE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isOptimalShield()); |
|||
EXPECT_TRUE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(std::stod(value), shieldExpression->getValue()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
|||
|
|||
TEST(MdpShieldingParserTest, OptimalShieldTest) { |
|||
std::shared_ptr<storm::expressions::ExpressionManager> manager(new storm::expressions::ExpressionManager()); |
|||
manager->declareBooleanVariable("a"); |
|||
manager->declareIntegerVariable("x"); |
|||
|
|||
storm::parser::FormulaParser formulaParser(manager); |
|||
|
|||
std::string filename = "optimalShieldFileName"; |
|||
std::string input = "<" + filename + ", Optimal> Pmax=? [G (a|x>3)]"; |
|||
|
|||
std::shared_ptr<storm::logic::Formula const> formula(nullptr); |
|||
std::vector<storm::jani::Property> property; |
|||
ASSERT_NO_THROW(property = formulaParser.parseFromString(input)); |
|||
EXPECT_TRUE(property.at(0).isShieldingProperty()); |
|||
|
|||
std::shared_ptr<storm::logic::ShieldExpression const> shieldExpression(nullptr); |
|||
ASSERT_NO_THROW(shieldExpression = property.at(0).getShieldingExpression()); |
|||
EXPECT_FALSE(shieldExpression->isPreSafetyShield()); |
|||
EXPECT_FALSE(shieldExpression->isPostSafetyShield()); |
|||
EXPECT_TRUE(shieldExpression->isOptimalShield()); |
|||
EXPECT_FALSE(shieldExpression->isRelative()); |
|||
EXPECT_EQ(filename, shieldExpression->getFilename()); |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue