Change regex for detecting edges of graph

This commit is contained in:
Eryk Miszczuk 2019-12-08 10:33:19 +01:00
parent 0dac5776a8
commit e8bee03228
2 changed files with 7 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import re import re
import sys import sys
atandt_desc_pattern = re.compile(r"^([0-9]+) ([0-9]+) (\S+)( [0-9]+\.[0-9]+)?$") atandt_desc_pattern = re.compile(r"^([0-9]+)[ \t]([0-9]+)[ \t](\S+)([ \t][0-9]+(\.[0-9]+)?)?$") #^([0-9]+)[ \t]([0-9]+)[ \t](\S+)([ \t][0-9]+(\.[0-9]+)?)?$
atandt_accepted_state_pattern = re.compile(r"^[0-9]+$") atandt_accepted_state_pattern = re.compile(r"^[0-9]+$")
current_state = 0 current_state = 0

View File

@ -3,7 +3,7 @@
import re import re
import sys import sys
# Regex pattern for reading atandt format
atandt_desc_pattern = re.compile(r"^([0-9]+)\t([0-9]+)\t(\S+)$") #^([0-9]+)\t([0-9]+)\t(\S+)$ regex for tab separated columns atandt_desc_pattern = re.compile(r"^([0-9]+)\t([0-9]+)\t(\S+)$") #^([0-9]+)\t([0-9]+)\t(\S+)$ regex for tab separated columns
atandt_accepted_state_pattern = re.compile(r"^[0-9]+$") atandt_accepted_state_pattern = re.compile(r"^[0-9]+$")
@ -25,14 +25,14 @@ def dfs(graph, start):
stack.add(el) stack.add(el)
while stack: while stack:
edge = stack.pop() edge = stack.pop()
print('Current edge: {edge}'.format(edge = edge)) #print('Current edge: {edge}'.format(edge = edge))
if edge not in visited: if edge not in visited:
visited.add(edge) visited.add(edge)
children = set() children = set()
for val in filter_set(state_move, edge[2]): for val in filter_set(state_move, edge[2]):
stack.add(val) stack.add(val)
print('Stack: {stack}'.format(stack = stack)) #print('Stack: {stack}'.format(stack = stack))
print('Visited: {visited}'.format(visited = visited)) #print('Visited: {visited}'.format(visited = visited))
else: else:
return [-1] return [-1]
return visited return visited
@ -52,6 +52,6 @@ print('Accept states: {accept_states}'.format(accept_states = accept_states))
vis = dfs(state_move, 0) vis = dfs(state_move, 0)
if -1 in vis: if -1 in vis:
print("Cycle") print("TAK")
else: else:
print("Tree") print("NIE")