<?xml version="1.0" encoding="utf-8"?><!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_1.dtd'><nta><declaration>//This model is inspired by the vacuum cleaning world example described by Michael Wooldridge
//in his book "An Introduction to Multi Agent Systems, p52-54.

//Model made by Frits Vaandrager, Radboud University Nijmegen, February 2014
//The idea is simple: we let the robot just take "turn" and "forward" moves nondeterministically.
//We store the choice made for each location/orientation pair. The robot may only make this move once
//during its first cycle through the room.

//Uppaal does not support enumerated types so we encode some constants as integers

//CONSTANTS

//size of toom
const int n=3;

//strtaegy values
const int undefined = 0;
const int turn = 1;
const int forward = 2;

//directions
const int N = 3;
const int E = 4;
const int S = 5;
const int W = 6;

//TYPES
// range of x, y positions
typedef int[0,n-1] pos;
// range of directions: the set {N, E, S, W}
typedef int[N,W] dir;
// range of strateggy values: the set {free, turn, forward}
typedef int[undefined,forward] strategy_values;

dir rotate(dir direction){
return (direction==N)?E:((direction==E)?S:((direction==S)?W:N));
}

//CHANNELS
// just to give transitions a name
broadcast chan turn_act;
broadcast chan forward_act;

//STATE VARIABLES
//x coordinate of robot
pos x;
//y coordinate of robot
pos y;
//orientation of robot
dir d;
//the state variable "strategy" gives the strategy as it has been defined thus far,
//that is, given a position and an orientation for which the strategy is defined, it tells whether the robot should turn or move forward.
strategy_values strategy[pos][pos][dir];

//AUXILIARY STUFF ONLY NEEDED TO STATE PROPERTIES
//function used for stating properties
//when the robot has visited a square in the room then for at least one of the four orientations the strategy for that square must be defined
bool visited(pos x1, pos y1){
return strategy[x1][y1][N] != undefined || strategy[x1][y1][E] != undefined || strategy[x1][y1][S] != undefined || strategy[x1][y1][W] != undefined;
}

//These are auxiliary variable used to count the number of turns and forward moves in a run
int tcount, fcount;
</declaration><template><name x="5" y="5">Robot</name><declaration>

</declaration><location id="id0" x="-608" y="-192"></location><init ref="id0"/><transition><source ref="id0"/><target ref="id0"/><label kind="guard" x="-576" y="-168">(d==N imply y&lt;n-1) &amp;&amp; (d==E imply x&lt;n-1) &amp;&amp; (d==S imply y&gt;0) &amp;&amp; (d==W imply x&gt;0) 
&amp;&amp; strategy[x][y][d] != turn</label><label kind="synchronisation" x="-576" y="-184">forward_act!</label><label kind="assignment" x="-576" y="-136">strategy[x][y][d]:=forward,
x := (d==W)?(x-1 ) : ( (d==E) ? (x+1) : x),
y := (d==S)?(y-1 ) : ( (d==N) ? (y+1) : y),
fcount++</label><label kind="comments">non-deterministically select an object that can synchronize on the backward channel. If synchronization is possible progress time according to the move time of the object.</label><nail x="-576" y="-128"/><nail x="-640" y="-128"/></transition><transition><source ref="id0"/><target ref="id0"/><label kind="guard" x="-576" y="-256">strategy[x][y][d] != forward</label><label kind="synchronisation" x="-576" y="-272">turn_act!</label><label kind="assignment" x="-576" y="-240">strategy[x][y][d]:=turn,
d:= rotate(d),
tcount++</label><label kind="comments">Non-deterministically select an object that can synchronize on the forward channel. If synchronization is possible progress time according to the move time of the object.</label><nail x="-640" y="-256"/><nail x="-576" y="-256"/></transition></template><template><name>Dummy</name><location id="id1" x="0" y="0"></location><init ref="id1"/><transition><source ref="id1"/><target ref="id1"/><label kind="synchronisation" x="32" y="24">forward_act?</label><nail x="32" y="64"/><nail x="-32" y="64"/></transition><transition><source ref="id1"/><target ref="id1"/><label kind="synchronisation" x="32" y="-56">turn_act?</label><nail x="-32" y="-64"/><nail x="32" y="-64"/></transition></template><system>//The sole purpose of the Dummy automaton is that in the counterexample traces generated by Uppaal
//the action (Turn or Forward) is visible. It should be easy to write a script that plots the
//diagrams from the Uppaal traces.

system Robot, Dummy;

progress
{
fcount+tcount;
}</system></nta>