【问题标题】:Kou's algorithm to find Steiner Tree using igraphKou 使用 igraph 查找 Steiner 树的算法
【发布时间】:2015-07-17 07:41:45
【问题描述】:

我正在尝试实现 Kou 算法以使用 igraph 识别 R 中的 Steiner 树。

寇氏算法可以这样描述:

  1. 找到完整的距离图 G'(G' 有 V' = S(斯坦纳节点),并且对于 VxV 中的每一对节点 (u,v),有一条边的权重等于最小的权重这些节点之间的成本路径 p_(u,v) in G)
  2. 在 G' 中找到最小生成树 T'
  3. 通过用 G 的相应最短路径替换 T' 的每条边来构造 G 的子图 Gs,这是 G' 的一条边(有几条最短路径,选择任意一条)。
  4. 求 Gs 的最小生成树 Ts(如果有多个最小生成树,则任意选择一个)
  5. 从 Ts 构造一棵 Steiner 树 Th,方法是删除 Ts 中的边(如有必要),使 Th 中的所有叶子都是 Steiner 节点。

前两个步骤很简单:

g <- erdos.renyi.game(100, 1/10) # graph
V(g)$name <- 1:100

# Some steiner nodes
steiner.points <- sample(1:100, 5)

# Complete distance graph G'
Gi <- graph.full(5)
V(Gi)$name <- steiner.points

# Find a minimum spanning tree T' in G'
mst <- minimum.spanning.tree(Gi)

但是,我不知道如何将 T' 中的边替换为 G 中的最短路径。我知道使用 get.shortest.paths 我可以从一对节点中获取 vpath,但是我如何替换和在 T' 中与 G 中的 shortest.path 边缘?

提前非常感谢

【问题讨论】:

    标签: r igraph


    【解决方案1】:

    如果我理解你所写的算法,我认为这可以帮助你完成第 3 步,但如果不是这样,请澄清:

    library(igraph)
    
    set.seed(2002)
    
    g <- erdos.renyi.game(100, 1/10) # graph
    V(g)$name <- as.character(1:100)
    
    ## Some steiner nodes:
    steiner.points <- sample(1:100, 5)
    
    ## Complete distance graph G'
    Gi <- graph.full(5)
    V(Gi)$name <- steiner.points
    
    ## Find a minimum spanning tree T' in G'
    mst <- minimum.spanning.tree(Gi)
    
    ##  For each edge in mst, replace with shortest path:
    edge_list <- get.edgelist(mst)
    
    Gs <- mst
    for (n in 1:nrow(edge_list)) {
        i <- edge_list[n,2]
        j <- edge_list[n,1]
        ##  If the edge of T' mst is shared by Gi, then remove the edge from T'
        ##    and replace with the shortest path between the nodes of g: 
        if (length(E(Gi)[which(V(mst)$name==i) %--% which(V(mst)$name==j)]) == 1) {
            ##  If edge is present then remove existing edge from the 
            ##    minimum spanning tree:
            Gs <- Gs - E(Gs)[which(V(mst)$name==i) %--% which(V(mst)$name==j)]
    
            ##  Next extract the sub-graph from g corresponding to the 
            ##    shortest path and union it with the mst graph:
            g_sub <- induced.subgraph(g, (get.shortest.paths(g, from=V(g)[i], to=V(g)[j])$vpath[[1]]))
            Gs <- graph.union(Gs, g_sub, byname=T)
      }
    }
    
    par(mfrow=c(1,2))
    plot(mst)
    plot(Gs)
    

    左边是最小生成树图,右边是最短路径:

    【讨论】:

    • 感谢@Forrest,但是mst 中的所有边都应替换为最短路径(如果有多个最短路径,则随机选择一个)。我附上了一个链接,您可以在其中看到图形示例cs.umaine.edu/~markov/SteinerTrees.pdf
    • 我不确定您指的是哪些边缘。左图是您计算的最小生成树。右图中的每条边都被原始图 g 的最短路径替换,除了边 1 %--% 100 在模拟数据中是直接连接(节点 1 和 100 是邻居)。如果我遗漏了什么,请帮助我?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    相关资源
    最近更新 更多