<?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_2.dtd'>
<nta>
	<declaration>// Place global declarations here.
const int NTRAINS := 2;

typedef int[1,NTRAINS] train_id_t;
typedef int[0,NTRAINS] id_t;

chan appr[train_id_t];
chan stop[train_id_t];
chan leave[train_id_t];
chan go[train_id_t];</declaration>
	<template>
		<name x="5" y="5">Train</name>
		<parameter>train_id_t id</parameter>
		<declaration>// Place local declarations here.
clock x;</declaration>
		<location id="id0" x="-255" y="-187">
			<name x="-238" y="-204">Restarting</name>
			<label kind="invariant" x="-238" y="-187">x&lt;=15</label>
		</location>
		<location id="id1" x="-357" y="-85">
			<name x="-382" y="-68">Waiting</name>
		</location>
		<location id="id2" x="-255" y="-297">
			<name x="-265" y="-331">Crossing</name>
			<label kind="invariant" x="-238" y="-314">x&lt;=5</label>
		</location>
		<location id="id3" x="-450" y="-187">
			<name x="-561" y="-212">Approaching</name>
			<label kind="invariant" x="-518" y="-195">x&lt;=20</label>
		</location>
		<location id="id4" x="-450" y="-297">
			<name x="-460" y="-331">Far</name>
		</location>
		<init ref="id4"/>
		<transition>
			<source ref="id2"/>
			<target ref="id4"/>
			<label kind="guard" x="-374" y="-340">x&gt;=3</label>
			<label kind="synchronisation" x="-374" y="-323">leave[id]!</label>
		</transition>
		<transition>
			<source ref="id0"/>
			<target ref="id2"/>
			<label kind="guard" x="-246" y="-255">x&gt;=7</label>
			<label kind="assignment" x="-246" y="-238">x:=0</label>
		</transition>
		<transition>
			<source ref="id1"/>
			<target ref="id0"/>
			<label kind="synchronisation" x="-297" y="-144">go[id]?</label>
			<label kind="assignment" x="-297" y="-127">x:=0</label>
		</transition>
		<transition>
			<source ref="id3"/>
			<target ref="id2"/>
			<label kind="guard" x="-374" y="-229">x&gt;=10</label>
			<label kind="assignment" x="-374" y="-212">x:=0</label>
		</transition>
		<transition>
			<source ref="id3"/>
			<target ref="id1"/>
			<label kind="guard" x="-450" y="-136">x&lt;=10</label>
			<label kind="synchronisation" x="-450" y="-119">stop[id]?</label>
		</transition>
		<transition>
			<source ref="id4"/>
			<target ref="id3"/>
			<label kind="synchronisation" x="-518" y="-263">appr[id]!</label>
			<label kind="assignment" x="-493" y="-246">x:=0</label>
		</transition>
	</template>
	<template>
		<name>Semaphore</name>
		<declaration>id_t stopping_train := 0;

</declaration>
		<location id="id5" x="-119" y="-93">
			<name x="-144" y="-76">Stopping</name>
			<committed/>
		</location>
		<location id="id6" x="-119" y="-195">
			<name x="-127" y="-229">Busy</name>
		</location>
		<location id="id7" x="-119" y="-297">
			<name x="-136" y="-331">Free</name>
		</location>
		<init ref="id7"/>
		<transition>
			<source ref="id7"/>
			<target ref="id6"/>
			<label kind="select" x="-229" y="-272">i : train_id_t</label>
			<label kind="synchronisation" x="-229" y="-255">go[i]!</label>
			<nail x="-153" y="-246"/>
		</transition>
		<transition>
			<source ref="id5"/>
			<target ref="id6"/>
			<label kind="synchronisation" x="-85" y="-161">stop[stopping_train]!</label>
			<label kind="assignment" x="-85" y="-144">stopping_train := 0</label>
			<nail x="-85" y="-136"/>
		</transition>
		<transition>
			<source ref="id6"/>
			<target ref="id5"/>
			<label kind="select" x="-238" y="-170">i : train_id_t</label>
			<label kind="synchronisation" x="-212" y="-153">appr[i]?</label>
			<label kind="assignment" x="-289" y="-136">stopping_train := i</label>
			<nail x="-153" y="-144"/>
		</transition>
		<transition>
			<source ref="id6"/>
			<target ref="id7"/>
			<label kind="select" x="-34" y="-272">i : train_id_t</label>
			<label kind="synchronisation" x="-34" y="-255">leave[i]?</label>
			<nail x="-42" y="-195"/>
			<nail x="-42" y="-297"/>
		</transition>
		<transition>
			<source ref="id7"/>
			<target ref="id6"/>
			<label kind="select" x="-347" y="-263">i : train_id_t</label>
			<label kind="synchronisation" x="-322" y="-246">appr[i]?</label>
			<nail x="-263" y="-297"/>
			<nail x="-263" y="-195"/>
		</transition>
	</template>
	<system>// Place template instantiations here.
// List one or more processes to be composed into a system.
system Train, Semaphore;
    </system>
	<queries>
		<query>
			<formula>Train(1).Approaching --&gt; Train(1).Crossing
			</formula>
			<comment>
			</comment>
		</query>
		<query>
			<formula>A[] forall (i : train_id_t) forall (j : train_id_t) (Train(i).Crossing and Train(j).Crossing imply i == j)
			</formula>
			<comment>
			</comment>
		</query>
		<query>
			<formula>A[] not deadlock
			</formula>
			<comment>
			</comment>
		</query>
	</queries>
</nta>
