Browse Source

updated interface - now states are correctly transmitted

Simon Van Mierlo 9 years ago
parent
commit
58ef37f5e0
2 changed files with 67 additions and 12 deletions
  1. 21 5
      interface/PN/main.py
  2. 46 7
      models/reachability.alc

+ 21 - 5
interface/PN/main.py

@@ -449,12 +449,13 @@ class PNInterface(tk.Tk):
 
     def setup(self):
         free = PlaceVis(self.pn_canvas, 100, 200, "free", 3)
+        max_items = PlaceVis(self.pn_canvas, 150, 400, "maximum items", 3)
         producing = PlaceVis(self.pn_canvas, 200, 200, "producing", 0)
         produced = PlaceVis(self.pn_canvas, 300, 200, "produced", 0)
         waiting = PlaceVis(self.pn_canvas, 400, 200, "waiting", 2)
         consuming = PlaceVis(self.pn_canvas, 500, 200, "consuming", 0)
         global places
-        places = [free, producing, produced, waiting, consuming]
+        places = [free, producing, produced, waiting, consuming, max_items]
         
         start_produce = TransitionVis(self.pn_canvas, 150, 100, "start producing")
         end_produce = TransitionVis(self.pn_canvas, 150, 300, "end producing")
@@ -466,6 +467,7 @@ class PNInterface(tk.Tk):
         f_to_s_p = PlaceToTransitionVis(self.pn_canvas, free, start_produce)
         s_p_to_p = TransitionToPlaceVis(self.pn_canvas, start_produce, producing)
         p_to_e_p = PlaceToTransitionVis(self.pn_canvas, producing, end_produce)
+        m_i_to_e_p = PlaceToTransitionVis(self.pn_canvas, max_items, end_produce)
         e_p_to_f = TransitionToPlaceVis(self.pn_canvas, end_produce, free)
         
         w_to_s_c = PlaceToTransitionVis(self.pn_canvas, waiting, start_consume)
@@ -476,7 +478,7 @@ class PNInterface(tk.Tk):
         e_p_to_p = TransitionToPlaceVis(self.pn_canvas, end_produce, produced)
         p_to_s_c = PlaceToTransitionVis(self.pn_canvas, produced, start_consume)
         global p2ts
-        p2ts = [f_to_s_p, p_to_e_p, w_to_s_c, c_to_e_c, p_to_s_c]
+        p2ts = [f_to_s_p, p_to_e_p, w_to_s_c, c_to_e_c, p_to_s_c, m_i_to_e_p]
         global t2ps
         t2ps = [s_p_to_p, e_p_to_f, s_c_to_c, e_c_to_w, e_p_to_p]
         
@@ -558,12 +560,21 @@ class PNInterface(tk.Tk):
         except ModelExists:
             pass
             
