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


Python hypergraph.hypergraph函数代码示例

本文整理汇总了Python中pygraph.classes.hypergraph.hypergraph函数的典型用法代码示例。如果您正苦于以下问题:Python hypergraph函数的具体用法?Python hypergraph怎么用?Python hypergraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: create_release_graph

def create_release_graph(objects, release, previous):
    release_graph = hypergraph()
    release_graph.add_nodes(objects)
    release_graph.add_edges([release, previous])

    file_objects = [ccm_cache.get_object(o) for o in objects]
    for o in file_objects:
        link = True
        # Bind objects to this release
        successors = o.get_successors()
        if successors:
            for s in successors:
                if s not in release_graph.nodes():
                    link &= True
                else:
                    link &=False
        if link:
            if o.get_object_name() not in release_graph.links(release):
                release_graph.link(o.get_object_name(), release)

        # Bind objects to previous release
        predecessors = o.get_predecessors()
        if predecessors is not None:
            for p in predecessors:
                if p not in objects:
                    if not release_graph.has_node(p):
                        release_graph.add_node(p)
                        #print "linking", p, "to release", previous
                        release_graph.link(p, previous)

    return release_graph
开发者ID:J-Sorenson,项目名称:PySynergy,代码行数:31,代码来源:ccm_history_to_graphs.py

示例2: test_cut_nodes_in_hypergraph

 def test_cut_nodes_in_hypergraph(self):
     gr = hypergraph()
     
     # Add some nodes / edges
     gr.add_nodes(range(9))
     gr.add_hyperedges(['a', 'b', 'c'])
     
     # Connect the 9 nodes with three size-3 hyperedges
     for node_set in [['a',0,1,2], ['b',3,4,5], ['c',6,7,8]]:
         for node in node_set[1:]:
             gr.link(node, node_set[0])
     
     # Connect the groups
     gr.add_hyperedges(['l1','l2'])
     gr.link(0, 'l1')
     gr.link(3, 'l1')
     gr.link(5, 'l2')
     gr.link(8, 'l2')
     
     cn = cut_nodes(gr);
     
     assert 0 in cn
     assert 3 in cn
     assert 5 in cn
     assert 8 in cn
     assert len(cn) == 4
开发者ID:svn2github,项目名称:python-graph2,代码行数:26,代码来源:unittests-accessibility.py

示例3: test_hypergraph_equality_labels

 def test_hypergraph_equality_labels(self):
     """
     Hyperaph equality test. This one checks edge equality. 
     """
     gr = hypergraph()
     gr.add_nodes([0,1,2,3])
     gr.add_edge('e1')
     gr.add_edge('e2')
     gr.add_edge('e3')
     gr.set_edge_label('e1', 'l1')
     gr.set_edge_label('e2', 'l2')
     
     gr2 = deepcopy(gr)
     
     gr3 = deepcopy(gr)
     gr3.set_edge_label('e3', 'l3')
     
     gr4 = deepcopy(gr)
     gr4.set_edge_label('e1', 'lx')
     
     gr5 = deepcopy(gr)
     gr5.del_edge('e1')
     gr5.add_edge('e1')
     
     assert gr == gr2
     assert gr2 == gr
     assert gr != gr3
     assert gr3 != gr
     assert gr != gr4
     assert gr4 != gr
     assert gr != gr5
     assert gr5 != gr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:32,代码来源:unittests-hypergraph.py

示例4: test_hypergraph_equality_edges

 def test_hypergraph_equality_edges(self):
     """
     Hyperaph equality test. This one checks edge equality. 
     """
     gr = hypergraph()
     gr.add_nodes([0,1,2,3])
     gr.add_edge('e1')
     gr.add_edge('e2')
     gr.link(0, 'e1')
     gr.link(1, 'e1')
     gr.link(1, 'e2')
     gr.link(2, 'e2')
     
     gr2 = deepcopy(gr)
     
     gr3 = deepcopy(gr)
     gr3.del_edge('e2')
     
     gr4 = deepcopy(gr)
     gr4.unlink(1, 'e2')
     
     assert gr == gr2
     assert gr2 == gr
     assert gr != gr3
     assert gr3 != gr
     assert gr != gr4
     assert gr4 != gr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:27,代码来源:unittests-hypergraph.py

