예제 #1
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def D_fronteir():

	global faulty_edge_list
	D_fronteir_li	=[]


	if(G[faulty_edge_list[0]][faulty_edge_list[1]]['value_non_fault']=='x'):	#Sensitize the fault
		print "faulty edge is added to D_fronteir_list"
		D_fronteir_li.append((faulty_edge_list[0],faulty_edge_list[1]))

	for i in G.nodes:
#		print i
		flag1 =False
		flag2 =False

		if(G.nodes[i]['type']=='gate'):
			#print "ioaefjpeiofljpowef'''''"
			gate_op_edge = list(G.out_edges(nbunch=i, data=False))
			gate_ip_edge = list(G.in_edges(nbunch=i, data=False))
			
			if(G.edges[gate_op_edge[0]]['value_non_fault']=='x' or G.edges[gate_op_edge[0]]['value_faulty']=='x'):		#Output is 'x'
				for j in gate_ip_edge:
					if(G.edges[j]['value_non_fault']=='1' and G.edges[j]['value_faulty'] =='0') or (G.edges[j]['value_non_fault']=='0' and G.edges[j]['value_faulty'] =='1'): #Input is D or D_bar check
						flag1=True	
						print " d or d_bar in nodes:",j
					if(G.edges[j]['value_non_fault']=='x' or G.edges[j]['value_faulty']=='x'):							#one of the Other Inputs is 'x'
						flag2= True
			
			if(flag1==True and flag2 ==True):
							print "D_fronteir in the_ ", j
							D_fronteir_li.insert(0,gate_op_edge[0])
							print "D_fronteir in the_appened case ", D_fronteir_li
			
	
	return D_fronteir_li
예제 #2
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def assign_undefined_ip(node_D_fronteir):
		#Assigning a non-controlling value to the gate
	print "-------------------------------------assign_undefined_ip------------------------------------------"
	print "node_D_fronteir",node_D_fronteir 
	global G
	print "NODES" , G.nodes(data=True)
	gate_type =G.nodes[node_D_fronteir]['gate_type']
	gate_ip_edge = list(G.in_edges(nbunch=node_D_fronteir, data=False))
	#new_D_fronteir_edge=list(list(G.out_edges(nbunch=node_D_fronteir, data=False))[0])
	if (gate_type =='not'):
		#print "gate_ip_edge",list(gate_ip_edge[0])
		return list(gate_ip_edge[0])
	else:
		if(gate_type=='and' or  gate_type=='nand'):
			control_val =0
		elif(gate_type=='or' or  gate_type=='nor'):
			control_val =1
		for i in range(len(gate_ip_edge)):
				if(G.edges[gate_ip_edge[i]]['value_non_fault']=='x' or G.edges[gate_ip_edge[i]]['value_faulty']=='x'):
					if (gate_type == 'xor' or gate_type == 'xnor') and (G.node[gate_ip_edge[i][0]]['cc0'] < G.edges[gate_ip_edge[i]][0]['cc1']):
       						control_val = 1
   					else:
       						control_val = 0
					return gate_ip_edge[i],str(int(not control_val))
	return 0
예제 #3
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def primary_output():
	POedge_list= []
	for item in G.nodes(data=True):
		if(item[1]['type']=='output'):
			list_outedge =list(G.in_edges(nbunch=item[0], data=False))	
			POedge_list.append(list_outedge[0])
	return POedge_list
예제 #4
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def Initialising() :
	global G 
	for node in G.nodes(data=True):
		if( node[1]['type']!= 'input' and node[1]['cc0'] == 1 and node[1]['cc1'] == 1):
			Controllability_init(node[0])
	print "********************************************initialised_controllability**************************"	
	for node in G.nodes(data=True):
		if (node[1]['type']!='check'):
			flag = 0
#			print "inside Observability", node
			for incoming_edge in G.in_edges(node[0]):
				if G.edges[incoming_edge]['CO'] == 'x':
					flag = 1
			if flag==1:
				Observability_init(node[0])
	print "********************************************Observability_Initialised**************************"	
예제 #5
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def Observability_init(node):
#	for outgoing in G.successors(node):
#		if  (G.[outgoing]['type']='output'):
#			return
	global G 
