Simon Van Mierlo 9 лет назад
Родитель
Сommit
c02cf37a81

BIN
interface/PN/addbp.disabled.icon.gif


BIN
interface/PN/godevent.disabled.icon.gif


BIN
interface/PN/load.disabled.icon.gif


+ 163 - 52
interface/PN/main.py

@@ -7,6 +7,8 @@ transitions = []
 p2ts = []
 t2ps = []
 cond = threading.Condition()
+small_step_cond = threading.Condition()
+small_step_input = None
 
 class AttributeEditor(tk.Toplevel):
     def __init__(self, title, entries, callback):
@@ -106,6 +108,9 @@ class PlaceVis:
         self.canvas.itemconfig(self.name_text, text=attr_vals["name"])
         self.canvas.itemconfig(self.tokens_text, text=attr_vals["tokens"])
         window.destroy()
+        
+    def set_tokens(self, tokens):
+        self.canvas.itemconfig(self.tokens_text, text=str(tokens))
     
 class TransitionVis:
     H = 30
@@ -122,8 +127,10 @@ class TransitionVis:
         canvas.tag_bind(self.name_text, "<Double-Button-1>", self.edit)
         canvas.tag_bind(self.vis, "<B1-Motion>", self.move)
         canvas.tag_bind(self.name_text, "<B1-Motion>", self.move)
-        canvas.tag_bind(self.vis, "<Button-3>", self.delete)
-        canvas.tag_bind(self.name_text, "<Button-3>", self.delete)
+        canvas.tag_bind(self.vis, "<Button-3>", self.select)
+        canvas.tag_bind(self.name_text, "<Button-3>", self.select)
+        canvas.tag_bind(self.vis, "<Double-Button-3>", self.delete)
+        canvas.tag_bind(self.name_text, "<Double-Button-3>", self.delete)
         self.x = x
         self.y = y
         self.t2ps = []
@@ -139,6 +146,18 @@ class TransitionVis:
         self.last_click_x = event.x
         self.last_click_y = event.y
         
+    def set_enabled(self, enabled=False):
+        if enabled:
+            self.canvas.itemconfig(self.vis, fill="green")
+        else:
+            self.canvas.itemconfig(self.vis, fill="black")
+            
+    def select(self, event):
+        global small_step_input
+        small_step_input = {'type': 'selected_transition', 'value': self.name}
+        with small_step_cond:
+            small_step_cond.notify()
+        
     def delete(self, event):
         self.canvas.delete(self.vis)
         self.canvas.delete(self.name_text)
@@ -238,6 +257,7 @@ class MarkingVis:
     def __init__(self, canvas, x, y, node_id, content={}):
         self.node_id = node_id
         self.canvas = canvas
+        self.marking_val = content
         self.vis = canvas.create_text(x, y, text=str(content), font=('Helvetica', '14'))
         self.bbox = canvas.bbox(self.vis)
         canvas.move(self.vis, (self.bbox[2]-self.bbox[0])/2, (self.bbox[3]-self.bbox[1])/2)
@@ -247,6 +267,8 @@ class MarkingVis:
         canvas.tag_bind(self.rect, "<Button-1>", self.clicked)
         canvas.tag_bind(self.vis, "<B1-Motion>", self.move)
         canvas.tag_bind(self.rect, "<B1-Motion>", self.move)
+        canvas.tag_bind(self.vis, "<Button-3>", self.rightclicked)
+        canvas.tag_bind(self.rect, "<Button-3>", self.rightclicked)
         canvas.tag_lower(self.rect)
         self.x = x
         self.y = y
@@ -265,6 +287,12 @@ class MarkingVis:
             self.canvas.itemconfig(self.rect, fill="yellow")
         else:
             self.canvas.itemconfig(self.rect, fill="")
+            
+    def rightclicked(self, event):
+        global small_step_input
+        small_step_input = {'type': 'selected_marking', 'value': self.node_id}
+        with small_step_cond:
+            small_step_cond.notify()
     
     def clicked(self, event):
         event.widget.clicked = True
