From b05b8410d3535b1bc045e21fc7685c259f4719c8 Mon Sep 17 00:00:00 2001 From: Richard Wong Date: Mon, 6 May 2024 16:32:01 +0900 Subject: [PATCH] Feat: added 3 approaches to get MPS: planarity test, exact via ILP, and cactus --- ...gdf_mps_simple.cpp => ogdf_mps_cactus.cpp} | 5 +- make_planar/ogdf_mps_exact.cpp | 4 - make_planar/ogdf_mps_fast.cpp | 74 +++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) rename make_planar/{ogdf_mps_simple.cpp => ogdf_mps_cactus.cpp} (92%) create mode 100644 make_planar/ogdf_mps_fast.cpp diff --git a/make_planar/ogdf_mps_simple.cpp b/make_planar/ogdf_mps_cactus.cpp similarity index 92% rename from make_planar/ogdf_mps_simple.cpp rename to make_planar/ogdf_mps_cactus.cpp index cfad9e4..ff35e5c 100644 --- a/make_planar/ogdf_mps_simple.cpp +++ b/make_planar/ogdf_mps_cactus.cpp @@ -1,9 +1,9 @@ #include #include -#include // #include #include +#include #include #include @@ -40,7 +40,8 @@ int main(int argc, char* argv[]) std::cout << "start planarization" << std::endl; List *delEdges = new List; // empty list - ogdf::MaximalPlanarSubgraphSimple mps(*(new PlanarSubgraphFast)); + PlanarSubgraphCactus psc; + ogdf::MaximalPlanarSubgraphSimple mps(psc); mps.call(G, *delEdges); diff --git a/make_planar/ogdf_mps_exact.cpp b/make_planar/ogdf_mps_exact.cpp index 5b72893..3c2ffed 100644 --- a/make_planar/ogdf_mps_exact.cpp +++ b/make_planar/ogdf_mps_exact.cpp @@ -27,10 +27,6 @@ int main(int argc, char* argv[]) return 1; } - - NodeArray numbering(G); - int num = computeSTNumbering(G, numbering, nullptr, nullptr, true); - OGDF_ASSERT(num == G.numberOfNodes()); // print after input // graphPrinter(G); diff --git a/make_planar/ogdf_mps_fast.cpp b/make_planar/ogdf_mps_fast.cpp new file mode 100644 index 0000000..df5786d --- /dev/null +++ b/make_planar/ogdf_mps_fast.cpp @@ -0,0 +1,74 @@ +/* + * + */ +#include +#include + +#include +// #include +#include +#include + +#include + +using namespace ogdf; + + +int main(int argc, char* argv[]) +{ + + string inputFile = argv[1]; + Graph G; + + if (!GraphIO::read(G, inputFile, GraphIO::readGML)) { + std::cerr << "Could not read input.gml" << std::endl; + return 1; + } + + + NodeArray numbering(G); + int num = computeSTNumbering(G, numbering, nullptr, nullptr, true); + OGDF_ASSERT(num == G.numberOfNodes()); + + // print after input + // graphPrinter(G); + std::cout << "G Planarity: " << ogdf::isPlanar(G) << std::endl; + std::cout << "Original number of nodes: " << G.numberOfNodes() << std::endl; + std::cout << "Original number of edges: " << G.numberOfEdges() << std::endl; + + // separator for planarization + // <--------------> + + // PQ implementation to make planar subgraph + std::cout << "start planarization" << std::endl; + List *delEdges = new List; // empty list + + PlanarSubgraphFast psf; + // comment out to use default options + // psf.runs(1); + ogdf::MaximalPlanarSubgraphSimple mps(psf); + mps.call(G, *delEdges); + + + std::cout << "Edges removed:" << delEdges->size() << std::endl; + + + // delete removed edges + for (edge e: *delEdges) { + // print removed edges + // std::cout << e->adjSource() << std::endl; + G.delEdge(e); + } + + + // write processed graph to new gml file + // GraphIO::write(G, "output.gml", GraphIO::writeGML); + + + std::cout << "G planarity: " << ogdf::isPlanar(G) << std::endl; + std::cout << "Original number of nodes: " << G.numberOfNodes() << std::endl; + std::cout << "Subgraph number of edges: " << G.numberOfEdges() << std::endl; + + + return 0; +}