Jelajahi Sumber

Add new state to receive request queries

DricomDragon 5 tahun lalu
induk
melakukan
b43acadffd
1 mengubah file dengan 126 tambahan dan 67 penghapusan
  1. 126 67
      ds/trains0.xml

+ 126 - 67
ds/trains0.xml

@@ -3,9 +3,10 @@
 <nta>
 	<declaration>/*
 OR - 2019
+Adapted by Jovian HERSEMEULE - 2020
  */
 
-const int NAB = 3;         // # trains
+const int NAB = 3;
 const int NBA = 3;
 const int N = 6;
 
@@ -14,7 +15,7 @@ typedef int[0,NBA-1] id_tBA;
 
 int ab=0, ba=0;
 
-chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA];
+chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA], requestAB[NAB], requestBA[NBA];
 
 </declaration>
 	<template>
@@ -24,12 +25,12 @@ chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA];
 		<location id="id0" x="-51" y="0">
 			<name x="-51" y="17">A</name>
 		</location>
-		<location id="id1" x="34" y="0">
-			<name x="25" y="17">BA</name>
-			<label kind="invariant" x="51" y="-8">x&lt;=10</label>
+		<location id="id1" x="93" y="0">
+			<name x="84" y="17">BA</name>
+			<label kind="invariant" x="110" y="-8">x&lt;=10</label>
 		</location>
-		<location id="id2" x="34" y="-127">
-			<name x="34" y="-161">B</name>
+		<location id="id2" x="93" y="-127">
+			<name x="93" y="-161">B</name>
 		</location>
 		<location id="id3" x="-51" y="-127">
 			<name x="-59" y="-161">Safe</name>
@@ -47,12 +48,13 @@ chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA];
 		<transition>
 			<source ref="id2"/>
 			<target ref="id1"/>
-			<label kind="synchronisation" x="42" y="-85">accesBA[id] ?</label>
-			<label kind="assignment" x="42" y="-68">x:=0</label>
+			<label kind="synchronisation" x="101" y="-85">accesBA[id] ?</label>
+			<label kind="assignment" x="101" y="-68">x:=0</label>
 		</transition>
 		<transition>
 			<source ref="id3"/>
 			<target ref="id2"/>
+			<label kind="synchronisation" x="-33" y="-144">requestBA[id] !</label>
 		</transition>
 	</template>
 	<template>
@@ -62,15 +64,15 @@ chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA];
 		<location id="id4" x="127" y="93">
 			<name x="116" y="65">Safe</name>
 		</location>
-		<location id="id5" x="212" y="93">
-			<name x="211" y="65">A</name>
+		<location id="id5" x="280" y="93">
+			<name x="279" y="65">A</name>
 		</location>
 		<location id="id6" x="127" y="229">
 			<name x="124" y="243">B</name>
 		</location>
-		<location id="id7" x="212" y="229">
-			<name x="202" y="243">AB</name>
-			<label kind="invariant" x="228" y="218">x&lt;=10</label>
+		<location id="id7" x="280" y="229">
+			<name x="270" y="243">AB</name>
+			<label kind="invariant" x="296" y="218">x&lt;=10</label>
 		</location>
 		<init ref="id4"/>
 		<transition>
@@ -85,12 +87,13 @@ chan        accesAB[NAB], accesBA[NBA], libAB[NAB], libBA[NBA];
 		<transition>
 			<source ref="id5"/>
 			<target ref="id7"/>
-			<label kind="synchronisation" x="212" y="144">accesAB[id] ?</label>
-			<label kind="assignment" x="212" y="161">x:=0</label>
+			<label kind="synchronisation" x="280" y="144">accesAB[id] ?</label>
+			<label kind="assignment" x="280" y="161">x:=0</label>
 		</transition>
 		<transition>
 			<source ref="id4"/>
 			<target ref="id5"/>
+			<label kind="synchronisation" x="145" y="76">requestAB[id] !</label>
 		</transition>
 	</template>
 	<template>
@@ -128,87 +131,143 @@ id_tAB tail()
 {
    return list[len - 1];
 }</declaration>
-		<location id="id8" x="-102" y="51">
-			<name x="-153" y="43">Free</name>
+		<location id="id8" x="314" y="102">
+			<name x="331" y="94">Free</name>
 		</location>
 		<location id="id9" x="212" y="-68">
