Browse Source

Fixed semantics example (was broken due to runtime changes).

Joeri Exelmans 3 years ago
parent
commit
b148794d66
2 changed files with 49 additions and 40 deletions
  1. 36 27
      examples/semantics/run.py
  2. 13 13
      examples/semantics/statechart_semantics.xml

+ 36 - 27
examples/semantics/run.py

@@ -13,7 +13,9 @@ if __name__ == "__main__":
   # Generate semantic variants, and filter invalid ones
   variants = statechart_model.generate_semantic_variants()
 
-  print("Total variants:", len(variants))
+  variants_filtered = [v for v in variants if v.semantics.enabledness_memory_protocol == v.semantics.assignment_memory_protocol]
+
+  print("Total variants:", len(variants_filtered))
   
   # These rules perfectly partition the set of variants into "valid" and "invalid":
   def is_valid(semantics):
@@ -21,34 +23,27 @@ if __name__ == "__main__":
     if semantics.combo_step_maximality > semantics.big_step_maximality:
       return False
 
-    # I cannot think of a reason why someone would ever set assignment memory protocol to a different value from enabledness memory protocol.
-    # The model currently only detects enabledness memory protocol, anyway.
-    if semantics.assignment_memory_protocol != semantics.enabledness_memory_protocol:
-      return False
-
     # Combo steps only make sense if another semantic option refers to them
-    must_have_combo_steps = (semantics.input_event_lifeline == InputEventLifeline.FIRST_COMBO_STEP or
+    combo_steps_defined = (semantics.input_event_lifeline == InputEventLifeline.FIRST_COMBO_STEP or
           semantics.internal_event_lifeline == InternalEventLifeline.NEXT_COMBO_STEP or
           semantics.enabledness_memory_protocol == MemoryProtocol.COMBO_STEP)
 
-    # "Combo Take One" is the default combo-step maximality option in SCCD, and is also the option
-    # that is chosen when no combo-steps are being defined. Therefore, options different from "Combo Take One"
-    # are only allowed when combo-step semantics are being used.
-    if not must_have_combo_steps and semantics.combo_step_maximality > Maximality.TAKE_ONE:
-      return False
-
-    # If big-step maximality is "Take One", a big-step will always equal a combo step. 
-    # Therefore combo-steps do not really exist as entities that should be referred to by other semantic options.
-    # E.g. Input event lifeline "Present in First Combo Step" should be "Present in Whole" instead.
-    # E.g. Internal event lifeline "Present in Next Combo Step" makes no sense, the event will never be sensed!
-    # E.g. Memory protocol "Combo Step" should be "Big Step" instead.
-    if semantics.big_step_maximality == Maximality.TAKE_ONE and must_have_combo_steps:
-      return False
+    if combo_steps_defined:
+      if semantics.big_step_maximality == Maximality.TAKE_ONE:
+        # Combo steps will always equal big steps, and therefore don't really exist!
+        # E.g. Input event lifeline "Present in First Combo Step" should be "Present in Whole" instead.
+        # E.g. Internal event lifeline "Present in Next Combo Step" makes no sense, the event will never be sensed!
+        # E.g. Memory protocol "Combo Step" should be "Big Step" instead.
+        return False
+    else:
+      # Has no effect
+      if semantics.combo_step_maximality > Maximality.TAKE_ONE:
+        return False
 
     return True
 
-  valid_variants = [v for v in variants if is_valid(v.semantics)]
-  invalid_variants = [v for v in variants if not is_valid(v.semantics)]
+  valid_variants = [v for v in variants_filtered if is_valid(v.semantics)]
+  invalid_variants = [v for v in variants_filtered if not is_valid(v.semantics)]
 
   print("Valid variants:", len(valid_variants))
   print("Invalid variants:", len(invalid_variants))
@@ -82,7 +77,7 @@ if __name__ == "__main__":
   }
 
   state_id_to_semantics = {
-    statechart_model.tree.state_dict[state_name].opt.state_id: tup
+    statechart_model.tree.state_dict[state_name].state_id: tup
       for state_name, tup in state_name_to_semantics.items()
   }
 
