Subversion Repositories programming

Rev

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

Rev 395 Rev 396
Line 66... Line 66...
66
		start_node: the node to start at (must have a get_children() function)
66
		start_node: the node to start at (must have a get_children() function)
67
		goal_nodes: a list of nodes to end at"""
67
		goal_nodes: a list of nodes to end at"""
68
 
68
 
69
		self.__start_node = start_node
69
		self.__start_node = start_node
70
		self.__goal_nodes = goal_nodes
70
		self.__goal_nodes = goal_nodes
71
		self.__ordering_func = list.sort
-
 
72
 
-
 
73
	def set_ordering_func (self, func):
-
 
74
		"""Set the ordering function to use."""
-
 
75
		self.__ordering_func = func
-
 
76
 
71
 
77
	def __find_nearest_child (self, children, already_visited):
72
	def __find_nearest_child (self, children, already_visited):
78
		"""Find the child that we came from. This necessitates that
73
		"""Find the child that we came from. This necessitates that
79
		the list already_visited be sorted in the order of nodes visited"""
74
		the list already_visited be sorted in the order of nodes visited"""
-
 
75
 
-
 
76
		# This is the stupidest hack ever (gotta hate they school computers!)
-
 
77
		rev = already_visited[:]
-
 
78
		rev.reverse()
-
 
79
 
80
		for n in reversed(already_visited):
80
		for n in rev: #reversed(already_visited):
81
			if n in children:
81
			if n in children:
82
				return n
82
				return n
83
 
83
 
84
		# This should never happen
84
		# This should never happen
85
		raise ValueError
85
		raise ValueError
Line 108... Line 108...
108
			if not firsttime:
108
			if not firsttime:
109
				v1 = str(N)
109
				v1 = str(N)
110
				v2 = str(self.__find_nearest_child (M, CLOSED))
110
				v2 = str(self.__find_nearest_child (M, CLOSED))
111
 
111
 
112
				result.add_edge (v1, v2)
112
				result.add_edge (v1, v2)
113
				result.set_edge_color (v1, v2, yapgvb.colors.red)
113
				result.set_edge_color (v1, v2, 'red')
114
				result.set_edge_label (v1, v2, str(counter))
114
				result.set_edge_label (v1, v2, str(counter))
115
 
115
 
116
			else:
116
			else:
117
				# Set start node shape to be a double circle
117
				# Set start node shape to be a double circle
118
				result.set_vertex_shape (str(N), yapgvb.shapes.doublecircle)
118
				result.set_vertex_shape (str(N), 'doublecircle')
119
				firsttime = False
119
				firsttime = False
120
			###############################################################
120
			###############################################################
121
 
121
 
122
			# Check if we've reached the goal
122
			# Check if we've reached the goal
123
			if N in self.__goal_nodes:
123
			if N in self.__goal_nodes:
124
				# Set the goal node's shape to be a diamond
124
				# Set the goal node's shape to be a diamond
125
				result.set_vertex_shape (str(N), yapgvb.shapes.diamond)
125
				result.set_vertex_shape (str(N), 'diamond')
126
 
126
 
127
				# Create the return result
127
				# Create the return result
128
				search_result = SearchResult (completed=True,
128
				search_result = SearchResult (completed=True,
129
							status='Success',
129
							status='Success',
130
							depth_reached=N.depth,
130
							depth_reached=N.depth,