【问题标题】:Find the path and max-weigted edge in a Minimax path-finding solution?在 Minimax 寻路解决方案中找到路径和最大加权边?
【发布时间】:2014-10-06 12:59:04
【问题描述】:

我目前有一个编程任务:给定一个大的加权无连接图(1

到目前为止,我将图形存储在 AdjacencyList 中(IntegerPair 的向量的向量,其中第一个整数是邻居,第二个是边的权重)。

我还使用 Prim 算法获得了最小生成树:

private static void process(int vtx) {
  taken.set(vtx, true);

  for (int j = 0; j < AdjList.get(vtx).size(); j++) {
      IntegerPair v = AdjList.get(vtx).get(j);
      if (!taken.get(v.first())) {
          pq.offer(new IntegerPair(v.second(), v.first()));  //sort by weight then by adjacent vertex
      }
   }
}

void PreProcess() {
  Visited = new Vector<Boolean>();
  taken = new Vector<Boolean>(); 
  pq = new PriorityQueue<IntegerPair>();

  taken.addAll(Collections.nCopies(V, false));

  process(0);
  int numTaken = 1;
  int mst_cost = 0;

  while (!pq.isEmpty() && numTaken != V) { //do this until all V vertices are taken (or E = V - 1 edges are taken)
      IntegerPair front = pq.poll();

      if (!taken.get(front.second())) { // we have not connected this vertex yet
          mst_cost += front.first(); // add the weight of this edge
          process(front.second());
          numTaken++;
      }
  }
}

我现在陷入的是如何找到从源到目的地的路径并在以下查询中返回最大权重边缘:

int Query(int source, int destination) {
 int ans = 0;



 return ans;
}

有人告诉我使用深度优先搜索来遍历生成的 MST,但我认为 DFS 将遍历所有不在正确路径上的顶点(我说的对吗?)。以及如何找到最大边?

(这个问题与任何SSSP算法都没有关系,因为我没有学过Dijstra等)

【问题讨论】:

  • 这似乎与极小极大无关。

标签: path-finding depth-first-search minimum-spanning-tree minimax prims-algorithm


【解决方案1】:

一种可能的方法是使用 Kruskal 的 MST 算法。这是一个贪心算法,从一个空图开始,重复添加最轻的边,产生一个循环。这满足了树的属性,同时保证了最小加权路径。

要找到最大加权边缘,您还可以使用算法的属性。由于您知道 EdgeWeight(n) =

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-11
    • 1970-01-01
    • 2020-09-28
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多