#	for edge in G.edges(data=True):
#		print edge[0],edge[1],edge[2]['CO']
	#print "###########################################################################################################"
	if G.node[node]['type'] == 'output' :
		for incoming_edge in G.in_edges(node):
		#		print "node = output ,so CO=0"
				G.edges[incoming_edge]['CO'] = 0;
	elif G.node[node]['type'] == 'input':
		for incoming_edge in G.in_edges(node):
			for outgoing_edge in G.out_edges(node):
				G.edges[incoming_edge]['CO']=G.edges[outgoing_edge]['CO']

	else:
		successorsC0_list=[]
		for outgoing_edge in G.out_edges(node):
			if (G.edges[outgoing_edge]['CO'] == 'x'):
		#	 	print "going in Observability_init(", outgoing_edge[1],")"
			 	Observability_init(outgoing_edge[1])			#out_egde will be list = [ (Start node,end node )]
		#	 	print "Finished in Observability_init(", outgoing_edge[1],")"
			
			successorsC0_list.append(G.edges[outgoing_edge]['CO'])

			 	

		if G.node[node]['type'] =='fanout':
			for stem in G.in_edges(node):
				G.edges[stem]['CO']= min(successorsC0_list)

		else:
			if G.node[node]['gate_type'] =='and' or G.node[node]['gate_type']=='nand':
				for incoming_edge in G.in_edges(node):
		#			predecessorCC0_list=[]
					predecessorCC1_list=[]
					for other_incoming_edge in G.in_edges(node):

						if other_incoming_edge!= incoming_edge :
		#					print other_incoming_edge,incoming_edge,"test"
		#					predecessorCC0_list.append(G.node[other_incoming_edge[0]]['cc0'])	 
							predecessorCC1_list.append(G.node[other_incoming_edge[0]]['cc1'])
		#			print node
		#			print successorsC0_list[0] 
		#			print sum(predecessorCC1_list) 	
					G.edges[incoming_edge]['CO']=successorsC0_list[0] + sum(predecessorCC1_list) +1	


			elif G.node[node]['gate_type'] =='or' or G.node[node]['gate_type']=='nor':
				
				for incoming_edge in G.in_edges(node):
					predecessorCC0_list=[]
		#			predecessorCC1_list=[]
					for other_incoming_edge in G.in_edges(node):
						if other_incoming_edge!= incoming_edge :
							predecessorCC0_list.append(G.node[other_incoming_edge[0]]['cc0'])	 
		#					predecessorCC1_list.append(G.node[other_incoming_edge[0]]['cc1'])

					G.edges[incoming_edge]['CO']=successorsC0_list[0] + sum(predecessorCC0_list) +1	

			elif G.node[node]['gate_type'] =='not': 
				for stem in G.in_edges(node):
					G.edges[stem]['CO']= successorsC0_list[0] + 1 
예제 #6
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def Forward_Implication(node1,node2):
	global G
	print "\n \n \n node1",node1,"node2",node2
	list_outedges =list(G.out_edges(nbunch=node2, data=False))				
	list_inedges =list(G.in_edges(nbunch=node2, data=False))
	print "faulty_edge_list[:2]",faulty_edge_list[:2]
			
	
	if(G.nodes[node2]['type']=='fanout'):

		print "faulty_edge_list[:2]",faulty_edge_list[:2]
		print "G[node1][node2]['value_faulty']",G[node1][node2]['value_faulty']
		for i in range(len(list_outedges)):
		
			G.edges[list_outedges[i]]['value_non_fault']  = G[node1][node2]['value_non_fault']
			if(faulty_edge_list[0]!=list_outedges[i][0] or faulty_edge_list[1]!=list_outedges[i][1]):
				G.edges[list_outedges[i]]['value_faulty']  = G[node1][node2]['value_faulty']
			
			next_node1		=list_outedges[i][0]
			next_node2		=list_outedges[i][1]
			print "new_node1 new_node2",next_node1,next_node2,G.edges[list_outedges[i]]['value_faulty'] 	
			if(G.nodes[next_node2]['type']=='gate' or G.nodes[next_node2]['type']=='fanout'):
				Forward_Implication(next_node1,next_node2)
			
			#next_node1	= node1
			#next_node2	= node2
	elif(G.nodes[node2]['type']=='gate'):
		list_input_non_faulty =[]
		list_input_faulty	  =[]
		print G.nodes[node2]['gate_type'],node2	
		for i in range(len(list_inedges)):
			list_input_non_faulty.append(G.edges[list_inedges[i]]['value_non_fault'])
			list_input_faulty.append(G.edges[list_inedges[i]]['value_faulty'])
		print "fault list",list_input_faulty 
		print "nonfault list",list_input_non_faulty
		
		if(G.nodes[node2]['gate_type']=='and'):
			output_non_faulty_value = gates_lib.AND_gate(list_input_non_faulty)
			output_faulty_value	  = gates_lib.AND_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='or'):
			output_non_faulty_value =	gates_lib.OR_gate(list_input_non_faulty)
			output_faulty_value	  =	gates_lib.OR_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='nand'):
			output_non_faulty_value =	gates_lib.NAND_gate(list_input_non_faulty)
			output_faulty_value	  = gates_lib.NAND_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='nor'):
			output_non_faulty_value =	gates_lib.NOR_gate(list_input_non_faulty)
			output_faulty_value      =gates_lib.NOR_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='xor'):
			output_non_faulty_value =	gates_lib.XOR_gate(list_input_non_faulty)
			output_faulty_value      =gates_lib.XOR_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='xnor'):
			output_non_faulty_value =	gates_lib.XNOR_gate(list_input_non_faulty)
			output_faulty_value      =gates_lib.XNOR_gate(list_input_faulty)
		elif(G.nodes[node2]['gate_type']=='not'):
			output_non_faulty_value =	gates_lib.NOT_gate(list_input_non_faulty[0])
			output_faulty_value	  = gates_lib.NOT_gate(list_input_faulty[0])
			#print "OUTPUT",output_non_faulty_value
		#Assign the value_non_fault to the output_non_faulty_value nodes
		print output_non_faulty_value,"non_faulty)output @",list_outedges[0]
		G.edges[list_outedges[0]]['value_non_fault'] = output_non_faulty_value 
				
		print "list_outedge",list_outedges[0] ,"and the faulty_edge_list=",faulty_edge_list	
		print "list_outedge[0][0]",list_outedges[0][0] ,"and the faulty_edge_list[0]=",faulty_edge_list[0]

		print "list_outedge[0][1]",list_outedges[0][1] ,"and the faulty_edge_list[1]=",faulty_edge_list[1]	
		print 

		if(faulty_edge_list[0] !=list_outedges[0][0] or faulty_edge_list[1] !=list_outedges[0][1]): 		#in case of the Gates, the output egdes will have only one element(tuple)
			G.edges[list_outedges[0]]['value_faulty'] = output_faulty_value 
			print output_faulty_value,"faulty_output @",list_outedges[0]
		
			
		next_node1 =list(G.out_edges(nbunch=node2, data=False))[0][0]
		next_node2 =list(G.out_edges(nbunch=node2, data=False))[0][1]
		#print "node1 node2",node1,node2
		if(G.nodes[node2]['type']!='output'):		#Check whether Fault Propagated to Primary output_non_faulty_value
			Forward_Implication(next_node1,next_node2)
