Feat: added 3 approaches to get MPS: planarity test, exact via ILP, and

cactus
This commit is contained in:
Richard Wong 2024-05-06 16:32:01 +09:00
parent 850255fab2
commit b05b8410d3
Signed by: richard
GPG Key ID: 72948FBB6D359A6D
3 changed files with 77 additions and 6 deletions

View File

@ -1,9 +1,9 @@
#include <ogdf/basic/STNumbering.h> #include <ogdf/basic/STNumbering.h>
#include <ogdf/fileformats/GraphIO.h> #include <ogdf/fileformats/GraphIO.h>
#include <ogdf/planarity/PlanarSubgraphFast.h>
// #include <ogdf/planarity/PlanarSubgraphBoyerMyrvold.h> // #include <ogdf/planarity/PlanarSubgraphBoyerMyrvold.h>
#include <ogdf/planarity/MaximumPlanarSubgraph.h> #include <ogdf/planarity/MaximumPlanarSubgraph.h>
#include <ogdf/planarity/PlanarSubgraphCactus.h>
#include <ogdf/planarity/MaximalPlanarSubgraphSimple.h> #include <ogdf/planarity/MaximalPlanarSubgraphSimple.h>
#include <iostream> #include <iostream>
@ -40,7 +40,8 @@ int main(int argc, char* argv[])
std::cout << "start planarization" << std::endl; std::cout << "start planarization" << std::endl;
List<edge> *delEdges = new List<edge>; // empty list List<edge> *delEdges = new List<edge>; // empty list
ogdf::MaximalPlanarSubgraphSimple<int> mps(*(new PlanarSubgraphFast<int>)); PlanarSubgraphCactus<int> psc;
ogdf::MaximalPlanarSubgraphSimple<int> mps(psc);
mps.call(G, *delEdges); mps.call(G, *delEdges);

View File

@ -27,10 +27,6 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
NodeArray<int> numbering(G);
int num = computeSTNumbering(G, numbering, nullptr, nullptr, true);
OGDF_ASSERT(num == G.numberOfNodes());
// print after input // print after input
// graphPrinter(G); // graphPrinter(G);

View File

@ -0,0 +1,74 @@
/*
*
*/
#include <ogdf/basic/STNumbering.h>
#include <ogdf/fileformats/GraphIO.h>
#include <ogdf/planarity/PlanarSubgraphFast.h>
// #include <ogdf/planarity/PlanarSubgraphBoyerMyrvold.h>
#include <ogdf/planarity/MaximumPlanarSubgraph.h>
#include <ogdf/planarity/MaximalPlanarSubgraphSimple.h>
#include <iostream>
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<int> 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<edge> *delEdges = new List<edge>; // empty list
PlanarSubgraphFast<int> psf;
// comment out to use default options
// psf.runs(1);
ogdf::MaximalPlanarSubgraphSimple<int> 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;
}