Ejemplo n.º 1
0
Archivo: Graph.py Proyecto: zhued/intro
	def copyDeeply(self, g):
		# self assignment check, done in C++ a little differently
		if self.isEqual(g):
			return
		# clear out the existing Vertex and Edge data
		self.clear()
		# copy each Vertex and update the Edge array as we go
		# notice here we can use the vertexCount of the other
		# graph, g to count how many to copy
		for i in range(0, g.vertexCount):
			# make a new Vertex from g's Vertex
			v = Vertex(g.vertices[i].name)
			# add that Vertex to our Vertex list
			self.vertices.append(v)
			# update our vertexCount
			self.vertexCount += 1
			# add a new row to the edges array; this is self.edges[i], below
			self.edges.append([])
			# copy a row of Edges from g to here
			for j in range(0, g.vertexCount):
				# make a new Edge from g's edge
				e = Edge(g.edges[i][j].cost)
				# add the Edge to the end of the row
				self.edges[i].append(e)
				# count edges up if the Edge is not a zero edge
				if e.empty() == False:
					self.edgeCount += 1
		# create the 'bad Vertex' we send back when there's 
		# no good answer to getVertex()
		self.badVertex = Vertex('bad vertex')
		# set this Vertex to be bad
		self.badVertex.setBadness(True)
		# create the 'bad Edge' we send back when there's 
		# no good answer to getEdge()
		self.badEdge = Edge(0.0)
		# set this Edge to be bad
		self.badEdge.setBadness(True)