예제 #7
0
파일: myPODEM_v2.py 프로젝트: cpr888/PODEM
def Backtrace(input_list, vs):
	global G
	print "input list in bactrace =",input_list,"vs",vs	
	flag=1
	setting=0
	v=vs
	v_f='x'
	# this flag is used in the future where we have ti decide which valaue to check
	if v=='0':
		flag='cc0'
	else:
		flag='cc1'
	updated_input_list=input_list
	s=input_list[0]
	if G.node[s]['type']=='fanout':
		for incoming in G.predecessors(s):
			s=incoming
			temp =(s,input_list[0])
			updated_input_list=temp
			print "updated input list after checking fanout",updated_input_list,vs		
	
	print "node type= " , G.node[s]['type']
	if G.node[s]['type']=='input':
		return updated_input_list,vs
	elif G.node[s]['type']!='input':
		if G.node[s]['gate_type']=='nand' or G.node[s]['gate_type']=='nor' or G.node[s]['gate_type']=='not':
			print "inside the value change"
			if v=='1':
				v='0'
			elif v=='0':
				v='1'
		setting=get_setting(s,v)
		max_ctrl_val=0
		min_ctrl_val=50
		print "input list in bactrace =",input_list,"vs",vs	
		if setting==1:			#all inpiuts are to be controlled
			print " seeting = 1"
			for in_edge in G.in_edges(s):
				if G.node[in_edge[0]][flag] >= max_ctrl_val and G.edges[in_edge]['value_non_fault']=='x':	#if you want to find the max CC0
					max_ctrl_val=G.node[in_edge[0]][flag]
					nxt_backtrack_edge = in_edge
					if G.node[nxt_backtrack_edge[0]]['type']=='fanout':
						for var in G.in_edges(nxt_backtrack_edge[0]):
							nxt_backtrack_edge=var
			if G.node[nxt_backtrack_edge[0]]['type'] == 'input' :
				return (nxt_backtrack_edge,v)	
			else:
				if (G.node[nxt_backtrack_edge[0]]['gate_type'] == 'nand' or G.node[nxt_backtrack_edge[0]]['gate_type'] == 'nor' or G.node[nxt_backtrack_edge[0]]['gate_type'] == 'not'):
					print "in here"
					pi,v_f=Backtrace(nxt_backtrack_edge,v)
		elif setting==0:
			print " seeting = 0"
			for in_edge in G.in_edges(s):
				if G.node[in_edge[0]][flag] <= min_ctrl_val and G.edges[in_edge]['value_non_fault']=='x':	#if you want to find the max CC0
					min_ctrl_val=G.node[in_edge[0]][flag]
					print "in_edge,ctrl",in_edge ,min_ctrl_val
					nxt_backtrack_edge = in_edge
					if G.node[nxt_backtrack_edge[0]]['type']=='fanout':
						for var in G.in_edges(nxt_backtrack_edge[0]):
							nxt_backtrack_edge=var
					print "in_edge,nxt_backtrack_edge,v",in_edge ,nxt_backtrack_edge,v
			if G.node[nxt_backtrack_edge[0]]['type'] == 'input' :
				print "gonna return this as its input node"
				return nxt_backtrack_edge,v
			else:
				if (G.node[nxt_backtrack_edge[0]]['gate_type'] == 'nand' or G.node[nxt_backtrack_edge[0]]['gate_type'] == 'nor' or G.node[nxt_backtrack_edge[0]]['gate_type'] == 'not'):
					print "in here to Backtrace"
					pi,v_f=Backtrace(nxt_backtrack_edge,v)
	
		return pi,v_f