@@ -372,7 +400,7 @@ class PNInterface(tk.Tk):
                               "P2T": self.place_to_transition,
                               "T2P": self.transition_to_place}
         self.button_img = {}
-        self.buttons_vis = []
+        self.buttons_vis = {}
         i = 0
         for k in self.buttons:
             v = self.button_config[k]
@@ -381,7 +409,7 @@ class PNInterface(tk.Tk):
             else:
                 btn = tk.Button(self.modelling_toolbar_frame, text=k, command=v)
             btn.grid(row=0, column=i, padx=self.INTER_SPACING, sticky=tk.W)
-            self.buttons_vis.append(btn)
+            self.buttons_vis[k] = btn
             i += 1
         
         # debugging toolbar
@@ -390,18 +418,23 @@ class PNInterface(tk.Tk):
         
         self.INTER_SPACING = 5
         
-        self.buttons = ["Load", "Continuous", "Step", "Manual", "Add_Breakpoint"]
-        self.button_config = {"Load": self.load,
-                              "Continuous": self.continuous,
-                              "Step": self.step,
-                              "Manual": self.manual,
-                              "Add_Breakpoint": self.add_breakpoint}
-        self.button_img = {"Load": tk.PhotoImage(file="load.icon.gif"),
-                           "Continuous": tk.PhotoImage(file="simulate.icon.gif"),
-                           "Step": tk.PhotoImage(file="step.icon.gif"),
-                           "Manual": tk.PhotoImage(file="godevent.icon.gif"),
-                           "Add_Breakpoint": tk.PhotoImage(file="addbp.icon.gif")}
-        self.buttons_vis = []
+        self.buttons = ["load", "continuous", "step", "manual", "add_breakpoint"]
+        self.button_config = {"load": self.load,
+                              "continuous": self.continuous,
+                              "step": self.step,
+                              "manual": self.manual,
+                              "add_breakpoint": self.add_breakpoint}
+        self.button_img = {"load": tk.PhotoImage(file="load.icon.gif"),
+                           "continuous": tk.PhotoImage(file="simulate.icon.gif"),
+                           "step": tk.PhotoImage(file="step.icon.gif"),
+                           "manual": tk.PhotoImage(file="godevent.icon.gif"),
+                           "add_breakpoint": tk.PhotoImage(file="addbp.icon.gif")}
+        self.button_img_disabled = {"load": tk.PhotoImage(file="load.disabled.icon.gif"),
+                                    "continuous": tk.PhotoImage(file="simulate.disabled.icon.gif"),
+                                    "step": tk.PhotoImage(file="step.disabled.icon.gif"),
+                                    "manual": tk.PhotoImage(file="godevent.disabled.icon.gif"),
+                                    "add_breakpoint": tk.PhotoImage(file="addbp.disabled.icon.gif")}
+        self.buttons_vis = {}
         i = 0
         for k in self.buttons:
             v = self.button_config[k]
@@ -410,7 +443,10 @@ class PNInterface(tk.Tk):
             else:
                 btn = tk.Button(self.debugging_toolbar_frame, text=k, command=v)
             btn.grid(row=0, column=i, padx=self.INTER_SPACING, sticky=tk.W)
-            self.buttons_vis.append(btn)
+            self.buttons_vis[k] = btn
+            if k != "load":
+                btn.config(state=tk.DISABLED)
+                btn.config(image=self.button_img_disabled[k])
             i += 1
         
         # Petrinets canvas        
@@ -446,6 +482,15 @@ class PNInterface(tk.Tk):
         self.grid_rowconfigure(1, weight=1)
         
         self.setup()
+        
+    def enable_buttons(self, commands):
+        for (k, btn) in self.buttons_vis.items():
+            if k in commands:
+                btn.config(state=tk.NORMAL)
+                btn.config(image=self.button_img[k])
+            else:
+                btn.config(state=tk.DISABLED)
+                btn.config(image=self.button_img_disabled[k])
 
     def setup(self):
         free = PlaceVis(self.pn_canvas, 100, 200, "free", 3)