-			<name x="178" y="-59">AB</name>
-			<label kind="comments" x="34" y="-59">At least one on AB</label>
+			<name x="221" y="-59">OnlyAB</name>
+			<label kind="comments" x="280" y="-59">At least one train on AB ;
+and no train blocked on B</label>
 		</location>
-		<location id="id10" x="212" y="187">
-			<name x="178" y="161">BA</name>
-			<label kind="comments" x="34" y="161">At least one on BA</label>
+		<location id="id10" x="212" y="263">
+			<name x="229" y="238">OnlyBA</name>
+		</location>
+		<location id="id11" x="-153" y="-68">
+			<name x="-272" y="-68">RequestFromB</name>
+			<label kind="comments" x="-493" y="-102">Waiting for AB trains to leave shared section;
+some other trains are waiting on B.</label>
+		</location>
+		<location id="id12" x="-153" y="263">
+			<name x="-280" y="254">RequestFromA</name>
 		</location>
 		<init ref="id8"/>
 		<transition>
-			<source ref="id10"/>
+			<source ref="id8"/>
+			<target ref="id9"/>
+			<label kind="select" x="144" y="17">e:id_tAB</label>
+			<label kind="synchronisation" x="102" y="34">requestAB[e] ?</label>
+			<nail x="212" y="59"/>
+		</transition>
+		<transition>
+			<source ref="id8"/>
 			<target ref="id10"/>
-			<label kind="select" x="221" y="263">e:id_tBA</label>
-			<label kind="synchronisation" x="221" y="280">libBA[e] ?</label>
-			<label kind="assignment" x="221" y="297">ba --</label>
-			<nail x="280" y="255"/>
-			<nail x="212" y="255"/>
+			<label kind="select" x="144" y="136">e:id_tBA</label>
+			<label kind="synchronisation" x="102" y="153">requestBA[e] ?</label>
+			<nail x="212" y="144"/>
+		</transition>
+		<transition>
+			<source ref="id12"/>
+			<target ref="id9"/>
+			<label kind="guard" x="-221" y="136">ba == 0</label>
+			<nail x="-153" y="144"/>
+		</transition>
+		<transition>
+			<source ref="id10"/>
+			<target ref="id8"/>
+			<label kind="guard" x="263" y="186">ba == 0</label>
+		</transition>
+		<transition>
+			<source ref="id12"/>
+			<target ref="id12"/>
+			<label kind="select" x="-153" y="322">e:id_tBA</label>
+			<label kind="synchronisation" x="-153" y="339">libBA[e] ?</label>
+			<label kind="assignment" x="-153" y="356">ba --</label>
+			<nail x="-85" y="322"/>
+			<nail x="-153" y="322"/>
+		</transition>
+		<transition>
+			<source ref="id10"/>
+			<target ref="id12"/>
+			<label kind="select" x="-8" y="229">e:id_tAB</label>
+			<label kind="synchronisation" x="-8" y="246">requestAB[e] ?</label>
 		</transition>
 		<transition>
 			<source ref="id10"/>
 			<target ref="id10"/>
-			<label kind="select" x="357" y="187">e:id_tBA</label>
-			<label kind="synchronisation" x="357" y="204">accesBA[e] !</label>
-			<label kind="assignment" x="357" y="221">ba ++</label>
-			<nail x="348" y="187"/>
-			<nail x="348" y="255"/>
+			<label kind="select" x="93" y="339">e:id_tBA</label>
+			<label kind="synchronisation" x="93" y="356">requestBA[e] ?</label>
+			<nail x="170" y="331"/>
+			<nail x="102" y="331"/>
 		</transition>
 		<transition>
 			<source ref="id9"/>
 			<target ref="id9"/>
