I try to solve with spin the task about the farmer, wolf, goat and cabbage.
So, I found the folowing promela description:
#define fin (all_right_side == true)
#define wg (g_and_w == false)
#define gc (g_and_c == false)
ltl ltl_0 { <> fin && [] ( wg && gc ) }
bool all_right_side, g_and_w, g_and_c;
active proctype river()
{
bit f = 0,
w = 0,
g = 0,
c = 0;
all_right_side = false;
g_and_w = false;
g_and_c = false;
printf("MSC: f %c w %c g %c c %c \n", f, w, g, c);
do
:: (f==1) && (f == w) && (f ==g) && (f == c) ->
all_right_side = true;
break;
:: else ->
if
:: (f == w) ->
f = 1 - f;
w = 1 - w;
:: (f == c) ->
f = 1 - f;
w = 1 - c;
:: (f == g) ->
f = 1 - f;
w = 1 - g;
:: (true) ->
f = 1 - f;
fi;
printf("M f %c w %c g %c c %c \n", f, w, g, c);
if
:: (f != g && g == c) ->
g_and_c = true;
:: (f != g && g == w) ->
g_and_w = true;
::else ->
skip
fi
od;
printf ("MSC: OK!\n")
}
I add there an LTL-formula: ltl ltl_0 { <> fin && [] ( wg && gc ) } to verify, than the wolf wouldn't eat a goat, and the goat wouldn't eat the cabbage. I want to get an example, how the farmer can transport all his needs (w-g-c) without loss.
When I run verification, I get the following result: State-vector 20 byte, depth reached 59, errors: 1 64 states, stored 23 states, matched 87 transitions (= stored+matched) 0 atomic steps hash conflicts: 0 (resolved)
This means that the program has generated an example for me. But I cannot interpret it. The content of *.pml.trial file is:enter image description here
Please, help me to interpret.
In order to "interpret" it, you could modify your source code so that each time an action is taken something intellegibile is printed on stdout.
e.g.:
+ something similar for the cases
(f == c)
,(f == g)
and(true)
.Note: your source code already provides
printf("M f %c w %c g %c c %c \n", f, w, g, c);
, which can be used to interpret the counter-example if you keep in mind that0
meansleft
and1
meansright
. I would prefer a more verbose tracing, though.After you have done this for each possible transition, you can see what happens within your counter-example by running spin in the following way
The option
-t
replays the latesttrail
found by spin upon the violation of some assertion/property.