Created
September 1, 2018 04:26
-
-
Save eduardoleon/3132bd298a7ce8bc06b58db4f0fa382c to your computer and use it in GitHub Desktop.
Promela model for the problem about people crossing a bridge or a river or whatever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mtype = { left, right } | |
inline shift(source, target) { | |
/* select who goes */ | |
if | |
:: side[0] == source -> pick = 0 | |
:: side[1] == source -> pick = 1 | |
:: side[2] == source -> pick = 2 | |
:: side[3] == source -> pick = 3 | |
fi | |
/* update the elapsed time for this round */ | |
if | |
:: round < delay[pick] -> round = delay[pick] | |
:: else -> skip | |
fi | |
/* make them actually go */ | |
side[pick] = target | |
} | |
inline totalize() { | |
/* update the total elapsed time */ | |
total = total + round | |
round = 0 | |
} | |
init { | |
mtype side[4] = left | |
int delay[4] = { 1, 2, 5, 10 } | |
int pick, cycle, round, total | |
do | |
:: /* send two people to the right side */ | |
shift(left, right) | |
shift(left, right) | |
totalize() | |
/* if everyone is already on the right side, stop, | |
* otherwise send someone back to the left side */ | |
if | |
:: cycle == 2 -> break | |
:: else -> | |
shift(right, left) | |
totalize() | |
cycle++ | |
fi | |
od | |
/* this assertion will fail, because there is a better solution */ | |
assert(total >= 19) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment