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


Python Graph.getIndex方法代码示例

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


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

示例1: Graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import getIndex [as 别名]
    [3, 0], [3, 1], [3, 2], [3, 4], [3, 5],
    [4, 2], [4, 3], [4, 5], [4, 7], [4, 8], [4, 10],
    [5, 0], [5, 3], [5, 4], [5, 6], [5, 7],
    [6, 5], [6, 7],
    [7, 4], [7, 5], [7, 6], [7, 8],
    [8, 4], [8, 7], [8, 9], [8, 10], [8, 11],
    [9, 8], [9, 11],
    [10, 2], [10, 4], [10, 8], [10, 11],
    [11, 8], [11, 9], [11, 10]
  ]

graph1 = Graph(vertices, edges)
print("The vertices in graph1: " + str(graph1.getVertices()))
print("The number of vertices in graph1: " + str(graph1.getSize()))
print("The vertex with index 1 is " + graph1.getVertex(1))
print("The index for Miami is " + str(graph1.getIndex("Miami")))
print("The degree for Miami is " + str(graph1.getDegree("Miami")))
print("The edges for graph1:")
graph1.printEdges()
    
graph1.addVertex("Savannah")
graph1.addEdge("Atlanta", "Savannah")
graph1.addEdge("Savannah", "Atlanta")
print("\nThe edges for graph1 after adding a new vertex and edges:")
graph1.printEdges()

# List of Edge objects for graph in Figure 16.3(a)
names = ["Peter", "Jane", "Mark", "Cindy", "Wendy"]
edges = [[0, 2], [1, 2], [2, 4], [3, 4]]

# Create a graph with 5 vertices
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:33,代码来源:TestGraph.py

示例2: Graph

# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import getIndex [as 别名]
# Create an edge list for graph in Figure 16.1
edges = [
    [0, 1], [0, 3], [0, 5],
    [1, 0], [1, 2], [1, 3],
    [2, 1], [2, 3], [2, 4], [2, 10],
    [3, 0], [3, 1], [3, 2], [3, 4], [3, 5],
    [4, 2], [4, 3], [4, 5], [4, 7], [4, 8], [4, 10],
    [5, 0], [5, 3], [5, 4], [5, 6], [5, 7],
    [6, 5], [6, 7],
    [7, 4], [7, 5], [7, 6], [7, 8],
    [8, 4], [8, 7], [8, 9], [8, 10], [8, 11],
    [9, 8], [9, 11],
    [10, 2], [10, 4], [10, 8], [10, 11],
    [11, 8], [11, 9], [11, 10]
  ]

graph = Graph(vertices, edges)

dfs = graph.dfs(graph.getIndex("Chicago"))

searchOrders = dfs.getSearchOrders()
print(str(dfs.getNumberOfVerticesFound()) +
    " vertices are searched in this DFS order:")
for i in range(len(searchOrders)):
    print(graph.getVertex(searchOrders[i]), end = " ")
print();

for i in range(len(searchOrders)):
    if dfs.getParent(i) != -1:
        print("parent of " + graph.getVertex(i) +
            " is " + graph.getVertex(dfs.getParent(i)))
开发者ID:EthanSeaver,项目名称:Python-Projects,代码行数:33,代码来源:TestDFS.py


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