本文整理汇总了Python中networkx.DiGraph.degree方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.degree方法的具体用法?Python DiGraph.degree怎么用?Python DiGraph.degree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.degree方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import degree [as 别名]
class DepF :
def __init__(self, field) :
self.__offsets = []
self.__field = field
############ create depency field graph #########
# Initial values to build the graph (depth, width, cycles)
self.__depth = 3
self.__width = 3
self.__cycles = 2
self.__G = DiGraph()
G = self.__G
G.add_node( self._new_node(G) )
# Create randomlu the graph without cycle
self.__random( G, 0 )
# Find the best path to add cycles
d = all_pairs_dijkstra_path_length( G )
l = list( reversed( sorted( d, key=lambda key: len(d[key]) ) ) )
for i in l :
if self.__cycles == 0 :
break
d_tmp = sorted( d[i], key=lambda key: d[i][key] )
G.add_edge( d_tmp[-1], i)
self.__cycles = self.__cycles - 1
print simple_cycles( G )
print G.node
print G.edge
print G.degree()
############ Add field <-> higher #####################################
# field F depends of the higher degree
# F <---> sorted( G.degree(), key=lambda key : G.degree()[key] )[-1]
#######################################################################
degree = G.degree()
high_degree = sorted( degree, key=lambda key : degree[key] )[-1]
# Link our protected field with the node which has the highest degree
G.add_edge( field.get_name(), high_degree )
G.add_edge( high_degree, field.get_name() )
#draw_graphviz(G)
#write_dot(G,'file.dot')
def get_field(self) :
return self.__field
def add_offset(self, idx) :
x = Offset( idx )
self.__offsets.append( x )
return x
def run(self, _vm, _analysis, _vm_generate) :
###############################################################
## dict (method) of list ( offset / list (of instructions) ) #
## - insert an element #
## - modify the offset with the new insertion #
###############################################################
list_OB = {}
############ Create dependencies fields ############
fields = { self.__field.get_name() : Field( _vm, _analysis, _vm_generate, self.__field, self, True ) }
fields[ self.__field.get_name() ].run( self.__G.degree()[ self.__field.get_name() ] )
print self.__field.get_name(), ": REAL_FIELD ->", self.__G.predecessors( self.__field.get_name() ), self.__G.degree()[self.__field.get_name()]
############ Create the name, the initial value and all access of the field ############
for i in self.__G.node :
# We have not yet add this new field
if i not in fields :
print i, "PRE ->", self.__G.predecessors( i ), self.__G.degree()[i]
name, access_flag, descriptor = _analysis.get_like_field()
_vm.insert_field( self.__field.get_class_name(), name, [ access_flag, descriptor ] )
fields[ i ] = Field( _vm, _analysis, _vm_generate, _vm.get_field_descriptor( self.__field.get_class_name(), name, descriptor ), self )
# degree of the field, prefix must be add if the protection is for a real field
fields[ i ].run( self.__G.degree()[i] )
########## Add all fields initialisation into the final list ############
for i in fields :
print "FIELD ->", i,
fields[ i ].show()
x = fields[ i ].insert_init()
if x != None :
try :
list_OB[ x[0] ].append( (x[1], x[2]) )
except KeyError :
list_OB[ x[0] ] = []
list_OB[ x[0] ].append( (x[1], x[2]) )
#.........这里部分代码省略.........
示例2: _construct
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import degree [as 别名]
#.........这里部分代码省略.........
dfg = DiGraph()
for stmt_idx, stmt in enumerate(statements):
# We want to skip over certain types, such as Imarks
if self._need_to_ignore(node.addr, stmt, stmt_idx):
continue
# break statement down into sub-expressions
exprs = stmt.expressions
stmt_node = stmt
dfg.add_node(stmt)
if stmt.tag == 'Ist_WrTmp':
tmpsnodes[stmt.tmp] = stmt_node
if exprs[0].tag == 'Iex_Binop':
if exprs[1].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[1].tmp], stmt_node)
else:
dfg.add_edge(exprs[1], stmt_node)
if exprs[2].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[2].tmp], stmt_node)
else:
dfg.add_edge(exprs[2], stmt_node)
elif exprs[0].tag == 'Iex_Unop':
dfg.remove_node(stmt_node)
if exprs[1].tag == 'Iex_RdTmp':
tmpsnodes[stmt.tmp] = copy(tmpsnodes[exprs[1].tmp])
tmpsnodes[stmt.tmp].tmp = stmt.tmp
else:
tmpsnodes[stmt.tmp] = exprs[1]
elif exprs[0].tag == 'Iex_RdTmp':
tmpsnodes[stmt.tmp] = copy(tmpsnodes[exprs[0].tmp])
tmpsnodes[stmt.tmp].tmp = stmt.tmp
elif exprs[0].tag == 'Iex_Get':
if putsnodes.has_key(exprs[0].offset):
dfg.add_edge(putsnodes[exprs[0].offset], stmt_node)
if len(exprs) > 1 and exprs[1].tag == "Iex_RdTmp":
dfg.add_edge(tmpsnodes[exprs[1].tmp], stmt_node)
elif len(exprs) > 1:
dfg.add_edge(exprs[1], stmt_node)
elif exprs[0].tag == 'Iex_Load':
if exprs[1].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[1].tmp], stmt_node)
else:
dfg.add_edge(exprs[1], stmt_node)
else:
# Take a guess by assuming exprs[0] is the op and any other expressions are args
for e in exprs[1:]:
if e.tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[e.tmp], stmt_node)
else:
dfg.add_edge(e, stmt_node)
elif stmt.tag == 'Ist_Store':
if exprs[0].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[0].tmp], stmt_node)
elif exprs[0].tag == 'Iex_Const':
dfg.add_edge(exprs[0], stmt_node)
if exprs[1].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[1].tmp], stmt_node)
else:
dfg.add_edge(exprs[1], stmt_node)
elif stmt.tag == 'Ist_Put':
if exprs[0].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[0].tmp], stmt_node)
elif exprs[0].tag == 'Iex_Const':
dfg.add_edge(exprs[0], stmt_node)
putsnodes[stmt.offset] = stmt_node
elif stmt.tag == 'Ist_Exit':
if exprs[0].tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[exprs[0].tmp], stmt_node)
elif stmt.tag == 'Ist_Dirty':
tmpsnodes[stmt.tmp] = stmt_node
elif stmt.tag == 'Ist_CAS':
tmpsnodes[stmt.oldLo] = stmt_node
else:
for e in stmt.expressions:
if e.tag == 'Iex_RdTmp':
dfg.add_edge(tmpsnodes[e.tmp], stmt_node)
else:
dfg.add_edge(e, stmt_node)
for vtx in dfg.nodes():
if dfg.degree(vtx) == 0:
dfg.remove_node(vtx)
if dfg.size() > 0:
dfgs[node.addr] = dfg
return dfgs