I am trying to produce the coverabilty graph for any petri net using a function i already have for the reachabilty but a keep getting the reachability graph no matter the input here is the function
def calculate_coverability_graph(num_places, num_transitions, markings_vector, incidence_matrix, weight_matrix, looped_weight_matrix):
markings_vector = markings_vector.astype(object)
def can_fire(markings_vector, incidence_matrix, weight_matrix):
fireable_transitions = []
for i in range(num_transitions):
def can_fire_transition(marking, transition=i):
for j in range(len(incidence_matrix)):
if incidence_matrix[j][transition] == -1:
if marking[j] != 'ω' and marking[j] < weight_matrix[j][transition]:
return False
return True
if can_fire_transition(markings_vector):
fireable_transitions.append(i)
return fireable_transitions
coverability_graph = nx.DiGraph()
markings_list = [tuple(markings_vector.flatten())]
coverability_graph.add_node(0)
queue = deque([(0, markings_vector)])
counter = 0
while queue:
if counter >= 100:
break
parent_index, parent_markings = queue.popleft()
for t in can_fire(parent_markings, incidence_matrix, weight_matrix):
new_markings = parent_markings.copy()
for j in range(len(incidence_matrix)):
if incidence_matrix[j][t] == -1:
if new_markings[j] != 'ω':
new_markings[j] -= weight_matrix[j][t]
elif incidence_matrix[j][t] == 1:
if new_markings[j] != 'ω':
new_markings[j] += weight_matrix[j][t]
# Update the new markings with looped_weight_matrix only for fired transitions
for j in range(len(incidence_matrix)):
if looped_weight_matrix[j][t] > 0 and new_markings[j] != 'ω':
new_markings[j] += looped_weight_matrix[j][t]
for i, (old, new) in enumerate(zip(parent_markings, new_markings)):
if not isinstance(old, str) and not isinstance(new, str) and new > old:
omega_reached = False
for ancestor in nx.ancestors(coverability_graph, parent_index):
ancestor_markings = markings_list[ancestor]
if ancestor_markings[i] == 'ω' or (not isinstance(ancestor_markings[i], str) and not isinstance(new, str) and new > ancestor_markings[i]):
omega_reached = True
break
if omega_reached:
new_markings[i] = 'ω'
try:
child_index = markings_list.index(tuple(new_markings.flatten()))
except ValueError:
child_index = len(markings_list)
markings_list.append(tuple(new_markings.flatten()))
coverability_graph.add_node(child_index)
queue.append((child_index, new_markings))
coverability_graph.add_edge(parent_index, child_index, transition=t)
counter += 1
return coverability_graph, markings_list
i think the issue is in denoting the omega value but i have no clue what it is or why its happening