@@ -506,8 +551,8 @@ class PNInterface(tk.Tk):
         
     def place_to_transition(self):
         def create_p2t(attr_vals, window):
-            src = [p for p in self.places if p.get_name() == attr_vals["src"]]
-            dst = [t for t in self.transitions if t.get_name() == attr_vals["dst"]]
+            src = [p for p in places if p.get_name() == attr_vals["src"]]
+            dst = [t for t in transitions if t.get_name() == attr_vals["dst"]]
             if len(src) == 1 and len(dst) == 1:
                 global p2ts
                 p2ts.append(PlaceToTransitionVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
@@ -518,8 +563,8 @@ class PNInterface(tk.Tk):
         
     def transition_to_place(self):
         def create_t2p(attr_vals, window):
-            src = [t for t in self.transitions if t.get_name() == attr_vals["src"]]
-            dst = [p for p in self.places if p.get_name() == attr_vals["dst"]]
+            src = [t for t in transitions if t.get_name() == attr_vals["src"]]
+            dst = [p for p in places if p.get_name() == attr_vals["dst"]]
             if len(src) == 1 and len(dst) == 1:
                 global t2ps
                 t2ps.append(TransitionToPlaceVis(self.pn_canvas, src[0], dst[0], attr_vals["weight"]))
@@ -529,6 +574,7 @@ class PNInterface(tk.Tk):
         editor = AttributeEditor('Create T2P', {"weight": 1, "src": "", "dst": ""}, create_t2p)
         
     def load(self):
+        self.enable_buttons([])
         with open("model.mvc", "w+") as model_file:
             for p in places:
                 model_file.write("Place %s {\n" % p.name.replace(" ", "_"))
@@ -592,40 +638,70 @@ class PNInterface(tk.Tk):
                     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']))
+            elif parsed_value["msg_type"] == "input_required":
+                if (not self.breakpoint_info_entered):
+                    with cond:
+                        cond.wait()
+                if parsed_value["name"] == "breakpoint name":
+                    return self.breakpoint_name
+                elif parsed_value["name"] == "disable on trigger?":
+                    return self.breakpoint_disable_on_trigger
+                elif parsed_value["name"] == "breakpoint function":
+                    upload_code(self.breakpoint_code)
+            elif parsed_value["msg_type"] == "enabled_commands":
+                self.enable_buttons(set(parsed_value["commands"]))
+                with cond:
+                    cond.wait()
+                return self.sim_mode
+            elif parsed_value["msg_type"] == "unexplored_markings":
+                unexplored_markings = set(parsed_value["markings"])
+                for m in self.markings:
+                    if m.node_id in unexplored_markings:
+                        m.set_current(True)
+                global small_step_input
+                small_step_input = None
+                while (small_step_input == None or small_step_input['type'] != 'selected_marking'):
+                    print 'waiting'
+                    with small_step_cond:
+                        small_step_cond.wait()
+                    print 'waiting done'
+                if (small_step_input['type'] == 'selected_marking'):
+                    self.load_marking(small_step_input['value'])
+                return small_step_input['value']
+            elif parsed_value["msg_type"] == "enabled_transitions":
+                enabled_transitions = set(parsed_value["transitions"])
+                for t in transitions:
+                    if t.name in enabled_transitions:
+                        t.set_enabled(True)
+                global small_step_input
+                small_step_input = None
+                while (small_step_input == None or small_step_input['type'] != 'selected_transition'):
+                    print 'waiting'
+                    with small_step_cond:
+                        small_step_cond.wait()
+                    print 'waiting done'
+                if (small_step_input['type'] == 'selected_transition'):
+                    for t in transitions:
+                        t.set_enabled(False)
+                    for m in self.markings:
+                        m.set_current(False)
+                return small_step_input['value']
+            elif parsed_value["msg_type"] == "mode_change":
+                if parsed_value["mode"] == "paused":
+                    with cond:
+                        cond.wait()
+                    return self.sim_mode
             return
         if value.startswith("#"):
             value = value[1:]
             print(value)
             return
-        if value.startswith("%"):
-            if (value[1:] == "construct_function"):
-                print("Enter your code...")
-                code = \
-                    """
-                    include "primitives.alh"
-
-                    Boolean function bp_1(reachable_states: Element, mappings: Element):
-                        log("Breakpoint check!")
-                        
-                        Element keys
-                        Element node
-                        String msg
-                        keys = dict_keys(reachable_states)
-                        while (read_nr_out(keys) > 0):
-                            node = reachable_states[set_pop(keys)]
-                            msg = cast_v2s(node["critical_section_2"])
-                            msg = "critical_section_2 = " + msg
-                            log(msg)
-                            if (integer_gt(node["critical_section_2"], 0)):
-                                return True!
-                        return False!
-                    """
-                upload_code(code)
-            return
-        print(value)
-        with cond:
-            cond.wait()
-        return self.sim_mode
+            
+    def load_marking(self, node_id):
+        marking = [m for m in self.markings if m.node_id == node_id][0]
+        for (k, v) in marking.marking_val.iteritems():
+            place = [p for p in places if p.name == k][0]
+            place.set_tokens(v)
         
     def continuous(self):
         self.sim_mode = "continuous"
@@ -646,16 +722,51 @@ class PNInterface(tk.Tk):
         self.sim_mode = "add_breakpoint"
         with cond:
             cond.notify()
+        self.breakpoint_name = None
+        self.breakpoint_disable_on_trigger = False
+        self.breakpoint_code = None
+        def edit_done(attr_vals, window):
+            self.breakpoint_name = attr_vals["breakpoint name"]
+            if attr_vals["disable on trigger?"] == "True":
+                self.breakpoint_disable_on_trigger = True
+            window.destroy()
+            with cond:
+                cond.notify()
+            self.breakpoint_info_entered = True
+        self.breakpoint_info_entered = False
+        editor = AttributeEditor('Input', {"breakpoint name": "", "disable on trigger?": "True"}, edit_done)
+        self.breakpoint_code = \
+            """
+            include "primitives.alh"
+
+            Boolean function bp_1(reachable_states: Element, mappings: Element):
+                log("Breakpoint check!")
+                
+                Element keys
+                Element node
+                String msg
+                keys = dict_keys(reachable_states)
+                while (read_nr_out(keys) > 0):
+                    node = reachable_states[set_pop(keys)]
+                    msg = cast_v2s(node["produced"])
+                    msg = "produced = " + msg
+                    log(msg)
+                    if (integer_gt(node["produced"], 0)):
+                        return True!
+                return False!
+            """
     
     def clicked(self, event):
         if hasattr(event.widget, 'clicked') and event.widget.clicked:
             event.widget.clicked = False
             return
+        global places
+        global transitions
         if self.mode in ["PLACE", "TRANSITION"]:
             if self.mode == "PLACE":
-                self.places.append(PlaceVis(self.pn_canvas, event.x, event.y))
+                places.append(PlaceVis(self.pn_canvas, event.x, event.y))
             if self.mode == "TRANSITION":
-                self.transitions.append(TransitionVis(self.pn_canvas, event.x, event.y))
+                transitions.append(TransitionVis(self.pn_canvas, event.x, event.y))
     
     def draw(self, event):
         pass

BIN
interface/PN/simulate.disabled.icon.gif


BIN
interface/PN/step.disabled.icon.gif


+ 83 - 55
models/reachability.alc

@@ -64,7 +64,7 @@ Boolean function reachability_graph(model : Element):
     mode = "paused"
     
     while (True):
-        output("Please enter your command. Options: continuous, step, manual, add_breakpoint")
+        output('{"msg_type": "enabled_commands", "commands": ["step", "continuous", "manual", "add_breakpoint"]}')
         user_input = input()
         if (user_input == "step"):
             break!
@@ -75,20 +75,21 @@ Boolean function reachability_graph(model : Element):
         if (user_input == "add_breakpoint"):
             bp_name = ""
             while (bool_or(bp_name == "", dict_in(breakpoints, bp_name))):
-                output("Please enter a breakpoint name.")
+                output('{"msg_type": "input_required", "name": "breakpoint name", "type": "string"}')
                 bp_name = input()
-                output("Disable on trigger? (default = True)")
+                output('{"msg_type": "input_required", "name": "disable on trigger?", "type": "boolean"}')
                 disable_on_trigger_str = input()
-                if (disable_on_trigger_str == "False"):
-                    disable_on_trigger = False
-                else:
+                if (disable_on_trigger_str == "True"):
                     disable_on_trigger = True
-            output("%construct_function")
+                else:
+                    disable_on_trigger = False
+            output('{"msg_type": "input_required", "name": "breakpoint function", "type": "code"}')
             new_breakpoint = create_node()
             dict_add_fast(new_breakpoint, "function", construct_function())
             dict_add_fast(new_breakpoint, "disable_on_trigger", disable_on_trigger)
             dict_add_fast(new_breakpoint, "enabled", True)
             dict_add_fast(breakpoints, bp_name, new_breakpoint)
+            output(('{"msg_type": "state_change", "state": "breakpoint_added", "breakpoint_name": ' + bp_name) + '}')
     mode = user_input
 
     // Create a dictionary representation for each transition
@@ -97,6 +98,8 @@ Boolean function reachability_graph(model : Element):
     all_transitions = allInstances(model, "PetriNet/Transition")
     while (read_nr_out(all_transitions) > 0):
         transition = set_pop(all_transitions)
+        String transition_name
+        transition_name = read_attribute(model, transition, "name")
 
         tv = create_node()
         links = allIncomingAssociationInstances(model, transition, "PetriNet/P2T")
@@ -105,7 +108,7 @@ Boolean function reachability_graph(model : Element):
             name = reverseKeyLookup(model["model"], read_edge_src(model["model"][link]))
             link_weight = read_attribute(model, link, "weight")
             dict_add_fast(tv, name, link_weight)
-        dict_add_fast(transition_vectors_consume, transition, tv)
+        dict_add_fast(transition_vectors_consume, transition_name, tv)
 
         tv = create_node()
         links = allOutgoingAssociationInstances(model, transition, "PetriNet/T2P")
@@ -114,7 +117,7 @@ Boolean function reachability_graph(model : Element):
             name = reverseKeyLookup(model["model"], read_edge_dst(model["model"][link]))
             link_weight = read_attribute(model, link, "weight")
             dict_add_fast(tv, name, link_weight)
-        dict_add_fast(transition_vectors_produce, transition, tv)
+        dict_add_fast(transition_vectors_produce, transition_name, tv)
 
     workset = create_node()
 
@@ -155,27 +158,26 @@ Boolean function reachability_graph(model : Element):
     all_transitions = set_copy(all_transitions_original)
     while (read_nr_out(all_transitions) > 0):
         transition = set_pop(all_transitions)
+        String transition_name
+        transition_name = read_attribute(model, transition, "name")
 
-        keys = dict_keys(transition_vectors_consume[transition])
+        keys = dict_keys(transition_vectors_consume[transition_name])
         possible = True
         while (read_nr_out(keys) > 0):
             key = set_pop(keys)
 
             // Compare the values in the state with those consumed by the transition
-            if (integer_lt(dict_repr[key], transition_vectors_consume[transition][key])):
+            if (integer_lt(dict_repr[key], transition_vectors_consume[transition_name][key])):
                 // Impossible transition, so discard this one
                 possible = False
                 break!
         if (possible):
-            set_add(enabled_transitions_set, transition)
+            set_add(enabled_transitions_set, transition_name)
             
     if (read_nr_out(enabled_transitions[state_id]) > 0):
         set_add(workset, state_id)
     
     if (bool_or(mode == "step", mode == "manual")):
-        if (mode == "step"):
-            mode = "paused"
-            output('{"msg_type": "mode_change", "mode": "paused"}')
         output('{"msg_type": "state_change", "state": "initialized"}')
         
         Element dict_values
@@ -189,6 +191,10 @@ Boolean function reachability_graph(model : Element):
         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) + '}}')
