// Undoes the elimination (or contraction) of a vertex public void Uneliminate() { FVertex restoreVertex = baseVertices[undoStack.Pop().a]; foreach (int u in restoreVertex.Adj) { AddAdj(baseVertices[u], restoreVertex); } currentVertices[vertexCount] = currentVertices[restoreVertex.ListLocation]; currentVertices[restoreVertex.ListLocation].ListLocation = vertexCount; currentVertices[restoreVertex.ListLocation] = restoreVertex; vertexPresent[restoreVertex.Id] = true; vertexCount++; while (undoStack.Count > 0) { UndoInfo ui = undoStack.Peek(); if (ui.b < 0) { break; } undoStack.Pop(); RemoveEdge(ui.a, ui.b); } }
// Implements the edge addition heuristic public void EdgeAddition(int upper) { #if DFS_EDGEADDITION UndoInfo temp = undoStack.Pop(); bool repeat = true; while (repeat) { repeat = false; foreach (FVertex v1 in Vertices) { if (v1.Degree < upper) { continue; } foreach (FVertex v2 in Vertices) { if (v2.Degree < upper) { continue; } if (v1.Id >= v2.Id || IsEdge(v1, v2)) { continue; } if (CommonNB(v1, v2) >= upper) { if (!AddEdge(v1, v2)) { throw new Exception(); } undoStack.Push(new UndoInfo(v1.Id, v2.Id)); repeat = true; } } } } undoStack.Push(temp); #endif }