@@ -98,8 +93,7 @@ if __name__ == "__main__":
     pass
 
   # List of input events for the big-step is always the same, so declare it outside the loop
-  input0_id = globals.events.get_id("input0")
-  input_events = [InternalEvent(id=input0_id, name="", params=[])]
+  input_events = [InternalEvent(name="input0", params=[])]
 
 
   def check_variants(variants):
@@ -140,6 +134,21 @@ if __name__ == "__main__":
 
 
   correct, incorrect = check_variants(valid_variants)
-  print("\nOf the valid variants, corrently inferred %d, incorrectly inferred %d." % (len(correct), len(incorrect)))
+  # for inc in correct:
+  #   print("CORRECT:")
+  #   print(inc)
+  # for inc in incorrect:
+  #   print("INCORRECT:")
+  #   print("what it was:", inc[0])
+  #   print("what the SC says it is:", inc[1])
+  print("\nOf the valid variants, correctly inferred %d, incorrectly inferred %d." % (len(correct), len(incorrect)))
   correct, incorrect = check_variants(invalid_variants)
-  print("Of the invalid variants, corrently inferred %d, incorrectly inferred %d." % (len(correct), len(incorrect)))
+  print("Of the invalid variants, correctly inferred %d, incorrectly inferred %d." % (len(correct), len(incorrect)))
+  # for inc in correct:
+  #   print("CORRECT:")
+  #   print(inc)
+  # for inc in incorrect:
+  #   print("INCORRECT:")
+  #   print("what it was:", inc[0])
+  #   print("what the SC says it is:", inc[1])
+

+ 13 - 13
examples/semantics/statechart_semantics.xml

@@ -79,8 +79,8 @@
         <state id="InternalEventLifeline" initial="Initial">
           <!-- <state id="NonRemainder" initial="Initial"> -->
           <state id="Initial">
-            <transition cond='INSTATE(["/P/InternalEventLifeline/RegionReceive1/GotEvent"]) and not INSTATE(["/P/InternalEventLifeline/RegionReceive2/GotEvent"])' target="../NextSmallStep"/>
-            <transition cond='INSTATE(["/P/InternalEventLifeline/RegionReceive1/GotEvent", "/P/InternalEventLifeline/RegionReceive2/GotEvent"])' target="../Remainder"/>
+            <transition cond='@in("/P/InternalEventLifeline/RegionReceive1/GotEvent") and not @in("/P/InternalEventLifeline/RegionReceive2/GotEvent")' target="../NextSmallStep"/>
+            <transition cond='@in("/P/InternalEventLifeline/RegionReceive1/GotEvent") and @in("/P/InternalEventLifeline/RegionReceive2/GotEvent")' target="../Remainder"/>
             <transition target="../Queue"/>
           </state>
           <state id="NextSmallStep">
@@ -90,7 +90,7 @@
           <state id="NextComboStep">
           </state>
           <state id="Queue">
-            <transition cond='INSTATE(["/P/InternalEventLifeline/RegionReceive1/GotEvent", "/P/InternalEventLifeline/RegionReceive2/GotEvent"])' target="../NextComboStep"/>
+            <transition cond='@in("/P/InternalEventLifeline/RegionReceive1/GotEvent") and @in("/P/InternalEventLifeline/RegionReceive2/GotEvent")' target="../NextComboStep"/>
           </state>
         </state>
       </parallel>
@@ -182,17 +182,17 @@
 
         <state id="ComboStepMaximality" initial="NoComboSteps">
           <state id="NoComboSteps">
