trains0.xml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
  3. <nta>
  4. <declaration>/*
  5. OR - 2019
  6. Adapted by Jovian HERSEMEULE - 2020
  7. */
  8. const int NAB = 3;
  9. const int NBA = 3;
  10. const int N = 6;
  11. typedef int[0,NAB-1] id_tAB;
  12. typedef int[0,NBA-1] id_tBA;
  13. int ab=0, ba=0;
  14. chan accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA], requestAB[NAB], requestBA[NBA];
  15. </declaration>
  16. <template>
  17. <name>TrainBA</name>
  18. <parameter>const id_tBA id</parameter>
  19. <declaration>clock x;</declaration>
  20. <location id="id0" x="-51" y="0">
  21. <name x="-51" y="17">A</name>
  22. <urgent/>
  23. </location>
  24. <location id="id1" x="93" y="0">
  25. <name x="84" y="17">BA</name>
  26. <label kind="invariant" x="110" y="-8">x&lt;=10</label>
  27. </location>
  28. <location id="id2" x="93" y="-127">
  29. <name x="93" y="-161">B</name>
  30. </location>
  31. <location id="id3" x="-51" y="-127">
  32. <name x="-59" y="-161">Safe</name>
  33. </location>
  34. <init ref="id3"/>
  35. <transition>
  36. <source ref="id0"/>
  37. <target ref="id3"/>
  38. <label kind="synchronisation" x="-51" y="-68">libBA[id] !</label>
  39. </transition>
  40. <transition>
  41. <source ref="id1"/>
  42. <target ref="id0"/>
  43. </transition>
  44. <transition>
  45. <source ref="id2"/>
  46. <target ref="id1"/>
  47. <label kind="synchronisation" x="101" y="-85">accesBA[id] ?</label>
  48. <label kind="assignment" x="101" y="-68">x:=0</label>
  49. </transition>
  50. <transition>
  51. <source ref="id3"/>
  52. <target ref="id2"/>
  53. <label kind="synchronisation" x="-33" y="-144">requestBA[id] !</label>
  54. </transition>
  55. </template>
  56. <template>
  57. <name x="40" y="16">TrainAB</name>
  58. <parameter>const id_tAB id</parameter>
  59. <declaration>clock x;</declaration>
  60. <location id="id4" x="127" y="93">
  61. <name x="116" y="65">Safe</name>
  62. </location>
  63. <location id="id5" x="280" y="93">
  64. <name x="279" y="65">A</name>
  65. </location>
  66. <location id="id6" x="127" y="229">
  67. <name x="124" y="243">B</name>
  68. <urgent/>
  69. </location>
  70. <location id="id7" x="280" y="229">
  71. <name x="270" y="243">AB</name>
  72. <label kind="invariant" x="296" y="218">x&lt;=10</label>
  73. </location>
  74. <init ref="id4"/>
  75. <transition>
  76. <source ref="id6"/>
  77. <target ref="id4"/>
  78. <label kind="synchronisation" x="127" y="144">libAB[id] !</label>
  79. </transition>
  80. <transition>
  81. <source ref="id7"/>
  82. <target ref="id6"/>
  83. </transition>
  84. <transition>
  85. <source ref="id5"/>
  86. <target ref="id7"/>
  87. <label kind="synchronisation" x="280" y="144">accesAB[id] ?</label>
  88. <label kind="assignment" x="280" y="161">x:=0</label>
  89. </transition>
  90. <transition>
  91. <source ref="id4"/>
  92. <target ref="id5"/>
  93. <label kind="synchronisation" x="145" y="76">requestAB[id] !</label>
  94. </transition>
  95. </template>
  96. <template>
  97. <name x="40" y="16">CTRL</name>
  98. <declaration>id_tAB list[N+1];
  99. int[0,N] len;
  100. // Put an element at the end of the queue
  101. void enqueue(id_tAB element)
  102. {
  103. list[len++] = element;
  104. }
  105. // Remove the front element of the queue
  106. void dequeue()
  107. {
  108. int i = 0;
  109. len -= 1;
  110. while (i &lt; len)
  111. {
  112. list[i] = list[i + 1];
  113. i++;
  114. }
  115. list[i] = 0;
  116. }
  117. // Returns the front element of the queue
  118. id_tAB front()
  119. {
  120. return list[0];
  121. }
  122. // Returns the last element of the queue
  123. id_tAB tail()
  124. {
  125. return list[len - 1];
  126. }</declaration>
  127. <location id="id8" x="314" y="102">
  128. <name x="331" y="94">Free</name>
  129. </location>
  130. <location id="id9" x="212" y="-68">
  131. <name x="238" y="-59">OnlyAB</name>
  132. <label kind="comments" x="297" y="-59">At least one train on AB ;
  133. and no train blocked on B</label>
  134. </location>
  135. <location id="id10" x="212" y="263">
  136. <name x="229" y="238">OnlyBA</name>
  137. </location>
  138. <location id="id11" x="-153" y="-68">
  139. <name x="-272" y="-68">RequestFromB</name>
  140. <label kind="comments" x="-484" y="-42">Waiting for AB trains to leave shared section;
  141. some other trains are waiting on B.</label>
  142. </location>
  143. <location id="id12" x="-153" y="263">
  144. <name x="-272" y="246">RequestFromA</name>
  145. </location>
  146. <init ref="id8"/>
  147. <transition>
  148. <source ref="id11"/>
  149. <target ref="id11"/>
  150. <label kind="select" x="-263" y="-221">e:id_tAB</label>
  151. <label kind="synchronisation" x="-263" y="-204">accesAB[e]!</label>
  152. <nail x="-187" y="-187"/>
  153. <nail x="-263" y="-187"/>
  154. </transition>
  155. <transition>
  156. <source ref="id12"/>
  157. <target ref="id12"/>
  158. <label kind="select" x="-255" y="323">e:id_tBA</label>
  159. <label kind="synchronisation" x="-255" y="340">accesBA[e] !</label>
  160. <nail x="-196" y="323"/>
  161. <nail x="-256" y="323"/>
  162. </transition>
  163. <transition>
  164. <source ref="id8"/>
  165. <target ref="id9"/>
  166. <label kind="select" x="144" y="17">e:id_tAB</label>
  167. <label kind="synchronisation" x="102" y="34">requestAB[e] ?</label>
  168. <label kind="assignment" x="161" y="51">ab ++</label>
  169. <nail x="212" y="59"/>
  170. </transition>
  171. <transition>
  172. <source ref="id8"/>
  173. <target ref="id10"/>
  174. <label kind="select" x="144" y="136">e:id_tBA</label>
  175. <label kind="synchronisation" x="102" y="153">requestBA[e] ?</label>
  176. <label kind="assignment" x="161" y="170">ba ++</label>
  177. <nail x="212" y="144"/>
  178. </transition>
  179. <transition>
  180. <source ref="id12"/>
  181. <target ref="id9"/>
  182. <label kind="guard" x="-221" y="136">ba == 0</label>
  183. <nail x="-153" y="144"/>
  184. </transition>
  185. <transition>
  186. <source ref="id10"/>
  187. <target ref="id8"/>
  188. <label kind="guard" x="263" y="186">ba == 0</label>
  189. </transition>
  190. <transition>
  191. <source ref="id12"/>
  192. <target ref="id12"/>
  193. <label kind="select" x="-153" y="322">e:id_tBA</label>
  194. <label kind="synchronisation" x="-153" y="339">libBA[e] ?</label>
  195. <label kind="assignment" x="-153" y="356">ba --</label>
  196. <nail x="-85" y="322"/>
  197. <nail x="-153" y="322"/>
  198. </transition>
  199. <transition>
  200. <source ref="id10"/>
  201. <target ref="id12"/>
  202. <label kind="select" x="-42" y="212">e:id_tAB</label>
  203. <label kind="synchronisation" x="-42" y="229">requestAB[e] ?</label>
  204. <label kind="assignment" x="-42" y="246">ab ++</label>
  205. </transition>
  206. <transition>
  207. <source ref="id10"/>
  208. <target ref="id10"/>
  209. <label kind="select" x="323" y="263">e:id_tBA</label>
  210. <label kind="synchronisation" x="323" y="280">requestBA[e] ?</label>
  211. <label kind="assignment" x="323" y="298">ba ++</label>
  212. <nail x="314" y="323"/>
  213. <nail x="314" y="263"/>
  214. </transition>
  215. <transition>
  216. <source ref="id9"/>
  217. <target ref="id9"/>
  218. <label kind="select" x="331" y="-153">e:id_tAB</label>
  219. <label kind="synchronisation" x="331" y="-136">requestAB[e] ?</label>
  220. <label kind="assignment" x="331" y="-119">ab ++</label>
  221. <nail x="323" y="-153"/>
  222. <nail x="323" y="-68"/>
  223. </transition>
  224. <transition>
  225. <source ref="id11"/>
  226. <target ref="id10"/>
  227. <label kind="guard" x="-221" y="42">ab == 0</label>
  228. <nail x="-153" y="50"/>
  229. </transition>
  230. <transition>
  231. <source ref="id11"/>
  232. <target ref="id11"/>
  233. <label kind="select" x="-144" y="-238">e:id_tAB</label>
  234. <label kind="synchronisation" x="-144" y="-221">libAB[e] ?</label>
  235. <label kind="assignment" x="-144" y="-204">ab--</label>
  236. <nail x="-68" y="-187"/>
  237. <nail x="-153" y="-187"/>
  238. </transition>
  239. <transition>
  240. <source ref="id9"/>
  241. <target ref="id11"/>
  242. <label kind="select" x="-34" y="-119">e:id_tBA</label>
  243. <label kind="synchronisation" x="-34" y="-102">requestBA[e] ?</label>
  244. <label kind="assignment" x="-34" y="-85">ba ++</label>
  245. </transition>
  246. <transition>
  247. <source ref="id10"/>
  248. <target ref="id10"/>
  249. <label kind="select" x="221" y="339">e:id_tBA</label>
  250. <label kind="synchronisation" x="221" y="356">libBA[e] ?</label>
  251. <label kind="assignment" x="221" y="373">ba --</label>
  252. <nail x="280" y="331"/>
  253. <nail x="212" y="331"/>
  254. </transition>
  255. <transition>
  256. <source ref="id10"/>
  257. <target ref="id10"/>
  258. <label kind="select" x="110" y="340">e:id_tBA</label>
  259. <label kind="synchronisation" x="110" y="357">accesBA[e] !</label>
  260. <nail x="195" y="331"/>
  261. <nail x="110" y="331"/>
  262. </transition>
  263. <transition>
  264. <source ref="id9"/>
  265. <target ref="id9"/>
  266. <label kind="select" x="85" y="-229">e:id_tAB</label>
  267. <label kind="synchronisation" x="85" y="-212">accesAB[e] !</label>
  268. <nail x="187" y="-187"/>
  269. <nail x="85" y="-187"/>
  270. </transition>
  271. <transition>
  272. <source ref="id9"/>
  273. <target ref="id9"/>
  274. <label kind="select" x="212" y="-238">e:id_tAB</label>
  275. <label kind="synchronisation" x="212" y="-221">libAB[e] ?</label>
  276. <label kind="assignment" x="212" y="-204">ab--</label>
  277. <nail x="289" y="-187"/>
  278. <nail x="212" y="-187"/>
  279. </transition>
  280. <transition>
  281. <source ref="id9"/>
  282. <target ref="id8"/>
  283. <label kind="guard" x="272" y="8">ab == 0</label>
  284. </transition>
  285. </template>
  286. <system>system TrainAB, TrainBA, CTRL;
  287. </system>
  288. <queries>
  289. <query>
  290. <formula>E&lt;&gt; TrainBA(1).BA</formula>
  291. <comment></comment>
  292. </query>
  293. <query>
  294. <formula>E&lt;&gt; TrainBA(2).BA
  295. </formula>
  296. <comment>
  297. </comment>
  298. </query>
  299. <query>
  300. <formula>A[] forall (i : id_tBA) forall (j : id_tAB) TrainBA(i).BA &amp;&amp; TrainAB(j).AB imply i == j
  301. </formula>
  302. <comment>
  303. </comment>
  304. </query>
  305. <query>
  306. <formula>TrainBA(1).B --&gt; TrainBA(1).BA
  307. </formula>
  308. <comment>
  309. </comment>
  310. </query>
  311. <query>
  312. <formula>A&lt;&gt; TrainBA(1).BA
  313. </formula>
  314. <comment>
  315. </comment>
  316. </query>
  317. <query>
  318. <formula>A[] not deadlock</formula>
  319. <comment></comment>
  320. </query>
  321. <query>
  322. <formula>E&lt;&gt; TrainBA(1).BA &amp; TrainBA(2).BA
  323. </formula>
  324. <comment>
  325. </comment>
  326. </query>
  327. </queries>
  328. </nta>