trains0.xml 9.9 KB

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