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


Python Vertex.add_edge方法代码示例

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


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

示例1: test_top_sort_cycle

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_top_sort_cycle():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    g = Graph([a, b])
    assert_raises(ValueError, g.top_sort)
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例2: test_add_edge_normal

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_add_edge_normal():
    a = Vertex("A5")
    b = Vertex("A6")
    c = Edge(b)
    a.add_edge(c)
    assert len(a.edges) == 1
    assert c in a.edges
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例3: test_has_cycle_two_vertices_linked

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_has_cycle_two_vertices_linked():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    g = Graph([a, b])
    assert g.has_cycle()
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例4: test_is_connected_two_doubly_connected

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_is_connected_two_doubly_connected():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    g = Graph([a, b])
    assert g.is_connected()
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例5: test_find_path_direct_connection

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_find_path_direct_connection():
    a = Vertex("A13")
    b = Vertex("A14")
    a.add_edge(Edge(b))
    assert find_path(a, b) == [a, b]
    # Path is only in one direction
    assert find_path(b, a) == []
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例6: test_find_path_chain

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_find_path_chain():
    a = Vertex("A15")
    b = Vertex("A16")
    c = Vertex("A17")
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    assert find_path(a, c) == [a, b, c]
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例7: test_dfs_chain

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_dfs_chain():
    a = Vertex("A23")
    b = Vertex("A24")
    c = Vertex("A25")
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    assert dfs(a, c)
开发者ID:mmweber2,项目名称:adm,代码行数:9,代码来源:test_graph.py

示例8: test_dfs_cycle

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_dfs_cycle():
    a = Vertex("A30")
    b = Vertex("A31")
    c = Vertex("A32")
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    b.add_edge(Edge(c))
    assert dfs(a, c)
开发者ID:mmweber2,项目名称:adm,代码行数:10,代码来源:test_graph.py

示例9: test_find_path_cycle

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_find_path_cycle():
    a = Vertex("A33")
    b = Vertex("A34")
    c = Vertex("A35")
    a.add_edge(Edge(b))
    b.add_edge(Edge(a))
    b.add_edge(Edge(c))
    assert find_path(a, c) == [a, b, c]
开发者ID:mmweber2,项目名称:adm,代码行数:10,代码来源:test_graph.py

示例10: test_top_sort_chain

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_top_sort_chain():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    c = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    g = Graph([a, b, c])
    assert g.top_sort() == [a, b, c]
开发者ID:mmweber2,项目名称:adm,代码行数:10,代码来源:test_graph.py

示例11: test_add_edge_duplicate

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_add_edge_duplicate():
    a = Vertex("A7")
    b = Vertex("A8")
    c = Edge(b)
    d = Edge(b)
    a.add_edge(d)
    a.add_edge(c)
    assert len(a.edges) == 2
    assert d in a.edges
    assert c in a.edges
开发者ID:mmweber2,项目名称:adm,代码行数:12,代码来源:test_graph.py

示例12: test_dfs_multiple_paths

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_dfs_multiple_paths():
    a = Vertex("A26")
    b = Vertex("A27")
    c = Vertex("A28")
    d = Vertex("A29")
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    c.add_edge(Edge(d))
    a.add_edge(Edge(d))
    assert dfs(a, d)
开发者ID:mmweber2,项目名称:adm,代码行数:12,代码来源:test_graph.py

示例13: test_find_path_ignores_weights

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_find_path_ignores_weights():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b, 1))
    c = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(c, 100))
    b.add_edge(Edge(c, 1))
    assert find_path(a, c) == [a, c]
开发者ID:mmweber2,项目名称:adm,代码行数:10,代码来源:test_graph.py

示例14: test_is_connected_three_vert_two_connections

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_is_connected_three_vert_two_connections():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    c = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    c.add_edge(Edge(a))
    g = Graph([a, b, c])
    assert g.is_connected()
开发者ID:mmweber2,项目名称:adm,代码行数:11,代码来源:test_graph.py

示例15: test_has_cycle_indirect

# 需要导入模块: from graph import Vertex [as 别名]
# 或者: from graph.Vertex import add_edge [as 别名]
def test_has_cycle_indirect():
    a = Vertex(Vertex._make_test_vertex())
    b = Vertex(Vertex._make_test_vertex())
    c = Vertex(Vertex._make_test_vertex())
    a.add_edge(Edge(b))
    b.add_edge(Edge(c))
    c.add_edge(Edge(a))
    g = Graph([a, b, c])
    assert g.has_cycle()
开发者ID:mmweber2,项目名称:adm,代码行数:11,代码来源:test_graph.py


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