示例5: test_hypergraph_equality_weight

 def test_hypergraph_equality_weight(self):
     """
     Hyperaph equality test. This one checks edge equality. 
     """
     gr = hypergraph()
     gr.add_nodes([0,1,2,3])
     gr.add_edge('e1')
     gr.add_edge('e2')
     gr.add_edge('e3')
     gr.set_edge_weight('e1', 2)
     
     gr2 = deepcopy(gr)
     
     gr3 = deepcopy(gr)
     gr3.set_edge_weight('e3', 2)
     
     gr4 = deepcopy(gr)
     gr4.set_edge_weight('e1', 1)
     
     assert gr == gr2
     assert gr2 == gr
     assert gr != gr3
     assert gr3 != gr
     assert gr != gr4
     assert gr4 != gr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:25,代码来源:unittests-hypergraph.py

示例6: read_hypergraph

def read_hypergraph(string):
    """
    Read a hypergraph from a string in dot format. Nodes and edges specified in the input will be
    added to the current hypergraph.
    
    @type  string: string
    @param string: Input string in dot format specifying a graph.
    
    @rtype:  hypergraph
    @return: Hypergraph
    """
    hgr = hypergraph()
    dotG = pydot.graph_from_dot_data(string)
    
    # Read the hypernode nodes...
    # Note 1: We need to assume that all of the nodes are listed since we need to know if they
    #           are a hyperedge or a normal node
    # Note 2: We should read in all of the nodes before putting in the links
    for each_node in dotG.get_nodes():
        if 'hypernode' == each_node.get('hyper_node_type'):
            hgr.add_node(each_node.get_name())
        elif 'hyperedge' == each_node.get('hyper_node_type'):
            hgr.add_hyperedge(each_node.get_name())
    
    # Now read in the links to connect the hyperedges
    for each_link in dotG.get_edges():
        if hgr.has_node(each_link.get_source()):
            link_hypernode = each_link.get_source()
            link_hyperedge = each_link.get_destination()
        elif hgr.has_node(each_link.get_destination()):
            link_hypernode = each_link.get_destination()
            link_hyperedge = each_link.get_source()
        hgr.link(link_hypernode, link_hyperedge)
    
    return hgr
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:35,代码来源:dot.py

示例7: test_cut_edges_in_hypergraph

 def test_cut_edges_in_hypergraph(self):
     gr = hypergraph()
     
     # Add some nodes / edges
     gr.add_nodes(range(9))
     gr.add_hyperedges(['a1', 'b1', 'c1'])
     gr.add_hyperedges(['a2', 'b2', 'c2'])
     
     # Connect the 9 nodes with three size-3 hyperedges
     for node_set in [['a1',0,1,2], ['b1',3,4,5], ['c1',6,7,8], ['a2',0,1,2], ['b2',3,4,5], ['c2',6,7,8]]:
         for node in node_set[1:]:
             gr.link(node, node_set[0])
     
     # Connect the groups
     gr.add_hyperedges(['l1','l2'])
     gr.link(0, 'l1')
     gr.link(3, 'l1')
     gr.link(5, 'l2')
     gr.link(8, 'l2')
     
     ce = cut_edges(gr)
     
     assert 'l1' in ce
     assert 'l2' in ce
     assert len(ce) == 2
开发者ID:svn2github,项目名称:python-graph2,代码行数:25,代码来源:unittests-accessibility.py

示例8: test_check_add_node_s

    def test_check_add_node_s(self):
        gr = hypergraph()
        nodes = [1, 2, 3]
        gr.add_nodes(nodes)
        gr.add_node(0)

        for n in [0] + nodes:
            assert n in gr
            assert gr.has_node(n)
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-hypergraph.py

示例9: test_raise_exception_on_duplicate_node_addition

 def test_raise_exception_on_duplicate_node_addition(self):
     gr = hypergraph()
     gr.add_node("a_node")
     try:
         gr.add_node("a_node")
     except AdditionError:
         pass
     else:
         fail()
开发者ID:svn2github,项目名称:python-graph2,代码行数:9,代码来源:unittests-hypergraph.py

