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
def write_result(): global G global untestable_flag global faulty_edge_list output =str(faulty_edge_list) +"\n" print "faulty_edge_list",faulty_edge_list for item in G.edges(data=True): #print item if(G.nodes(data=True)[item[0]]['type'] =='input'):# or G.nodes(data=True)[item[1]]['type'] =='output'): print item[0],item[2]['value_non_fault'] ,item[2]['value_faulty'] # output +=str(item[0])+" " + str(item[1])+" " + str(item[2]['value_non_fault'])+" " +str(item[2]['value_faulty']) +"\n" output +=str(item[0])+" input value =" + str(item[2]['value_non_fault'])+"\n" if(G.nodes(data=True)[item[1]]['type'] =='output'): print item[0],item[2]['value_non_fault'] ,item[2]['value_faulty'] # output +=str(item[0])+" " + str(item[1])+" " + str(item[2]['value_non_fault'])+" " +str(item[2]['value_faulty']) +"\n" output +=str(item[0])+": non faulty output value =" + str(item[2]['value_non_fault'])+", faulty value=" +str(item[2]['value_faulty']) +"\n" if (untestable_flag==1): output += " Untestable/Redundant fault \n" else: output += "\n" f = open("PODEM_output.txt", 'a+') f.write(output) f.close()
def Controllability_init(node): global G # print node, "in controllability_node" for incoming in G.predecessors(node): if (G.node[incoming]['cc0'] == 1 and G.node[incoming]['cc1'] == 1 and G.node[incoming]['type'] != 'input'): Controllability_init(incoming) l0=[] l1=[] for predecessors in G.predecessors(node): l0.append(G.node[predecessors]['cc0']) l1.append(G.node[predecessors]['cc1']) #print G.node[node]['type'] if G.node[node]['type'] == 'check': return if G.node[node]['type'] == 'output' or G.node[node]['type'] == 'fanout' : # for predecessors in G.predecessors(node): G.node[node]['cc0'] = G.node[predecessors]['cc0'] G.node[node]['cc1'] = G.node[predecessors]['cc1'] elif G.node[node]['gate_type'] == 'and': G.node[node]['cc0'] = min(l0) + 1 G.node[node]['cc1'] = sum(l1) + 1 elif G.node[node]['gate_type'] == 'nand': G.node[node]['cc0'] = sum(l1) + 1 G.node[node]['cc1'] = min(l0) + 1 elif G.node[node]['gate_type'] == 'or': G.node[node]['cc0'] = sum(l0) + 1 G.node[node]['cc1'] = min(l1) + 1 elif G.node[node]['gate_type'] == 'nor': G.node[node]['cc0'] = min(l1) + 1 G.node[node]['cc1'] = sum(l0) + 1 elif G.node[node]['gate_type'] == 'not': G.node[node]['cc0'] = l1[0] + 1 G.node[node]['cc1'] = l0[0] + 1
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
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
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**************************"
def reset_graph(): global G global faulty_edge_list for item in G.edges(): G.edges[item]['fault']='' G.edges[item]['value_non_fault']='x' G.edges[item]['value_faulty']='x'
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
def main_PODEM(): global G global D_fronteir_list global PO_edge_list global implications_stack global count global untestable_flag pi=[] #count = count+1 count_limit=0 while (not (error_at_PO()) and count_limit<1000): count_limit=count_limit+1 print "while loop" print "---------------------------EDGES while entering the PODEM whileloop------------------------------------------------------------------" for edge in G.edges(data=True): #print edge print edge[0],edge[1],"not_faulty",edge[2]['value_non_fault'],"faulty",edge[2]['value_faulty'] D_fronteir_list= D_fronteir() print "count=",count ,"length of D_fronteir_list= ",len(D_fronteir_list) if len(D_fronteir_list)!=0: count = count+1 print "count=",count print "------------------------------------------------Objective round",count," --------------------------" node1,node2,vs=Objective() print "D_fronteir_list",D_fronteir_list print "length of D_fronteir_list= ",len(D_fronteir_list) print "----------------------------------------Objective round",count," DONE--------------------------" print "node1,node2,vs=",node1,node2,vs print "------------------------------------------------BACKTRACE round",count," --------------------------" pi,v=Backtrace((node1,node2),vs) print "------------------------------------------------Backtrace round",count," DONE--------------------------" print pi,v ,"Backtraced values" print "------------------------------------------------Value assignment round",count," --------------------------" assign_value_to_PI(pi,v); print "---------------------------EDGES after assignment------------------------------------------------------------------" for edge in G.edges(data=True): #print edge print edge[0],edge[1],"not_faulty",edge[2]['value_non_fault'],"faulty",edge[2]['value_faulty'] print "------------------------------------------------Forward_Implication round",count," --------------------------" Forward_Implication(pi[0],pi[1]) print "---------------------------EDGES after implication------------------------------------------------------------------" for edge in G.edges(data=True): #print edge print edge[0],edge[1],"not_faulty",edge[2]['value_non_fault'],"faulty",edge[2]['value_faulty'] if main_PODEM(): return True result = backtrack() # Backtrack can return new PI assignmnet or an empty list if not result: # implications list has been exhausted return False else: pi = result[:2] v = result[2] print "pi,v after backtrack =",pi,v print "------------------------------------------------Value assignment round",count," --------------------------" assign_value_to_PI(pi,v); print "------------------------------------------------Forward_Implication round",count," --------------------------" Forward_Implication(pi[0],pi[1]) if main_PODEM(): return True print "----------as the current pi=",pi,"assignment of either 0 or 1 is not helpful, we are backtracking again" v='x' assign_value_to_PI(pi,v); Forward_Implication(pi[0],pi[1]) return False elif not implications_stack: print "Redundant/untestable" untestable_flag=1 return False # else: # return False return True
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)
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
def faulty_edg(): for item in G.edges(data=True): if(item[2]['fault']=='sa1' ): return [item[0],item[1],'sa1','0'] elif(item[2]['fault']=='sa0'): return [item[0],item[1],'sa0','1']
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 print "\n\nEDGES:\n\n \n" for edge in G.edges(data=True): #print edge print edge[0],edge[1],"not_faulty",edge[2]['value_non_fault'],"faulty",edge[2]['value_faulty'] def error_at_PO(): global G global PO_edge_list print "check if D/D_bar is at output" for i in PO_edge_list: if(G.edges[i]['value_non_fault']!='x' and G.edges[i]['value_faulty']!='x' and G.edges[i]['value_non_fault']!=G.edges[i]['value_faulty'] ): print "D/D_bar is at output",i return True return False