+        
+        if (mode == "step"):
+            mode = "paused"
+            output('{"msg_type": "mode_change", "mode": "paused"}')
     
         while (True):
             if (mode == "manual"):
@@ -207,18 +213,26 @@ Boolean function reachability_graph(model : Element):
 
     while (read_nr_out(workset) > 0):
         if (mode == "manual"):
-            output("#markings to explore: ")
+            String markings
+            markings = '['
             workset_copy = set_copy(workset)
             while (read_nr_out(workset_copy) > 0):
                 curr_workset_el = set_pop(workset_copy)
-                output("#    " + cast_i2s(curr_workset_el))
+                markings = ((markings + '"') + cast_v2s(curr_workset_el)) + '"'
+                if (read_nr_out(workset_copy) > 0):
+                    markings = markings + ", "
+            markings = markings + "]"
+            output('{"msg_type": "state_change", "state": "small_step_done"}')
+            output(('{"msg_type": "unexplored_markings", "markings": ' + markings) + '}')
             while (True):
-                output("Please choose a marking.")
+                log("Please choose a marking.")
                 user_input_i = cast_s2i(input())
                 if (set_in(workset, user_input_i)):
+                    log("Marking found!")
                     state_id = user_input_i
                     set_remove(workset, state_id)
                     break!
