Skip to content

Commit

Permalink
Fixed such that the parser doesnt get stuck when models has loops
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusSAP committed Oct 21, 2024
1 parent 87d2408 commit 1759051
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions bpmnconstraints/parser/bpmn_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def run(self):
self.__flatten_model()
else:
self.model = XmlModel(self.bpmn_model)

self.__parse()
self.__mark_gateway_elements()
if self.transitivity:
Expand Down Expand Up @@ -115,22 +116,34 @@ def __get_parsed_cfo_by_bpmn_element(self, elem):
if parsed_cfo.get("id") == elem_id:
return parsed_cfo

def __find_transitive_closure(self, cfo, transitivity):
def __find_transitive_closure(self, cfo, transitivity, visited):
# Check if the current node has already been visited to prevent a loop
if cfo.get("id") in visited:
print(f"Already visited {cfo.get('id')}, skipping to avoid a loop.")
return

# Mark the current node as visited
visited.add(cfo.get("id"))

if cfo:
for successor in cfo.get("successor"):
successor_id = successor.get("id")

successor = self.__get_cfo_by_id(successor_id)
if successor:
if "is in gateway" not in successor:
transitivity.append(successor)
for successor in cfo.get("successor"):
successor_cfo = self.__get_cfo_by_id(successor.get("id"))
self.__find_transitive_closure(successor_cfo, transitivity)
self.__find_transitive_closure(successor_cfo, transitivity, visited)

def __add_transitivity(self):
for cfo in self.sequence:
transitivity = []
self.__find_transitive_closure(cfo, transitivity)

visited = set() # Initialize the visited set for cycle detection
self.__find_transitive_closure(cfo, transitivity, visited)

if transitivity:
cfo.update({"transitivity": transitivity})

Expand Down

0 comments on commit 1759051

Please sign in to comment.