本文整理汇总了Python中networkx.DiGraph.edges_iter方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.edges_iter方法的具体用法?Python DiGraph.edges_iter怎么用?Python DiGraph.edges_iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.DiGraph
的用法示例。
在下文中一共展示了DiGraph.edges_iter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edges_iter
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import edges_iter [as 别名]
def edges_iter(self, nbunch=None):
for edge in DiGraph.edges_iter(self, nbunch, data=True):
yield edge
示例2: reverse_weights
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import edges_iter [as 别名]
def reverse_weights(g:nx.DiGraph, weight='weight'):
g = g.reverse()
for s, t in g.edges_iter():
e = g[s][t]
e[weight] = -e[weight]
return g
示例3: __init__
# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import edges_iter [as 别名]
#.........这里部分代码省略.........
from_class_body.remove(method)
to_class_body = self._inheritance_graph.node[to_class_name]['class'].body
to_class_body.append(method)
method_info['class_name'] = to_class_name
change_size = len(method.body)
# update references
for method_invocation in self.method_invocations(method_name):
method_invocation.target = Name(to_class_name)
change_size += 1
return change_size
def rename_method(self, method_name):
new_name = 'method%d' % self.counter
self.counter += 1
method_info = self._method_call_graph.node[method_name]
method_info['method'].name = new_name
change_size = 1
for inv in self.method_invocations(method_name):
inv.name = new_name
change_size += 1
relabel_nodes(self._method_call_graph, {method_name: new_name}, copy=False)
method_info['fitness'] = random()
return change_size, new_name
def create_variable_declaration(self):
"""
:return: the new variable declaration
"""
var = VariableDeclaration(
type='int',
variable_declarators=[VariableDeclarator(
variable=Variable(
name='var' + str(self.counter)
),
initializer=Literal(self.counter)
)]
)
self.counter += 1
return var
def save(self, output_dir, save_src):
with open(path.join(output_dir, 'commits.csv'), 'w', newline='') as commits_file:
writer = csv.DictWriter(commits_file, ['min_fitness', 'change_size'])
writer.writeheader()
writer.writerows(self._revisions)
with open(path.join(output_dir, 'methods.csv'), 'w', newline='') as methods_file:
writer = csv.DictWriter(methods_file, ['method', 'class', 'ref_count'])
writer.writeheader()
for method_name, in_degree in self._method_call_graph.in_degree_iter():
writer.writerow({
'method': method_name,
'class': self._method_call_graph.node[method_name]['class_name'],
'ref_count': in_degree
})
with open(path.join(output_dir, 'methods.json'), 'w') as methods_file:
data = json_graph.node_link_data(self._method_call_graph)
json.dump(data, methods_file, skipkeys=True, default=lambda d: None)
association_graph = Graph()
for e in self._method_call_graph.edges_iter():
association_graph.add_edge(
self._method_call_graph.node[e[0]]['class_name'],
self._method_call_graph.node[e[1]]['class_name'])
for e in self._inheritance_graph.edges_iter():
association_graph.add_edge(*e)
with open(path.join(output_dir, 'classes.csv'), 'w', newline='') as classes_file:
writer = csv.DictWriter(classes_file, ['class', 'subclasses', 'lines', 'degree'])
writer.writeheader()
for class_name, in_degree in self._inheritance_graph.in_degree_iter():
klass = self._inheritance_graph.node[class_name]['class']
java_printer = JavaPrinter()
klass.accept(java_printer)
writer.writerow({'class': class_name,
'subclasses': in_degree,
'lines': java_printer.result.count('\n') + 1,
'degree': association_graph.degree(class_name)
if class_name in association_graph else 0
})
if save_src:
with open(path.join(output_dir, 'src', class_name + '.java'), 'w') as java_file:
java_file.write(java_printer.result)
with open(path.join(output_dir, 'classes.json'), 'w') as classes_file:
data = json_graph.node_link_data(association_graph)
json.dump(data, classes_file, skipkeys=True)
def commit(self, change_size):
self._revisions.append({
'min_fitness': min(self._method_call_graph.node[method_name]['fitness']
for method_name in self._method_call_graph),
'change_size': change_size
})
@staticmethod
def is_invocation(stmt, method_name):
return isinstance(stmt, ExpressionStatement) and \
isinstance(stmt.expression, MethodInvocation) and \
stmt.expression.name == method_name