From d8c3d46e33e3ab338187bf754e565c7af34311d8 Mon Sep 17 00:00:00 2001 From: iloveonsen Date: Fri, 12 Sep 2025 17:28:34 +0900 Subject: [PATCH] fix: fix issue causing alignments to be log-only --- ocpa/algo/conformance/alignments/algorithm.py | 8 +-- ocpa/objects/oc_petri_net/obj.py | 72 ++++++++++++------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/ocpa/algo/conformance/alignments/algorithm.py b/ocpa/algo/conformance/alignments/algorithm.py index 940f413..a11163f 100644 --- a/ocpa/algo/conformance/alignments/algorithm.py +++ b/ocpa/algo/conformance/alignments/algorithm.py @@ -314,8 +314,8 @@ def create_all_transitions(ocpn: ObjectCentricPetriNet, signature_in[in_arc.source.object_type] += 1 # add signature to transition - model_move = UndefinedModelMove(model_move=transition.name, objects=None, silent=transition.silent) - set_properties_of_transition(new_transition, TransitionSignature(transition.name, signature_in, + model_move = UndefinedModelMove(model_move=transition.label, objects=None, silent=transition.silent) + set_properties_of_transition(new_transition, TransitionSignature(transition.label, signature_in, signature_in, model_move)) # trans_prop = get_properties_of_transition(new_transition) # #print(f"Transitions property: {get_properties_of_transition(new_transition)}") @@ -381,8 +381,8 @@ def preprocessing_dejure_net(ocel: OCEL, indirect_id, ocpn): card_signature_in.setdefault(in_arc.source.object_type, 0) card_signature_in[in_arc.source.object_type] += 1 - model_move = UndefinedModelMove(model_move=transition.name, objects=None, silent=transition.silent) - set_properties_of_transition(transition, TransitionSignature(transition.name, card_signature_in, + model_move = UndefinedModelMove(model_move=transition.label, objects=None, silent=transition.silent) + set_properties_of_transition(transition, TransitionSignature(transition.label, card_signature_in, card_signature_in, model_move)) continue diff --git a/ocpa/objects/oc_petri_net/obj.py b/ocpa/objects/oc_petri_net/obj.py index 9317d8f..e4376b3 100644 --- a/ocpa/objects/oc_petri_net/obj.py +++ b/ocpa/objects/oc_petri_net/obj.py @@ -80,15 +80,27 @@ def __hash__(self): def __deepcopy__(self, memodict={}): if id(self) in memodict: return memodict[id(self)] - new_place = ObjectCentricPetriNet.Place( - self.name, self.object_type) + + name = getattr(self, "name", None) + object_type = getattr(self, "object_type", None) + initial = getattr(self, "initial", False) + final = getattr(self, "final", False) + + # copy initial and final flags as well + new_place = self.__class__(name, object_type, initial=initial, final=final) + # copy properties if they exist + if hasattr(self, 'properties'): + try: + setattr(new_place, 'properties', deepcopy(getattr(self, 'properties'), memo=memodict)) + except Exception: + setattr(new_place, 'properties', getattr(self, 'properties')) memodict[id(self)] = new_place - for arc in self.in_arcs: - new_arc = deepcopy(arc, memo=memodict) - new_place.in_arcs.add(new_arc) - for arc in self.out_arcs: - new_arc = deepcopy(arc, memo=memodict) - new_place.out_arcs.add(new_arc) + + # Init in_arcs and out_arcs if they do not exist + # No longer attach arcs during deepcopy of place, + # do it when deepcopying the arcs instead to remove duplicated arcs + if not hasattr(new_place, "in_arcs"): new_place.in_arcs = set() + if not hasattr(new_place, "out_arcs"): new_place.out_arcs = set() return new_place object_type = property(__get_object_type) @@ -186,15 +198,20 @@ def __hash__(self): def __deepcopy__(self, memodict={}): if id(self) in memodict: return memodict[id(self)] - new_trans = ObjectCentricPetriNet.Transition( - self.name, self.label, properties=self.properties) + + name = getattr(self, "name", None) + label = getattr(self, "label", None) + properties = getattr(self, "properties", None) + silent = getattr(self, "silent", False) + + # copy silent flag as well + new_trans = self.__class__(name, label, properties=properties, silent=silent) memodict[id(self)] = new_trans - for arc in self.in_arcs: - new_arc = deepcopy(arc, memo=memodict) - new_trans.in_arcs.add(new_arc) - for arc in self.out_arcs: - new_arc = deepcopy(arc, memo=memodict) - new_trans.out_arcs.add(new_arc) + + # No longer attach arcs during deepcopy of transition, + # do it when deepcopying the arcs instead to remove duplicated arcs + if not hasattr(new_trans, "in_arcs"): new_trans.in_arcs = set() + if not hasattr(new_trans, "out_arcs"): new_trans.out_arcs = set() return new_trans def to_dict(self): @@ -272,15 +289,22 @@ def __eq__(self, other): def __deepcopy__(self, memodict={}): if id(self) in memodict: return memodict[id(self)] - new_source = memodict[id(self.source)] if id(self.source) in memodict else deepcopy(self.source, - memo=memodict) - new_target = memodict[id(self.target)] if id(self.target) in memodict else deepcopy(self.target, - memo=memodict) - memodict[id(self.source)] = new_source - memodict[id(self.target)] = new_target - new_arc = ObjectCentricPetriNet.Arc( - new_source, new_target, weight=self.weight, properties=self.properties) + + new_source = deepcopy(getattr(self, "source", None), memo=memodict) + new_target = deepcopy(getattr(self, "target", None), memo=memodict) + + weight = getattr(self, "weight", 1) + variable = getattr(self, "variable", False) + properties = getattr(self, "properties", None) + + new_arc = self.__class__(new_source, new_target, weight=weight, variable=variable, properties=properties) memodict[id(self)] = new_arc + + # Attach the new arc to the new source and target + if hasattr(new_source, "out_arcs"): + new_source.out_arcs.add(new_arc) + if hasattr(new_target, "in_arcs"): + new_target.in_arcs.add(new_arc) return new_arc def to_dict(self):