def assign_from(self, other, assign_ids=False, copy_view_data=True): """Assigns the attributes of the location from another location. Args: other: The other location. assign_ids: Choose whether the IDs should be copied, too, or generated anew. copy_view_data: Choose whether the graphical view data should be copied as well. """ super().assign_from(other, assign_ids=assign_ids) self.invariants = map(lambda inv: inv.copy(), other.invariants) self.urgent = other.urgent self.committed = other.committed if copy_view_data: self.view = {} self.view["self"] = { "pos": { "x": other.view["self"]["pos"]["x"], "y": other.view["self"]["pos"]["y"] } } self.view["name_label"] = { "pos": { "x": other.view["name_label"]["pos"]["x"], "y": other.view["name_label"]["pos"]["y"] }, "id": unique_id("label") } self.view["invariant_label"] = { "pos": { "x": other.view["invariant_label"]["pos"]["x"], "y": other.view["invariant_label"]["pos"]["y"] }, "id": unique_id("label") }
def assign_from(self, other, assign_ids=False, copy_view_data=True): """Assigns the attributes of the edge from another edge. Args: other: The other edge. assign_ids: Choose whether the IDs should be copied, too, or generated anew. copy_view_data: Choose whether the graphical view data should be copied as well. """ super().assign_from(other) self.clock_guards = map(lambda grd: grd.copy(), other.clock_guards) self.variable_guards = map(lambda grd: grd.copy(), other.variable_guards) self.updates = map(lambda updt: updt.copy(), other.updates) self.resets = map(lambda rst: rst.copy(), other.resets) self.sync = other.sync.copy() if other.sync else None self.selects = map(lambda sel: sel.copy(), other.selects) if copy_view_data: self.view = {"nails": OrderedDict()} for nail_id in other.view["nails"]: nail = {"id": unique_id("nail"), "pos": {"x": other.view["nails"][nail_id]["pos"]["x"], "y": other.view["nails"][nail_id]["pos"]["y"]}} self.view["nails"][nail["id"]] = nail self.view["guard_label"] = { "pos": {"x": other.view["guard_label"]["pos"]["x"], "y": other.view["guard_label"]["pos"]["y"]}, "id": unique_id("label")} self.view["update_label"] = { "pos": {"x": other.view["update_label"]["pos"]["x"], "y": other.view["update_label"]["pos"]["y"]}, "id": unique_id("label")} self.view["sync_label"] = { "pos": {"x": other.view["sync_label"]["pos"]["x"], "y": other.view["sync_label"]["pos"]["y"]}, "id": unique_id("label")} self.view["select_label"] = { "pos": {"x": other.view["select_label"]["pos"]["x"], "y": other.view["select_label"]["pos"]["y"]}, "id": unique_id("label")}
def __init__(self, source, target, parent=None, id_=None): """Initializes Edge. Args: source: The source location object. target: The target location object. parent: The parent automaton object. id_: The unique edge ID ("edge-..."). """ super().__init__(source, target, parent, id_ if id_ else unique_id("edge")) self.clock_guards = [] self.variable_guards = [] self.updates = [] self.resets = [] self.sync = None self.selects = [] self.view = {"nails": OrderedDict()} center = {"x": int((self.source.view["self"]["pos"]["x"] + self.target.view["self"]["pos"]["x"]) / 2), "y": int((self.source.view["self"]["pos"]["y"] + self.target.view["self"]["pos"]["y"]) / 2)} self.view["guard_label"] = {"pos": {"x": center["x"], "y": center["y"] - 20}, "id": unique_id("label")} self.view["update_label"] = {"pos": {"x": center["x"], "y": center["y"]}, "id": unique_id("label")} self.view["sync_label"] = {"pos": {"x": center["x"], "y": center["y"] + 20}, "id": unique_id("label")} self.view["select_label"] = {"pos": {"x": center["x"], "y": center["y"] - 40}, "id": unique_id("label")}
def __init__(self, name=None, parent=None, id_=None): """Initializes Location. Args: name: The location name. parent: The parent automaton object. id_: The unique location ID ("loc-..."). """ super().__init__(name, parent, id_ if id_ else unique_id("loc")) self.invariants = [] self.urgent = False self.committed = False self.view = {"self": {"pos": {"x": 0, "y": 0}}, "name_label": {"pos": {"x": 20, "y": -20}, "id": unique_id("label")}, "invariant_label": {"pos": {"x": 20, "y": 20}, "id": unique_id("label")}}
def __init__(self, name, id_=None): """Initializes Template. Args: name: The template name. id_: The unique template ID ("tmpl-..."). """ super().__init__(name, id_ if id_ else unique_id("tmpl")) self.parameters = []
def __init__(self, name=None, id_=None): """Initializes WeightedGraph. Args: name: The graph name. id_: The unique graph ID ("w-graph-..."). """ id_ = id_ if id_ else unique_id("w-graph") super().__init__(name, id_)
def __init__(self, name, id_=None): """Initializes Automaton. Args: name: The automaton name. id_: The unique automaton ID ("atmt-..."). """ super().__init__(name, id_ if id_ else unique_id("atmt")) self.declaration = None self.init_loc = None
def add_nail(self, pos): """Adds a fixed point (nail) to the graphical representation of the edge. Args: pos: The fixed point position. Returns: None """ nail_id = unique_id("nail") self.view["nails"][nail_id] = {"pos": pos}
def __init__(self, name=None, id_=None): """Initializes Graph. Args: name: The graph name. id_: The unique graph ID ("graph-..."). """ self.id = id_ if id_ else unique_id("graph") self.name = name if name else self.id.replace("-", "_") self.nodes = OrderedDict() self.edges = OrderedDict()
def __init__(self, name=None, parent=None, id_=None): """Initializes Location. Args: name: The location name. parent: The parent automaton object. id_: The unique location ID ("loc-..."). """ super().__init__(name=name, parent=parent, id_=id_ if id_ else unique_id("loc"))
def new_template(self, name, id_=unique_id("tmpl")): """Creates a new template object and adds it to the system. Args: name: The location name. id_: An optionally custom template id. Returns: The new template object. """ tmpl = ta.Template(name, id_) self.add_template(tmpl) return tmpl
def __init__(self, source, target, parent=None, id_=None, weight=None): """Initializes WeightedEdge. Args: source: The source node object. target: The target node object. parent: The parent graph object. id_: The unique edge ID ("w-edge-..."). weight: The edge weight. """ id_ = id_ if id_ else unique_id("w-edge") super().__init__(source, target, parent, id_) self.weight = weight
def __init__(self, name=None, parent=None, id_=None): """Initializes Node. Args: name: The node name. parent: The parent graph object. id_: The unique node ID ("node-..."). """ self.id = id_ if id_ else unique_id("node") self.name = name if name else "" # id.replace("-", "_"); self.in_edges = OrderedDict() self.out_edges = OrderedDict() self.parent = parent self.view = {}
def __init__(self, source, target, parent=None, id_=None): """Initializes Edge. Args: source: The source node object. target: The target node object. parent: The parent graph object. id_: The unique edge ID ("edge-..."). """ if source is None: raise Exception(f'Edge source "{source}" not defined.') if target is None: raise Exception(f'Edge target "{target}" not defined.') self.id = id_ if id_ else unique_id("edge") self.parent = parent self.source = None self.target = None self.set_source_node(source) self.set_target_node(target) self.view = {}
def uppaal_xml_to_dict(system_xml_str): """Transforms the XML description of a Uppaal system into a data dictionary. Args: system_xml_str: The Uppaal system XML string. Returns: The data dictionary of Uppaal system data. """ system = OrderedDict() system_xml_str = system_xml_str.encode('utf-8') nta_element = etree.fromstring(system_xml_str) # Parse global declaration global_declaration_element = nta_element.find("declaration") if global_declaration_element is not None: system["global_declaration"] = global_declaration_element.text else: system["global_declaration"] = "" # Parse system declaration system_declaration_element = nta_element.find("system") if global_declaration_element is not None: system["system_declaration"] = system_declaration_element.text else: system["system_declaration"] = "" ################### # Parse templates # ################### system["templates"] = [] template_elements = nta_element.findall("template") for template_element in template_elements: template = OrderedDict() template["id"] = unique_id("tmpl") # Parse template name template_name_element = template_element.find("name") if template_name_element is not None: template["name"] = template_name_element.text else: template["name"] = "" # Parse template parameters template_parameters_element = template_element.find("parameter") if template_parameters_element is not None: template["parameters"] = template_parameters_element.text else: template["parameters"] = "" # Parse local template declaration template_declaration_element = template_element.find("declaration") if template_declaration_element is not None: template["declaration"] = template_declaration_element.text else: template["declaration"] = "" ################### # Parse locations # ################### template["locations"] = [] location_elements = template_element.findall("location") for location_element in location_elements: location = OrderedDict() location["id"] = location_element.attrib["id"] location["pos"] = { "x": int(location_element.attrib["x"]), "y": int(location_element.attrib["y"]) } # Parse location name location["name"] = None location["name_label"] = None location_name_element = location_element.find("name") if location_name_element is not None: label = OrderedDict() label["id"] = unique_id("label") label["pos"] = { "x": int(location_name_element.attrib["x"]), "y": int(location_name_element.attrib["y"]) } location["name"] = location_name_element.text location["name_label"] = label # Parse urgent / committed urgent_element = location_element.find("urgent") location["urgent"] = (urgent_element is not None) committed_element = location_element.find("committed") location["committed"] = (committed_element is not None) # Parse location labels location["invariant"] = None location["invariant_label"] = None label_elements = location_element.findall("label") for label_element in label_elements: label = OrderedDict() label["id"] = unique_id("label") label["pos"] = { "x": int(label_element.attrib["x"]), "y": int(label_element.attrib["y"]) } if label_element.attrib["kind"] == "invariant": location["invariant"] = label_element.text location["invariant_label"] = label template["locations"].append(location) # Parse initial location init_location_element = template_element.find("init") if init_location_element is not None: template["init_loc_id"] = init_location_element.attrib["ref"] ############### # Parse edges # ############### template["edges"] = [] # OrderedDict() edge_elements = template_element.findall("transition") for edge_element in edge_elements: edge = OrderedDict() edge["id"] = unique_id("edge") # Parse edge source location edge_source_element = edge_element.find("source") if edge_source_element is not None: edge["source_loc_id"] = edge_source_element.attrib["ref"] # Parse edge target location edge_target_element = edge_element.find("target") if edge_target_element is not None: edge["target_loc_id"] = edge_target_element.attrib["ref"] # Parse edge labels edge["guard"] = None edge["guard_label"] = None edge["update"] = None edge["update_label"] = None edge["synchronisation"] = None edge["sync_label"] = None edge["select"] = None edge["select_label"] = None label_elements = edge_element.findall("label") for label_element in label_elements: label = OrderedDict() label["id"] = unique_id("label") label["pos"] = { "x": int(label_element.attrib["x"]), "y": int(label_element.attrib["y"]) } if label_element.attrib["kind"] == "guard": edge["guard"] = label_element.text edge["guard_label"] = label elif label_element.attrib["kind"] == "assignment": edge["update"] = label_element.text edge["update_label"] = label elif label_element.attrib["kind"] == "synchronisation": edge["synchronisation"] = label_element.text edge["sync_label"] = label elif label_element.attrib["kind"] == "select": edge["select"] = label_element.text edge["select_label"] = label # Parse edge nails edge["nails"] = [] nail_elements = edge_element.findall("nail") for nail_element in nail_elements: nail = OrderedDict() nail["id"] = unique_id("nail") nail["pos"] = { "x": int(nail_element.attrib["x"]), "y": int(nail_element.attrib["y"]) } edge["nails"].append(nail) template["edges"].append(edge) system["templates"].append(template) ################# # Parse queries # ################# system["queries"] = [] root_query_element = nta_element.find("queries") if root_query_element is not None: query_elements = root_query_element.findall("query") for query_element in query_elements: query = OrderedDict() query["id"] = None formula_element = query_element.find("formula") if formula_element is not None: query["formula"] = formula_element.text.strip() comment_element = query_element.find("comment") if comment_element is not None: query["comment"] = comment_element.text.strip() system["queries"].append(query) # print(json.dumps(system, indent=2)) return system