-            <transition event="not input0" cond='INSTATE(["/P/InputEventLifeline/FirstComboStep", "/P/ComboStepMaximality/InputEventDeducer/TakeOne"])' target="../TakeOne"/>
-            <transition event="not input0" cond='INSTATE(["/P/InputEventLifeline/FirstComboStep", "/P/ComboStepMaximality/InputEventDeducer/Syntactic"])' target="../Syntactic"/>
-            <transition event="not input0" cond='INSTATE(["/P/InputEventLifeline/FirstComboStep", "/P/ComboStepMaximality/InputEventDeducer/TakeMany"])' target="../TakeMany"/>
+            <transition event="not input0" cond='@in("/P/InputEventLifeline/FirstComboStep") and @in("/P/ComboStepMaximality/InputEventDeducer/TakeOne")' target="../TakeOne"/>
+            <transition event="not input0" cond='@in("/P/InputEventLifeline/FirstComboStep") and @in("/P/ComboStepMaximality/InputEventDeducer/Syntactic")' target="../Syntactic"/>
+            <transition event="not input0" cond='@in("/P/InputEventLifeline/FirstComboStep") and @in("/P/ComboStepMaximality/InputEventDeducer/TakeMany")' target="../TakeMany"/>
 
-            <transition event="not internal0" cond='INSTATE(["/P/InternalEventLifeline/InternalEventLifeline/NextComboStep", "/P/ComboStepMaximality/InternalEventDeducer/TakeOne"])' target="../TakeOne"/>
-            <transition event="not internal0" cond='INSTATE(["/P/InternalEventLifeline/InternalEventLifeline/NextComboStep", "/P/ComboStepMaximality/InternalEventDeducer/Syntactic"])' target="../Syntactic"/>
-            <transition event="not internal0" cond='INSTATE(["/P/InternalEventLifeline/InternalEventLifeline/NextComboStep", "/P/ComboStepMaximality/InternalEventDeducer/TakeMany"])' target="../TakeMany"/>
+            <transition event="not internal0" cond='@in("/P/InternalEventLifeline/InternalEventLifeline/NextComboStep") and @in("/P/ComboStepMaximality/InternalEventDeducer/TakeOne")' target="../TakeOne"/>
+            <transition event="not internal0" cond='@in("/P/InternalEventLifeline/InternalEventLifeline/NextComboStep") and @in("/P/ComboStepMaximality/InternalEventDeducer/Syntactic")' target="../Syntactic"/>
+            <transition event="not internal0" cond='@in("/P/InternalEventLifeline/InternalEventLifeline/NextComboStep") and @in("/P/ComboStepMaximality/InternalEventDeducer/TakeMany")' target="../TakeMany"/>
 
-            <transition cond='x == 1 and INSTATE(["/P/MemoryProtocol/MemoryProtocol/ComboStep", "/P/ComboStepMaximality/MemoryProtocolDeducer/TakeOne"])' target="../TakeOne"/>
-            <transition cond='x == 1 and INSTATE(["/P/MemoryProtocol/MemoryProtocol/ComboStep", "/P/ComboStepMaximality/MemoryProtocolDeducer/Syntactic"])' target="../Syntactic"/>
-            <transition cond='x == 1 and INSTATE(["/P/MemoryProtocol/MemoryProtocol/ComboStep", "/P/ComboStepMaximality/MemoryProtocolDeducer/TakeMany"])' target="../TakeMany"/>
+            <transition cond='x == 1 and @in("/P/MemoryProtocol/MemoryProtocol/ComboStep") and @in("/P/ComboStepMaximality/MemoryProtocolDeducer/TakeOne")' target="../TakeOne"/>
+            <transition cond='x == 1 and @in("/P/MemoryProtocol/MemoryProtocol/ComboStep") and @in("/P/ComboStepMaximality/MemoryProtocolDeducer/Syntactic")' target="../Syntactic"/>
+            <transition cond='x == 1 and @in("/P/MemoryProtocol/MemoryProtocol/ComboStep") and @in("/P/ComboStepMaximality/MemoryProtocolDeducer/TakeMany")' target="../TakeMany"/>
           </state>
 
           <state id="TakeOne"/>
@@ -202,4 +202,4 @@
       </parallel>
     </parallel>
   </root>
-</statechart>
+</statechart>