示例#1
0
def raise_node_potentials(s, n, Edge, Cost, node_potential, Gr_Edge):
	color =[-1 for x in range(n)]
	parent =[-1 for x in range(n)]
	distance =[0 for x in range(n)]

	std_bfs (Gr_Edge,s,color,parent,distance)

	#Need to get visited nodes. Color changed to gray or black 
	visited=[]
	unvisited=[]
	for i in range(n):
		if color[i] == -1:
			unvisited.append(i)
		else:
			visited.append(i)

	min= 1000
	print color 
	print node_potential
	'''for a in range(len(visited)):
		for b in range(len(unvisited)):
			delta = Cost[a][b] - (node_potential[a]-node_potential[b]) #This qty is always >=0
			if delta < min :
				min = delta 
				to_be_raised = a

	node_potential[a] += 1'''



	for a in visited:
		for b in unvisited:
			if Edge[a][b] == 1:
				delta = Cost[a][b] - (node_potential[a]-node_potential[b])
				print delta 
				#print "Are we coming here? Yes, we are raising node potentials here"
				if delta< min:
					min = delta
					to_be_raised =a
				#	print "here"

	print "visited: ", visited
	print "unvisited: ", unvisited

	if min == 1000: 
		print "NOT POSSIBLE TO SATURATE ALL SOURCES "
		#return -1

	for a in visited:
		node_potential[a] += min 
	#node_potential[to_be_raised] += min
	
	print to_be_raised ," node's potential to be increased"
示例#2
0
def raise_node_potentials(s, n, Edge, Cost, node_potential, Gr_Edge):
	color =[-1 for x in range(n)]
	parent =[-1 for x in range(n)]
	distance =[0 for x in range(n)]

	std_bfs (Gr_Edge,s,color,parent,distance)

	#Need to get visited nodes. Color changed to gray or black 
	visited=[]
	unvisited=[]
	for i in range(n):
		if color[i] == -1:
			unvisited.append(i)
		else:
			visited.append(i)

	min= 1000
	print color 
	print node_potential

	print "visited: ", visited
	print "unvisited: ", unvisited

	for a in visited:
		for b in unvisited:
			if Edge[a][b] == 1:
				delta = Cost[a][b] - (node_potential[a]-node_potential[b])
				print "delta: ", delta 
				#print "Are we coming here? Yes, we are raising node potentials here"
				if delta< min:
					min = delta
					to_be_raised =a
				#	print "here"



	print "min of diff. of node pot. thing: ", min 
	for a in visited:
		node_potential[a] += min 
	#node_potential[to_be_raised] += min
	
	print to_be_raised ," node's potential to be increased"
示例#3
0
def raise_node_potentials(s, n, Edge, Cost, node_potential, Gr_Edge):
	color =[-1 for x in range(n)]
	parent =[-1 for x in range(n)]
	distance =[0 for x in range(n)]

	std_bfs (Gr_Edge,s,color,parent,distance)

	#Need to get visited nodes. Color changed to gray or black 
	visited=[]
	unvisited=[]
	for i in range(n):
		if color[i] == -1:
			unvisited.append(i)
		else:
			visited.append(i)

	min= 1000
	print color 
	print node_potential

	print "visited: ", visited
	print "unvisited: ", unvisited

	for a in visited:
		for b in unvisited:
			if Edge[a][b] == 1:
				delta = Cost[a][b] - (node_potential[a]-node_potential[b])
				print "delta: ", delta 
				#print "Are we coming here? Yes, we are raising node potentials here"
				if delta< min:
					min = delta
					to_be_raised =a
				#	print "here"



	print "min of diff. of node pot. thing: ", min 
	for a in visited:
		node_potential[a] += min 
	#node_potential[to_be_raised] += min
	
	print to_be_raised ," node's potential to be increased"