Skip to content

Commit

Permalink
Merge pull request #62 from signavio/stuckinloopfix
Browse files Browse the repository at this point in the history
Fixed such that the parser doesnt get stuck when models has loops
  • Loading branch information
a-rebmann authored Oct 21, 2024
2 parents 87d2408 + 440804a commit a02228c
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 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,36 @@ 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 a02228c

Please sign in to comment.