Browse Source
fix for approximation model, additional test for mdps, minor changes
fix for approximation model, additional test for mdps, minor changes
Former-commit-id: cc837ddf3e
main
11 changed files with 280 additions and 59 deletions
-
69examples/pmdp/consensus/4pars/coin4_2.nm
-
69examples/pmdp/consensus/4pars/coin4_8.nm
-
45examples/pmdp/two_dice/two_dice.nm
-
12src/modelchecker/region/AbstractSparseRegionModelChecker.cpp
-
1src/modelchecker/region/AbstractSparseRegionModelChecker.h
-
35src/modelchecker/region/ApproximationModel.cpp
-
23src/modelchecker/region/ApproximationModel.h
-
6src/modelchecker/region/SamplingModel.cpp
-
11src/modelchecker/region/SamplingModel.h
-
8test/functional/modelchecker/SparseDtmcRegionModelCheckerTest.cpp
-
60test/functional/modelchecker/SparseMdpRegionModelCheckerTest.cpp
@ -0,0 +1,69 @@ |
|||
// COIN FLIPPING PROTOCOL FOR POLYNOMIAL RANDOMIZED CONSENSUS [AH90] |
|||
// gxn/dxp 20/11/00 |
|||
|
|||
mdp |
|||
|
|||
// constants |
|||
const int N=4; |
|||
const int K=2; |
|||
const int range = 2*(K+1)*N; |
|||
const int counter_init = (K+1)*N; |
|||
const int left = N; |
|||
const int right = 2*(K+1)*N - N; |
|||
|
|||
//Coin Probabilities |
|||
const double p1; |
|||
const double p2; |
|||
const double p3; |
|||
const double p4; |
|||
|
|||
// shared coin |
|||
global counter : [0..range] init counter_init; |
|||
|
|||
module process1 |
|||
|
|||
// program counter |
|||
pc1 : [0..3]; |
|||
// 0 - flip |
|||
// 1 - write |
|||
// 2 - check |
|||
// 3 - finished |
|||
|
|||
// local coin |
|||
coin1 : [0..1]; |
|||
|
|||
// flip coin |
|||
[] (pc1=0) -> p1 : (coin1'=0) & (pc1'=1) + 1-p1 : (coin1'=1) & (pc1'=1); |
|||
// write tails -1 (reset coin to add regularity) |
|||
[] (pc1=1) & (coin1=0) & (counter>0) -> 1 : (counter'=counter-1) & (pc1'=2) & (coin1'=0); |
|||
// write heads +1 (reset coin to add regularity) |
|||
[] (pc1=1) & (coin1=1) & (counter<range) -> 1 : (counter'=counter+1) & (pc1'=2) & (coin1'=0); |
|||
// check |
|||
// decide tails |
|||
[] (pc1=2) & (counter<=left) -> 1 : (pc1'=3) & (coin1'=0); |
|||
// decide heads |
|||
[] (pc1=2) & (counter>=right) -> 1 : (pc1'=3) & (coin1'=1); |
|||
// flip again |
|||
[] (pc1=2) & (counter>left) & (counter<right) -> 1 : (pc1'=0); |
|||
// loop (all loop together when done) |
|||
[done] (pc1=3) -> 1 : (pc1'=3); |
|||
|
|||
endmodule |
|||
|
|||
// construct remaining processes through renaming |
|||
module process2 = process1[pc1=pc2,coin1=coin2,p1=p2] endmodule |
|||
module process3 = process1[pc1=pc3,coin1=coin3,p1=p3] endmodule |
|||
module process4 = process1[pc1=pc4,coin1=coin4,p1=p4] endmodule |
|||
|
|||
// labels |
|||
label "finished" = pc1=3 & pc2=3 & pc3=3 & pc4=3 ; |
|||
label "all_coins_equal_0" = coin1=0 & coin2=0 & coin3=0 & coin4=0 ; |
|||
label "all_coins_equal_1" = coin1=1 & coin2=1 & coin3=1 & coin4=1 ; |
|||
label "agree" = coin1=coin2 & coin2=coin3 & coin3=coin4 ; |
|||
label "finish_with_1" = pc1=3 & pc2=3 & pc3=3 & pc4=3 & coin1=1 & coin2=1 & coin3=1 & coin4=1 ; |
|||
|
|||
// rewards |
|||
rewards "steps" |
|||
true : 1; |
|||
endrewards |
|||
|
@ -0,0 +1,69 @@ |
|||
// COIN FLIPPING PROTOCOL FOR POLYNOMIAL RANDOMIZED CONSENSUS [AH90] |
|||
// gxn/dxp 20/11/00 |
|||
|
|||
mdp |
|||
|
|||
// constants |
|||
const int N=4; |
|||
const int K=8; |
|||
const int range = 2*(K+1)*N; |
|||
const int counter_init = (K+1)*N; |
|||
const int left = N; |
|||
const int right = 2*(K+1)*N - N; |
|||
|
|||
//Coin Probabilities |
|||
const double p1; |
|||
const double p2; |
|||
const double p3; |
|||
const double p4; |
|||
|
|||
// shared coin |
|||
global counter : [0..range] init counter_init; |
|||
|
|||
module process1 |
|||
|
|||
// program counter |
|||
pc1 : [0..3]; |
|||
// 0 - flip |
|||
// 1 - write |
|||
// 2 - check |
|||
// 3 - finished |
|||
|
|||
// local coin |
|||
coin1 : [0..1]; |
|||
|
|||
// flip coin |
|||
[] (pc1=0) -> p1 : (coin1'=0) & (pc1'=1) + 1-p1 : (coin1'=1) & (pc1'=1); |
|||
// write tails -1 (reset coin to add regularity) |
|||
[] (pc1=1) & (coin1=0) & (counter>0) -> 1 : (counter'=counter-1) & (pc1'=2) & (coin1'=0); |
|||
// write heads +1 (reset coin to add regularity) |
|||
[] (pc1=1) & (coin1=1) & (counter<range) -> 1 : (counter'=counter+1) & (pc1'=2) & (coin1'=0); |
|||
// check |
|||
// decide tails |
|||
[] (pc1=2) & (counter<=left) -> 1 : (pc1'=3) & (coin1'=0); |
|||
// decide heads |
|||
[] (pc1=2) & (counter>=right) -> 1 : (pc1'=3) & (coin1'=1); |
|||
// flip again |
|||
[] (pc1=2) & (counter>left) & (counter<right) -> 1 : (pc1'=0); |
|||
// loop (all loop together when done) |
|||
[done] (pc1=3) -> 1 : (pc1'=3); |
|||
|
|||
endmodule |
|||
|
|||
// construct remaining processes through renaming |
|||
module process2 = process1[pc1=pc2,coin1=coin2,p1=p2] endmodule |
|||
module process3 = process1[pc1=pc3,coin1=coin3,p1=p3] endmodule |
|||
module process4 = process1[pc1=pc4,coin1=coin4,p1=p4] endmodule |
|||
|
|||
// labels |
|||
label "finished" = pc1=3 & pc2=3 & pc3=3 & pc4=3 ; |
|||
label "all_coins_equal_0" = coin1=0 & coin2=0 & coin3=0 & coin4=0 ; |
|||
label "all_coins_equal_1" = coin1=1 & coin2=1 & coin3=1 & coin4=1 ; |
|||
label "agree" = coin1=coin2 & coin2=coin3 & coin3=coin4 ; |
|||
label "finish_with_1" = pc1=3 & pc2=3 & pc3=3 & pc4=3 & coin1=1 & coin2=1 & coin3=1 & coin4=1 ; |
|||
|
|||
// rewards |
|||
rewards "steps" |
|||
true : 1; |
|||
endrewards |
|||
|
@ -0,0 +1,45 @@ |
|||
// sum of two dice as the asynchronous parallel composition of |
|||
// two copies of Knuth's model of a fair die using only fair coins |
|||
|
|||
mdp |
|||
|
|||
//Coin Probabilities |
|||
const double p1; |
|||
const double p2; |
|||
|
|||
module die1 |
|||
|
|||
// local state |
|||
s1 : [0..7] init 0; |
|||
// value of the dice |
|||
d1 : [0..6] init 0; |
|||
|
|||
[] s1=0 -> p1 : (s1'=1) + 1-p1 : (s1'=2); |
|||
[] s1=1 -> p1 : (s1'=3) + 1-p1 : (s1'=4); |
|||
[] s1=2 -> p1 : (s1'=5) + 1-p1 : (s1'=6); |
|||
[] s1=3 -> p1 : (s1'=1) + 1-p1 : (s1'=7) & (d1'=1); |
|||
[] s1=4 -> p1 : (s1'=7) & (d1'=2) + 1-p1 : (s1'=7) & (d1'=3); |
|||
[] s1=5 -> p1 : (s1'=7) & (d1'=4) + 1-p1 : (s1'=7) & (d1'=5); |
|||
[] s1=6 -> p1 : (s1'=2) + 1-p1 : (s1'=7) & (d1'=6); |
|||
[] s1=7 & s2=7 -> 1: (s1'=7); |
|||
endmodule |
|||
|
|||
module die2 = die1 [ s1=s2, s2=s1, d1=d2, p1=p2 ] endmodule |
|||
|
|||
rewards "coinflips" |
|||
[] s1<7 | s2<7 : 1; |
|||
endrewards |
|||
|
|||
label "done" = s1=7 & s2=7; |
|||
label "two" = s1=7 & s2=7 & d1+d2=2; |
|||
label "three" = s1=7 & s2=7 & d1+d2=3; |
|||
label "four" = s1=7 & s2=7 & d1+d2=4; |
|||
label "five" = s1=7 & s2=7 & d1+d2=5; |
|||
label "six" = s1=7 & s2=7 & d1+d2=6; |
|||
label "seven" = s1=7 & s2=7 & d1+d2=7; |
|||
label "eight" = s1=7 & s2=7 & d1+d2=8; |
|||
label "nine" = s1=7 & s2=7 & d1+d2=9; |
|||
label "ten" = s1=7 & s2=7 & d1+d2=10; |
|||
label "eleven" = s1=7 & s2=7 & d1+d2=11; |
|||
label "twelve" = s1=7 & s2=7 & d1+d2=12; |
|||
label "doubles" = s1=7 & s2=7 & d1=d2; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue