2024-05-08 16:03:40 +09:00
|
|
|
/* Maximum Planar Subgraph by Integer Linear Program (ILP)
|
|
|
|
*
|
|
|
|
*/
|
2024-02-05 11:02:44 +09:00
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
#include <ogdf/fileformats/GraphIO.h>
|
2024-02-05 11:02:44 +09:00
|
|
|
#include <ogdf/planarity/MaximumPlanarSubgraph.h>
|
2024-05-08 16:03:40 +09:00
|
|
|
#include <filesystem>
|
2024-02-05 11:02:44 +09:00
|
|
|
#include <iostream>
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
using namespace ogdf;
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
string input_file = argv[1];
|
2024-02-05 11:02:44 +09:00
|
|
|
Graph G;
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
if (!GraphIO::read(G, input_file, GraphIO::readGML)) {
|
2024-02-05 11:02:44 +09:00
|
|
|
std::cerr << "Could not read input.gml" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
// --------------------------------
|
|
|
|
// planarize
|
|
|
|
// --------------------------------
|
2024-02-05 11:02:44 +09:00
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
// store the deleted edges to be used to delete edges from G
|
|
|
|
List<edge> *delEdges = new List<edge>;
|
2024-02-05 11:02:44 +09:00
|
|
|
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
auto start = std::chrono::high_resolution_clock::now();
|
2024-02-05 11:02:44 +09:00
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
// perform planarization by ILP
|
2024-02-05 11:02:44 +09:00
|
|
|
ogdf::MaximumPlanarSubgraph<int> mps;
|
|
|
|
mps.call(G, *delEdges);
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
auto end = std::chrono::high_resolution_clock::now();
|
|
|
|
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
|
|
|
|
double time = static_cast<double>(microseconds) / 1'000'000.0;
|
2024-02-05 11:02:44 +09:00
|
|
|
|
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
// --------------------------------
|
|
|
|
// print out result of planarization
|
|
|
|
// --------------------------------
|
2024-02-05 11:02:44 +09:00
|
|
|
|
2024-05-08 16:03:40 +09:00
|
|
|
int removed_edges = delEdges->size();
|
|
|
|
string filename = std::filesystem::path(input_file).stem();
|
|
|
|
std::cout << filename << ", " << removed_edges << ", " << time << std::endl;
|
2024-02-05 11:02:44 +09:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|