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 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