private void prim() throws ContradictionException { if (FILTER) { maxTArc = propHK.getMinArcVal(); } currentSCC = sccOf[start].get(); addNode(start); int from, to; while (tSize < n - 1 && !heap.isEmpty()) { while (tSize < n - 1 && !heap.isEmpty()) { to = heap.pop(); from = heap.getMate(to); addArc(from, to); } if (tSize < n - 1) { nextSCC(); } } if (tSize != n - 1) { propHK.contradiction(); } }
private void addNode(int i) { int y; int smallN = n / 2; if (!inTree.get(i)) { inTree.set(i); INeighbors nei = g.getNeighborsOf(i); for (int j = nei.getFirstElement(); j >= 0; j = nei.getNextElement()) { y = j; if (y >= smallN) { y -= smallN; } if ((!inTree.get(j)) && sccOf[y].get() == currentSCC) { if (ma.get(i * n + j) || ma.get(i + j * n)) { heap.add(j, minVal, i); } else { heap.add(j, costs[i][j], i); } } } } }
public void computeMST(double[][] costs, UndirectedGraph graph) throws ContradictionException { g = graph; ma = propHK.getMandatoryArcsBitSet(); for (int i = 0; i < n; i++) { Tree.getNeighborsOf(i).clear(); } this.costs = costs; heap.clear(); inTree.clear(); treeCost = 0; tSize = 0; minVal = propHK.getMinArcVal(); prim(); }