Subversion Repositories programming

Rev

Rev 388 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 388 Rev 391
Line 45... Line 45...
45
				return n
45
				return n
46
 
46
 
47
		# This should never happen
47
		# This should never happen
48
		raise ValueError
48
		raise ValueError
49
 
49
 
50
	def search (self, add_function, MAX_ITERATIONS=100):
50
	def search (self, add_function, MAX_NODES_CREATED=100):
51
 
51
 
52
		# Create the result graph
52
		# Create the result graph
53
		result = Graph ()
53
		result = Graph ()
54
		firsttime = True
54
		firsttime = True
55
		counter = 0
55
		counter = 0
Line 74... Line 74...
74
				result.add_edge (v1, v2)
74
				result.add_edge (v1, v2)
75
				result.set_edge_color (v1, v2, yapgvb.colors.red)
75
				result.set_edge_color (v1, v2, yapgvb.colors.red)
76
				result.set_edge_label (v1, v2, str(counter))
76
				result.set_edge_label (v1, v2, str(counter))
77
 
77
 
78
			else:
78
			else:
-
 
79
				# Set start node shape to be a double circle
-
 
80
				result.set_vertex_shape (str(N), yapgvb.shapes.doublecircle)
79
				firsttime = False
81
				firsttime = False
80
			###############################################################
82
			###############################################################
81
 
83
 
82
			# Check if we've reached the goal
84
			# Check if we've reached the goal
83
			if N in self.__goal_nodes:
85
			if N in self.__goal_nodes:
-
 
86
				# Set the goal node's shape to be a diamond
-
 
87
				result.set_vertex_shape (str(N), yapgvb.shapes.diamond)
84
				return result
88
				return result
85
 
89
 
86
			# Add the children of N (aka M) to OPEN
90
			# Add the children of N (aka M) to OPEN
87
			OPEN = add_function (M, OPEN, CLOSED)
91
			OPEN = add_function (M, OPEN, CLOSED)
88
 
92
 
89
			counter += 1
93
			counter += 1
90
 
94
 
91
			# Check to make sure we don't loop for too long
95
			# Check to make sure we don't loop for too long
92
			if counter > MAX_ITERATIONS:
96
			if (len(OPEN) + len(CLOSED)) > MAX_NODES_CREATED:
93
				return 'FAILURE'
97
				return 'FAILURE'
94
 
98
 
95
		return 'FAILURE'
99
		return 'FAILURE'
96
 
100
 
97
def add_bfs (M, OPEN, CLOSED):
101
def add_bfs (M, OPEN, CLOSED):