示例10: test_raise_exception_when_edge_added_to_non_existing_node

 def test_raise_exception_when_edge_added_to_non_existing_node(self):
     gr = hypergraph()
     gr.add_nodes([0, 1])
     try:
         gr.link(0, 3)
     except KeyError:
         pass
     else:
         fail()
     assert gr.neighbors(0) == []
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-hypergraph.py

示例11: test_raise_exception_on_non_existing_link_removal

 def test_raise_exception_on_non_existing_link_removal(self):
     gr = hypergraph()
     gr.add_node(0)
     gr.add_hyperedge(1)
     try:
         gr.unlink(0, 1)
     except ValueError:
         pass
     else:
         fail()
开发者ID:svn2github,项目名称:python-graph2,代码行数:10,代码来源:unittests-hypergraph.py

示例12: test_raise_exception_on_duplicate_edge_link

 def test_raise_exception_on_duplicate_edge_link(self):
     gr = hypergraph()
     gr.add_node("a node")
     gr.add_hyperedge("an edge")
     gr.link("a node", "an edge")
     try:
         gr.link("a node", "an edge")
     except AdditionError:
         pass
     else:
         fail()
开发者ID:svn2github,项目名称:python-graph2,代码行数:11,代码来源:unittests-hypergraph.py

示例13: test_connected_components_hypergraph

 def test_connected_components_hypergraph(self):
     gr = hypergraph()
     
     # Add some nodes / edges
     gr.add_nodes(range(9))
     gr.add_hyperedges(['a', 'b', 'c'])
     
     # Connect the 9 nodes with three size-3 hyperedges
     for node_set in [['a',0,1,2], ['b',3,4,5], ['c',6,7,8]]:
         for node in node_set[1:]:
             gr.link(node, node_set[0])
     
     cc = connected_components(gr)
     
     assert 3 == len(set(cc.values()))
     
     assert cc[0] == cc[1] and cc[1] == cc[2]
     assert cc[3] == cc[4] and cc[4] == cc[5]
     assert cc[6] == cc[7] and cc[7] == cc[8]
     
     
     # Do it again with two components and more than one edge for each
     gr = hypergraph()
     gr.add_nodes(range(9))
     gr.add_hyperedges(['a', 'b', 'c', 'd'])
     
     for node_set in [['a',0,1,2], ['b',2,3,4], ['c',5,6,7], ['d',6,7,8]]:
         for node in node_set[1:]:
             gr.link(node, node_set[0])
     
     cc = connected_components(gr)
     
     assert 2 == len(set(cc.values()))
     
     for i in [0,1,2,3]:
         assert cc[i] == cc[i+1]
     
     for i in [5,6,7]:
         assert cc[i] == cc[i+1]
         
     assert cc[4] != cc[5]
开发者ID:svn2github,项目名称:python-graph2,代码行数:41,代码来源:unittests-accessibility.py

示例14: test_hypergraph_link_unlink_link

 def test_hypergraph_link_unlink_link(self):
     """
     Hypergraph link-unlink-link test. It makes sure that unlink cleans 
     everything properly. No AdditionError should occur.
     """
     h = hypergraph()
     h.add_nodes([1,2])
     h.add_edges(['e1'])
     
     h.link(1, 'e1')
     h.unlink(1, 'e1')
     h.link(1,'e1')
开发者ID:GadgetSteve,项目名称:python-graph,代码行数:12,代码来源:unittests-hypergraph.py

示例15: create_task_graph

def create_task_graph(tasks, objects):
    task_graph = hypergraph()
    task_graph.add_nodes([o.get_object_name() for o in objects])
    task_graph.add_hyperedges([t.get_object_name() for t in tasks])
    #link the objects and the tasks
    for t in tasks:
        for o in t.get_objects():
            #print "linking:", o, "and", t.get_object_name()
            task_graph.link(o, t.get_object_name())
    # Add single_objects to task_graph
    for o in find_objects_without_associated_tasks(objects, tasks):
        task_graph.add_hyperedge(o.get_object_name())
        #print "linking:", o.get_object_name(), "and", o.get_object_name()
        task_graph.link(o.get_object_name(), o.get_object_name())

    return task_graph
开发者ID:knupouls,项目名称:PySynergy,代码行数:16,代码来源:ccm_history_to_graphs.py


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