template <class R> void CMatrix<R>::combineVertices(int a, int b, const R& aa, const R& ab, const R& ba, const R& bb) { combineVertices(a, b, aa, ab, ba, bb, 0); }
huReturn hookUp(const vector<SplitEdge> &g, int s, vector<SplitEdge> &bIn, int k, vector<vector<int>> &Y, historyIndex &h) { if (cG(s, g) != 0) { cout << "cG(s) problem in hookup" << endl; throw logic_error(""); } vector<SplitEdge> H = g; vector<SplitEdge> G1 = g; vector<SplitEdge> B = bIn; vector<SplitEdge> B1; vector<vector<int>> XS; int maxNodeInd = getMaxNodeInd(G1); for (int i = 0; i < maxNodeInd; i++) XS.push_back(vector<int>()); for (int i = 0; i < maxNodeInd; i++) XS[i].push_back(i); //cout << "About to enter while loop" << endl; while (getNumUsedNodes(H) >= 4) { vector<int> ma = maOrderingHeap(H, s); int v = ma[ma.size() - 2]; int w = ma[ma.size() - 1]; if (v == s || w == s) throw logic_error("SET WAS V - S, S FOUND"); vector<int> X1; H = combineVertices(H, v, w); H = compress(H); XS[v] = setUnion(XS[v], XS[w]); if (XS[w].size() == 0) { cout << "Error: W, " << w << " was merged twice. Quitting" << endl; throw logic_error(""); } XS[w] = vector<int>(); if (cG(v, H) < k) { int numToGet = (int)ceil(.5*(double(k) - double(cG(G1, XS[v])))); vector<SplitEdge> GX = inducedSubgraph(G1, XS[v]); vector<SplitEdge> delB; int added = 0; for (unsigned i = 0; i < GX.size(); i++) { SplitEdge e = SplitEdge(GX[i].end0, GX[i].end1, GX[i].weight, GX[i].orig0, GX[i].orig1); if (isMem(e, B)) { int bW = B[indexOfEdge(B, e.end0, e.end1)].weight; if (bW < e.weight) e.weight = bW; if (e.weight > (numToGet - added)) { e.weight = numToGet - added; } added += e.weight; delB.push_back(e); } if (added == numToGet) break; } if (added != numToGet) { cout << "Error: GX did not contain " << numToGet << " entries in B. Quitting." << endl; throw logic_error(""); } if (!isSubset(delB, B)) { cout << "ERROR: delB is not a subset of B." << endl; cout << "B:" << endl; output(B); cout << "delB:" << endl; output(delB); cout << "This was the GX to choose from:" << endl; output(GX); cout << "V: " << v << endl; cout << "W: " << w << endl; cout << "S: " << s << endl; throw logic_error(""); } B = setRemove(delB, B); B = removeZeroWeighted(B); B1 = setUnion(delB, B1); H = removeZeroWeighted(H); G1 = hookUpHelper(s, G1, delB, h); G1 = removeZeroWeighted(G1); H = removeZeroWeighted(H); bool addedFromXSinH = false; numToGet *= 2; for (unsigned i = 0; i < H.size(); i++) { SplitEdge tester = SplitEdge(s, v, 0, 0, 0); if (equals(tester, H[i])) { //cout << "Increasing weight in hookUp in H between " << H[i].end0 << " and " << H[i].end1 << "from " << H[i].weight << " to " << H[i].weight + numToGet << endl; H[i].weight += numToGet; addedFromXSinH = true; break; } } if (!addedFromXSinH && numToGet != 0) { //cout << "Creating edge in hookUp in H between " << s << " and " << v << " with weight " << numToGet << endl; SplitEdge e(s, v, numToGet, s, v); H.push_back(e); } vector<vector<int>> newY; for (unsigned i = 0; i < Y.size(); i++) { if (!isProperSubset(Y[i], XS[v])) newY.push_back(Y[i]); } bool foundX1inY = false; for (unsigned i = 0; i < newY.size(); i++) { if (setsEqual(newY[i], XS[v])) foundX1inY = true; } if (!foundX1inY) newY.push_back(XS[v]); Y = newY; } } huReturn ret; ret.BP = B1; ret.G1 = G1; ret.Y = Y; return ret; }