+                log("Marking *not* found!")
         else:
             state_id = set_pop(workset)
             
@@ -226,14 +240,21 @@ Boolean function reachability_graph(model : Element):
         enabled_transitions_set = enabled_transitions[state_id]
 
         if (mode == "manual"):
-            output("#enabled: ")
+            String enabled_transitions_output
+            enabled_transitions_output = '['
             enabled_copy = set_copy(enabled_transitions_set)
             while (read_nr_out(enabled_copy) > 0):
                 curr_transition = set_pop(enabled_copy)
-                output("#    " + curr_transition)
+                enabled_transitions_output = enabled_transitions_output + cast_v2s(curr_transition)
+                if (read_nr_out(enabled_copy) > 0):
+                    enabled_transitions_output = enabled_transitions_output + ", "
+            enabled_transitions_output = enabled_transitions_output + "]"
+            output('{"msg_type": "state_change", "state": "small_step_done"}')
+            output(('{"msg_type": "enabled_transitions", "transitions": ' + enabled_transitions_output) + '}')
             while (True):
                 output("Please choose an enabled transition.")
                 user_input = input()
+                log(user_input)
                 if (set_in(enabled_transitions_set, user_input)):
                     transition = user_input
                     set_remove(enabled_transitions_set, transition)
@@ -313,19 +334,21 @@ Boolean function reachability_graph(model : Element):
             all_transitions = set_copy(all_transitions_original)
             while (read_nr_out(all_transitions) > 0):
                 tmp_transition = set_pop(all_transitions)