+        def executeAL():
+            print("Execute AL")
+            status = transformation_execute_AL("analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, callback=self.callback)
+            print("Reachability generation success: " + str(status))
+        
+            print("Execute MT")
+            def print_mv(value):
+                print(value)
+            status = transformation_execute_MT("printReachability", {"ReachabilityGraph": "my_reachability"}, {}, callback=print_mv)
+            print("Reachability printing success: " + str(status))
+            
         # Start the reachability graph generation
-        print("Execute AL")
-        thrd = threading.Thread(target=transformation_execute_AL, args=["analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, self.callback])
+        thrd = threading.Thread(target=executeAL)
         thrd.daemon = True
         thrd.start()
-        # status = transformation_execute_AL("analyseReachability", {"PetriNet": "my_pn"}, {"ReachabilityGraph": "my_reachability"}, callback=self.callback)
         
     def callback(self, value):
         if value.startswith("{"):
@@ -576,6 +587,11 @@ class PNInterface(tk.Tk):
                 m2 = [m for m in self.markings if m.node_id == parsed_value['link_info']['target']][0]
                 t = [t for t in transitions if t.name == parsed_value['link_info']['transition']][0]
                 self.m2ms.append(MarkingToMarkingVis(self.rg_canvas, m1, m2, t))
+            elif parsed_value["msg_type"] == "reachable_nodes":
+                for n in parsed_value["nodes"]:
+                    node_id = n['node_id']
+                    if len([m for m in self.markings if m.node_id == node_id]) == 0:
+                        self.markings.append(MarkingVis(self.rg_canvas, 100, 50, node_id, n['node_marking']))
             return
         if value.startswith("#"):
             value = value[1:]

+ 46 - 7
models/reachability.alc

@@ -354,12 +354,18 @@ Boolean function reachability_graph(model : Element):
                     dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
                 String marking
                 marking = dict_to_string(dict_values)
-                output(((('{"msg_type": "node_added", "node_info": {"node_id": ' + cast_v2s(read_attribute(model, cast_i2s(state_id), "name"))) + ', "node_marking": ') + marking) + '}}')
+                output(((('{"msg_type": "node_added", "node_info": {"node_id": ' + cast_v2s(read_attribute(model, cast_i2s(target_id), "name"))) + ', "node_marking": ') + marking) + '}}')
             
-            String link_output
-            link_output = '{"msg_type": "link_added", "link_info": {'
-            link_output = link_output + '}}'
-            output(link_output)
+            // String link_output
+            //link_output = '{"msg_type": "link_added", "link_info": {'
+            //link_output = link_output + '"transition": '
+            //link_output = link_output + cast_v2s(new_transition)
+            //link_output = link_output + ', "source": '
+            //link_output = link_output + cast_v2s(state_id)
+            //link_output = link_output + ', "target": '
+            //link_output = link_output + cast_v2s(target_id)
+            //link_output = link_output + '}}'
+            // output(link_output)
             
         bp_keys = dict_keys(breakpoints)
         bp_triggered = False
@@ -368,10 +374,10 @@ Boolean function reachability_graph(model : Element):
             curr_bp = breakpoints[curr_bp_name]
             curr_bp_function = curr_bp["function"]
             if (bool_and(curr_bp["enabled"], curr_bp_function(reachable_states, mappings))):
-                output(("#breakpoint " + curr_bp_name) + " triggered")
+                output(('{"msg_type": "state_change", "state": "breakpoint_triggered", "breakpoint_name": ' + curr_bp_name) + '}')
                 if (bool_not(mode == "paused")):
                     mode = "paused"
-                    output("#mode: paused")
+                    output('{"msg_type": "mode_change", "mode": "paused"}')
                 bp_triggered = True
                 if (curr_bp["disable_on_trigger"]):
                     dict_delete(curr_bp, "enabled")
@@ -394,6 +400,8 @@ Boolean function reachability_graph(model : Element):
                     to_construct = to_construct + cast_v2s(mappings[key][curr_transition])
                     output(to_construct)
 
+        log("# reachable states: " + cast_v2s(next_id))
+                    
         if (bool_not(mode == "continuous")):
             while (True):
                 if (mode == "manual"):
@@ -410,5 +418,36 @@ Boolean function reachability_graph(model : Element):
                     mode = user_input
                     break!
 
+    output('{"msg_type": "mode_change", "mode": "finished"}')
+    // reachable_keys_copy = dict_keys(reachable_states)
+    Element all_states
+    Element curr_state
+    all_states = allInstances(model, "ReachabilityGraph/State")
+    to_construct = '{"msg_type": "reachable_nodes", "nodes": ['
+    // while (read_nr_out(reachable_keys_copy) > 0):
+        // key = set_pop(reachable_keys_copy)
+    while (read_nr_out(all_states) > 0):
+        curr_state = set_pop(all_states)
+        to_construct = to_construct + '{"node_id": '
+        to_construct = to_construct + cast_v2s(curr_state)
+        to_construct = to_construct + ',  "node_marking": '
+        Element dict_values
+        Element all_values
+        String place
+        dict_values = create_node()
+        all_values = allAssociationDestinations(model, curr_state, "ReachabilityGraph/Contains")
+        while (set_len(all_values) > 0):
+            place = set_pop(all_values)
+            dict_add(dict_values, read_attribute(model, place, "name"), read_attribute(model, place, "tokens"))
+        to_construct = to_construct + dict_to_string(dict_values)
+        // to_construct = to_construct + dict_to_string(reachable_states[key])
+        to_construct = to_construct + "}"
+        // if (read_nr_out(reachable_keys_copy) > 0):
+        if (read_nr_out(all_states) > 0):
+            to_construct = to_construct + ', '
+    to_construct = to_construct + ']}'
+    output(to_construct)
+    // TODO: Transitions
+            
     log("# reachable states: " + cast_v2s(next_id))
     return True!