def averageNodeData():
	sizeOfCover = range(0,200)
	averageRemovedEdges = range(0,200)

	G = nx.erdos_renyi_graph(100,0.05)		
	temp_data = range(0,200)
	for j in range(0,200):
		process = Popen(["../build/programming3", utils.dmax(G),"r"], stdout=PIPE)	
		(output, err) = process.communicate()
		print(output)
		exit_code = process.wait()
		data = re.findall(r"[-+]?\d*\.\d+|\d+",output)	
		data = [float(s) for s in data]	
		print(data)
		sizeOfCover[j] = data[0]
		averageRemovedEdges[j] = data[1]
	plt.plot(averageRemovedEdges, sizeOfCover, 'ro')
	plt.ylabel('Size Vertex Cover')
	plt.xlabel('Average #Edge Deletions per Iteration')
	plt.savefig('average_node_deletions.png', dpi=100)
def histogram():
	
	for i in range(1,10):
		G=nx.erdos_renyi_graph(100,0.01*i)
		temp_data = range(0,500)
		for j in range(0,500):
				process = Popen(["../build/programming3", utils.dmax(G),"r"], stdout=PIPE)	
				(output, err) = process.communicate()
				exit_code = process.wait()
				data = re.findall(r"[-+]?\d*\.\d+|\d+",output)	
				data = [float(s) for s in data]
				temp_data[j]=data[0]
		plt.clf()
		pl.clf()		
		(n,bins,patches)=pl.hist(temp_data,5,normed=1,histtype='bar',color='Burlywood',label='Histogram '+str(0.2*i))
		y = plt.mlab.normpdf(bins,np.mean(temp_data),np.std(temp_data))
		pl.plot(bins,y,'k--',linewidth=1.5,label='Fitted Gaussian')
		plt.legend()
		plt.xlabel('Size Vertex Cover')
		plt.ylabel('Probability')
		plt.savefig('histogram' + str(0.2*i) + '.png', dpi=100)
def generate_data():
	apxg_vc		= range(0,10)
	apxi_vc		= range(0,10)
	apxir_vc	= range(0,10)
	apxr_vc		= range(0,10)
	apxr_vc_mean 	= range(0,10)
	apxr_vc_errorl 	= range(0,10)
	apxr_vc_errorh 	= range(0,10)
	xaxis = range(0,10)
	ind = range(0,10)
	for i in range(0,10):
		print(str(i+1)+" ")
		#G=nx.erdos_renyi_graph(200,0.01*(i+1))
		#xaxis[i] = 0.01*(i+1)
		G = nx.random_regular_graph((i+1)*10, 101)
		xaxis[i] = (i+1)*10
		#G = nx.powerlaw_cluster_graph(50, i+2, 0.0)		
		temp_data = range(0,100)
		for j in range(0,100):
			process = Popen(["../build/programming3", utils.dmax(G),"r"], stdout=PIPE)	
			(output, err) = process.communicate()
			exit_code = process.wait()
			data = re.findall(r"[-+]?\d*\.\d+|\d+",output)	
			data = [float(s) for s in data]
			temp_data[j]=data[0]	
		#Random
		apxr_vc_mean[i]  	= np.mean(temp_data)
		apxr_vc_errorl[i] 	= np.min(temp_data)-np.mean(temp_data) 
		apxr_vc_errorh[i] 	= np.mean(temp_data)-np.max(temp_data)
		apxr_vc[i] 		= temp_data

		#Greedy		
		process = Popen(["../build/programming3", utils.dmax(G),"g"], stdout=PIPE)	
		(output, err) = process.communicate()
		exit_code = process.wait()
		apxg_vc[i] = int(output)

		#Greedy Improved
		process = Popen(["../build/programming3", utils.dmax(G),"i"], stdout=PIPE)	
		(output, err) = process.communicate()
		exit_code = process.wait()
		apxi_vc[i] = int(output)

		#Greedy Improved Reversed
		process = Popen(["../build/programming3", utils.dmax(G),"!"], stdout=PIPE)	
		(output, err) = process.communicate()
		exit_code = process.wait()
		apxir_vc[i] = int(output)

	plt.errorbar(ind,apxr_vc_mean,[apxr_vc_errorl,apxr_vc_errorh],fmt='-bo')
	plt.ylabel('Size Vertex Cover')
	plt.xlabel('% Graph Connectivity')
	#Random and Greedy
	b1 = plt.plot(xaxis,apxr_vc_mean,'-kx',label='Random Heuristic')
	plt.boxplot(apxr_vc, sym='k+', positions=xaxis,notch=1)
	b3 = plt.plot(xaxis,apxg_vc,'-.ro',label='Greedy Heuristic')
	plt.legend(loc='lower right')
	plt.savefig('RandomGreedy.png', dpi=100)
	#With pruning
	b4 = plt.plot(xaxis,apxi_vc,'-g^',label='Greedy Heuristic & Min Greedy Cover Pruning')
	b5 = plt.plot(xaxis,apxir_vc,'--bs',label='Greedy Heuristic & Max Greedy Cover Pruning')
	plt.legend(loc='lower right')
	plt.savefig('Pruning.png', dpi=100)