-			<label kind="select" x="408" y="-153">e:id_tAB</label>
-			<label kind="synchronisation" x="408" y="-136">accesAB[e] !</label>
-			<label kind="assignment" x="408" y="-119">ab++</label>
-			<label kind="comments" x="408" y="-178">One more train on AB</label>
-			<nail x="399" y="-68"/>
-			<nail x="399" y="-178"/>
+			<label kind="select" x="93" y="-229">e:id_tAB</label>
+			<label kind="synchronisation" x="93" y="-212">requestAB[e] ?</label>
+			<nail x="178" y="-187"/>
+			<nail x="102" y="-187"/>
+		</transition>
+		<transition>
+			<source ref="id11"/>
+			<target ref="id10"/>
+			<label kind="guard" x="-221" y="42">ab == 0</label>
+			<nail x="-153" y="50"/>
+		</transition>
+		<transition>
+			<source ref="id11"/>
+			<target ref="id11"/>
+			<label kind="select" x="-144" y="-238">e:id_tAB</label>
+			<label kind="synchronisation" x="-144" y="-221">libAB[e] ?</label>
+			<label kind="assignment" x="-144" y="-204">ab--</label>
+			<nail x="-68" y="-187"/>
+			<nail x="-153" y="-187"/>
 		</transition>
 		<transition>
 			<source ref="id9"/>
-			<target ref="id9"/>
-			<label kind="select" x="136" y="-161">e:id_tAB</label>
-			<label kind="synchronisation" x="136" y="-144">libAB[e] ?</label>
-			<label kind="assignment" x="136" y="-127">ab--</label>
-			<label kind="comments" x="59" y="-187">One train leaves AB</label>
-			<nail x="289" y="-187"/>
-			<nail x="212" y="-187"/>
+			<target ref="id11"/>
+			<label kind="select" x="8" y="-102">e:id_tBA</label>
+			<label kind="synchronisation" x="8" y="-85">requestBA[e] ?</label>
 		</transition>
 		<transition>
 			<source ref="id10"/>
-			<target ref="id8"/>
-			<label kind="guard" x="-170" y="136">ba == 0</label>
-			<label kind="comments" x="-221" y="161">No train on BA</label>
-			<nail x="-102" y="187"/>
+			<target ref="id10"/>
+			<label kind="select" x="221" y="339">e:id_tBA</label>
+			<label kind="synchronisation" x="221" y="356">libBA[e] ?</label>
+			<label kind="assignment" x="221" y="373">ba --</label>
+			<nail x="280" y="331"/>
+			<nail x="212" y="331"/>
 		</transition>
 		<transition>
-			<source ref="id8"/>
+			<source ref="id10"/>
 			<target ref="id10"/>
-			<label kind="select" x="221" y="102">e:id_tBA</label>
-			<label kind="synchronisation" x="221" y="119">accesBA[e] !</label>
-			<label kind="assignment" x="221" y="136">ba++</label>
-			<label kind="comments" x="221" y="76">First train on BA</label>
-			<nail x="212" y="85"/>
+			<label kind="select" x="357" y="263">e:id_tBA</label>
+			<label kind="synchronisation" x="357" y="280">accesBA[e] !</label>
+			<label kind="assignment" x="357" y="297">ba ++</label>
+			<nail x="348" y="263"/>
+			<nail x="348" y="331"/>
 		</transition>
 		<transition>
 			<source ref="id9"/>
-			<target ref="id8"/>
-			<label kind="guard" x="-169" y="-85">ab == 0</label>
-			<label kind="comments" x="-221" y="-59">No train on AB</label>
-			<nail x="-101" y="-68"/>
+			<target ref="id9"/>
+			<label kind="select" x="340" y="-153">e:id_tAB</label>
+			<label kind="synchronisation" x="340" y="-136">accesAB[e] !</label>
+			<label kind="assignment" x="340" y="-119">ab++</label>
+			<nail x="331" y="-68"/>
+			<nail x="331" y="-178"/>
 		</transition>
 		<transition>
-			<source ref="id8"/>
+			<source ref="id9"/>
 			<target ref="id9"/>
-			<label kind="select" x="221" y="0">e:id_tAB</label>
-			<label kind="synchronisation" x="221" y="17">accesAB[e] !</label>
-			<label kind="assignment" x="221" y="34">ab++</label>
-			<label kind="comments" x="221" y="-25">First train on AB</label>
-			<nail x="212" y="17"/>
+			<label kind="select" x="212" y="-238">e:id_tAB</label>
+			<label kind="synchronisation" x="212" y="-221">libAB[e] ?</label>
+			<label kind="assignment" x="212" y="-204">ab--</label>
+			<nail x="289" y="-187"/>
+			<nail x="212" y="-187"/>
+		</transition>
+		<transition>
+			<source ref="id9"/>
+			<target ref="id8"/>
+			<label kind="guard" x="272" y="8">ab == 0</label>
 		</transition>
 	</template>
 	<system>system TrainAB, TrainBA, CTRL;