I am trying to calculate the reachability graph for any petrinet. the function where the calculation happens is not enabeling me to fire enabeled transitions and therefore the grapgh has only the initial node with initial markings i have no idea what wrong or what i can correct
def calculate_reachability_tree(num_places, num_transitions, markings_vector, incidence_matrix):
# Initialize the reachability tree and markings list
reachability_tree = nx.DiGraph()
markings_list = [tuple(markings_vector.flatten())]
reachability_tree.add_node(0)
# Initialize the queue with the initial markings
queue = deque([(0, markings_vector)])
while queue:
parent_index, parent_markings = queue.popleft()
print(parent_markings)
for t in range(num_transitions):
print(num_transitions)
# Check if the transition is enabled
if np.all(parent_markings + incidence_matrix[:, t] >= 0):
print('in if')
# Fire the transition
new_markings = parent_markings + incidence_matrix[:, t]
# Check if the new markings are already in the markings list
try:
child_index = markings_list.index(tuple(new_markings.flatten()))
except ValueError:
# Add the new markings to the markings list and reachability tree
child_index = len(markings_list)
new_markings_clipped = new_markings[:num_places]
markings_list.append(tuple(new_markings_clipped.flatten()))
reachability_tree.add_node(child_index)
queue.append((child_index, new_markings_clipped))
# Add an edge between the parent and child markings
reachability_tree.add_edge(parent_index, child_index, transition=t)
return reachability_tree, markings_list