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


Python Graph.es['weight']方法代码示例

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


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

示例1: _gen_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es['weight'] [as 别名]
 def _gen_graph(self):
     # make it lazy to support optional addslaves command
     from igraph import Graph
     g = Graph().as_directed()
     g.add_vertices(self.vertex_count)
     g.es['weight'] = 1  # enable weight
     return g
开发者ID:eleme,项目名称:ruskit,代码行数:9,代码来源:distribute.py

示例2: gen_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es['weight'] [as 别名]
def gen_graph():
    masters = sum(ms, [])
    slaves = sum(ss, [])
    frees = sum(fs, [])
    ct = machine_count
    g = Graph().as_directed()
    g.add_vertices(2 * ct + 2)
    g.es['weight'] = 1
    assert g.is_weighted()
    lin = map(len, fs)
    # lin = map(operator.add, map(len, ss), map(len, fs))
    rout = map(len, ms)
    s = 2 * ct
    t = s + 1
    for i, m in enumerate(lin):
        g[s, i] = m
    for i, m in enumerate(rout):
        g[i + ct, t] = m

    cap = defaultdict(dict)
    for i, m in enumerate(lin):
        for j, n in enumerate(rout):
            if i == j:
                continue
            cap[i][j] = m
    assert len(ss) == ct
    # for i in range(ct):
    #     for slave in ss[i]:
    #         cap[i][slave.master.machine_tag] -= 1
    #         assert cap[i][slave.master.machine_tag] >= 0
    print cap
    for i in range(ct):
        for j in range(ct):
            if i == j:
                continue
            masters_in_j = set(slave.master.tag for slave in ss[i] if slave.master.machine_tag == j)  # to fight existing distribution error
            limit = len(ms[j]) - len(masters_in_j)
            cap[i][j] = min(limit, map(len, fs)[i])

    for i, m in enumerate(lin):
        if m == 0:
            continue
        for j, n in enumerate(rout):
            if i == j:
                continue
            g[i, ct + j] = cap[i][j]

    print g
    start = datetime.utcnow()
    mf = g.maxflow(s, t, g.es['weight'])
    end = datetime.utcnow()
    print 'result:', end - start
    print mf.value, sum(rout)
    print mf.flow
    print map(float, g.es['weight']), len(g.es['weight'])
开发者ID:doyoubi,项目名称:ClusterDist,代码行数:57,代码来源:solve.py

示例3: _gen_graph

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es['weight'] [as 别名]
 def _gen_graph(self):
     g = Graph().as_directed()
     g.add_vertices(self.vertex_count)
     g.es['weight'] = 1  # enable weight
     assert g.is_weighted()
     return g
开发者ID:doyoubi,项目名称:ClusterDist,代码行数:8,代码来源:solve.py

示例4: contributor_network

# 需要导入模块: from igraph import Graph [as 别名]
# 或者: from igraph.Graph import es['weight'] [as 别名]

#.........这里部分代码省略.........

            # journal editors are at the issue level
            for issue in j.issue_set.all():
                editors = issue.editors.all()
                for i, editor in enumerate(editors):
                    # only add if not already present
                    if editor.network_id not in graph.vs['name']:
                        graph.add_vertex(editor.network_id,
                                         type=editor.network_type,
                                         label=editor.firstname_lastname)
                    add_edge(((editor.network_id, j.network_id), 'editor'))

                    # add a co-editor rel to any other editors on this issue
                    for co_editor in editors[i+1:]:
                        add_edge(((editor.network_id, co_editor.network_id),
                                 'co-editor'))

                # authors and translators are at the item level
                for item in issue.item_set.all():
                    authors = item.creators.all()
                    for i, author in enumerate(authors):
                        # only add person if not already present in the graph
                        if author.network_id not in graph.vs['name']:
                            graph.add_vertex(author.network_id,
                                             label=author.firstname_lastname,
                                             type=author.network_type)
                        # author is a journal contributor
                        add_edge(((author.network_id, j.network_id),
                                 'contributor'))

                        # each author is connected to the issue editors who
                        # edited their work
                        for editor in editors:
                            add_edge(((editor.network_id, author.network_id),
                                     'edited'))

                        # add a co-author to any other authors on this item
                        for co_author in authors[i+1:]:
                            add_edge(((author.network_id, co_author.network_id),
                                     'co-author'))

                    for translator in item.translators.all():
                        # only add person if not already present in the graph
                        if translator.network_id not in graph.vs['name']:
                            graph.add_vertex(translator.network_id,
                                             label=translator.firstname_lastname,
                                             type=translator.network_type)

                        # translators are connected to the journal they contributed to
                        add_edge(((translator.network_id, j.network_id),
                                 'translator'))
                        # and to the author whose work they translated
                        for author in authors:
                            add_edge(((translator.network_id, author.network_id),
                                     'translated'))

            logger.debug('Added %d nodes and %d edges for %s in %.2f sec',
                         len(graph.vs()) - vtx_count, len(edges) - edge_count,
                         j, time.time() - start)

        # add person-school associations
        # - only a fairly small number of people are associated with
        # schools, so it should be most efficient to handle separately
        start = time.time()
        schooled_people = Person.objects.filter(schools__isnull=False) \
                                .prefetch_related('schools')
        for person in schooled_people:
            try:
                graph.vs.find(name=person.network_id)['schools'] = \
                    [s.name for s in person.schools.all()]

            except ValueError:
                # it's possible we have people associated with schools
                # who are not contributors to our journals, so this is
                # not an error, but providea  warning.
                logger.warn('School-associated person %s not found in contributor network graph',
                            person)
        logger.debug('Added school associations for %d people in %.2f sec',
                     schooled_people.count(), time.time() - start)

        start = time.time()
        # split edge information into source/target tuple and edge label
        edge_src_target, edge_labels = zip(*edges.keys())
        # add the edges to the graph
        graph.add_edges(edge_src_target)
        # set the edge labels
        graph.es['label'] = edge_labels
        # set edge weight based on number of occurrences
        graph.es['weight'] = edges.values()

        logger.debug('Added edges and edge sizes in %.2f sec',
                     time.time() - start)

        logger.debug('Complete journal contributor graph (%d nodes, %d edges) generated in %.2f sec',
                     len(graph.vs()), len(graph.es()), time.time() - full_start)

        # store the generated graph in the cache for the next time
        # for now, set cached graph to never time out
        cache.set(cls.contributor_network_cache_key, graph, None)
        return graph
开发者ID:emory-libraries-ecds,项目名称:zurnatikl,代码行数:104,代码来源:models.py


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