当前位置: 首页>>代码示例>>Python>>正文


Python DiGraph.in_degree_iter方法代码示例

本文整理汇总了Python中networkx.DiGraph.in_degree_iter方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.in_degree_iter方法的具体用法?Python DiGraph.in_degree_iter怎么用?Python DiGraph.in_degree_iter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx.DiGraph的用法示例。


在下文中一共展示了DiGraph.in_degree_iter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filter_non_dependencies

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import in_degree_iter [as 别名]
def filter_non_dependencies(nodes, get_deps_func):
    node_set = set(nodes)
    G = DiGraph()
    G.add_nodes_from(nodes)

    # process the edges based on the dependency function
    for n in G:
        deps = get_deps_func(n)
        logging.info('%s depends on %s' % (n, deps))
        for d in deps:
            if d in G:
                G.add_edge(n, d)



    # now filter the nodes and return them
    filtered_pkgs = {node for node, in_degree in G.in_degree_iter() if in_degree == 0}

    # now find any strongly connected components with size greater than 1
    # these will all have in degree > 0, but should still be included
    glist = [g for g in strongly_connected_component_subgraphs(G, copy=False) if g.number_of_nodes() > 1]

    for g in glist:
        # only counts if it was the original list
        nodes = [n for n in g.nodes() if n in node_set]
        if len(nodes) > 0:
            logging.debug('Strongly connected component: %s' % repr(nodes))
            for n in nodes:
                filtered_pkgs.add(n)

    return filtered_pkgs
开发者ID:ecbtln,项目名称:vm2docker,代码行数:33,代码来源:dependencygraph.py

示例2: __init__

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import in_degree_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
开发者ID:linzhp,项目名称:Codevo3,代码行数:104,代码来源:codebase.py


注:本文中的networkx.DiGraph.in_degree_iter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。