+                String transition_name
+                transition_name = read_attribute(model, tmp_transition, "name")
 
-                keys = dict_keys(transition_vectors_consume[tmp_transition])
+                keys = dict_keys(transition_vectors_consume[transition_name])
                 possible = True
                 while (read_nr_out(keys) > 0):
                     key = set_pop(keys)
 
                     // Compare the values in the state with those consumed by the transition
-                    if (integer_lt(new_dict_repr[key], transition_vectors_consume[tmp_transition][key])):
+                    if (integer_lt(new_dict_repr[key], transition_vectors_consume[transition_name][key])):
                         // Impossible transition, so discard this one
                         possible = False
                         break!
                 if (possible):
-                    set_add(enabled_transitions_set, tmp_transition)
+                    set_add(enabled_transitions_set, transition_name)
                     
             if (read_nr_out(enabled_transitions[target_id]) > 0):
                 set_add(workset, target_id)
@@ -335,14 +358,13 @@ Boolean function reachability_graph(model : Element):
 
         // And also store it in the model itself
         new_transition = instantiate_link(model, "ReachabilityGraph/Transition", "", cast_i2s(state_id), cast_i2s(target_id))
-        instantiate_attribute(model, new_transition, "name", read_attribute(model, transition, "name"))
+        instantiate_attribute(model, new_transition, "name", transition)
 
         if (bool_or(mode == "step", mode == "manual")):
-            if (mode == "step"):
-                mode = "paused"
-                output('{"msg_type": "mode_change", "mode": "paused"}')
+            if (mode == "manual"):
+                output('{"msg_type": "state_change", "state": "small_step_done"}')
             output('{"msg_type": "state_change", "state": "step_done"}')
-
+            
             if (new_node):
                 Element dict_values
                 Element all_values
@@ -355,6 +377,10 @@ Boolean function reachability_graph(model : Element):
                 String marking
                 marking = dict_to_string(dict_values)
                 output(((('{"msg_type": "node_added", "node_info": {"node_id": ' + cast_v2s(read_attribute(model, cast_i2s(target_id), "name"))) + ', "node_marking": ') + marking) + '}}')
+                
+            if (mode == "step"):
+                mode = "paused"
+                output('{"msg_type": "mode_change", "mode": "paused"}')
             
             // String link_output
             //link_output = '{"msg_type": "link_added", "link_info": {'
@@ -375,32 +401,38 @@ Boolean function reachability_graph(model : Element):
             curr_bp_function = curr_bp["function"]
             if (bool_and(curr_bp["enabled"], curr_bp_function(reachable_states, mappings))):
                 output(('{"msg_type": "state_change", "state": "breakpoint_triggered", "breakpoint_name": ' + curr_bp_name) + '}')
-                if (bool_not(mode == "paused")):
-                    mode = "paused"
-                    output('{"msg_type": "mode_change", "mode": "paused"}')
                 bp_triggered = True
                 if (curr_bp["disable_on_trigger"]):
                     dict_delete(curr_bp, "enabled")
                     dict_add_fast(curr_bp, "enabled", False)
         if (bp_triggered):
-            reachable_keys_copy = dict_keys(reachable_states)
-            while (read_nr_out(reachable_keys_copy) > 0):
-                key = set_pop(reachable_keys_copy)
-                to_construct = ("#" + cast_v2s(key))
-                to_construct = to_construct + ": "
-                to_construct = to_construct + dict_to_string(reachable_states[key])
-                output(to_construct)
-                keys = dict_keys(mappings[key])
-                while (read_nr_out(keys) > 0):
-                    curr_transition = set_pop(keys)
-                    to_construct = ("#" + cast_v2s(key))
-                    to_construct = to_construct + " --["
-                    to_construct = to_construct + cast_v2s(curr_transition)
-                    to_construct = to_construct + "]--> "
-                    to_construct = to_construct + cast_v2s(mappings[key][curr_transition])
-                    output(to_construct)
-
-        log("# reachable states: " + cast_v2s(next_id))
+            Element all_states
+            Element curr_state
+            all_states = allInstances(model, "ReachabilityGraph/State")
+            to_construct = '{"msg_type": "reachable_nodes", "nodes": ['
+            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 + "}"
+                if (read_nr_out(all_states) > 0):
+                    to_construct = to_construct + ', '
+            to_construct = to_construct + ']}'
+            output(to_construct)
+            // TODO: Transitions
+            if (bool_not(mode == "paused")):
+                mode = "paused"
+                output('{"msg_type": "mode_change", "mode": "paused"}')
                     
         if (bool_not(mode == "continuous")):
             while (True):
@@ -418,14 +450,10 @@ 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": '
@@ -440,14 +468,14 @@ Boolean function reachability_graph(model : Element):
             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
+    
+    output('{"msg_type": "mode_change", "mode": "finished"}')
             
     log("# reachable states: " + cast_v2s(next_id))
     return True!