build: added makefile for deferred_planarity_test

This commit is contained in:
Richard Wong 2024-02-05 11:02:44 +09:00
parent 28dceaa575
commit 00ce484c58
Signed by: richard
GPG Key ID: 5BD36BA2E9EE33D0
10 changed files with 191 additions and 9 deletions

6
.gitignore vendored
View File

@ -1,7 +1,11 @@
.vscode .vscode
deferred_planarity_test/bin deferred_planarity_test/build
make_graphs/bin make_graphs/bin
make_graphs/test_graphs make_graphs/test_graphs
make_planar/bin make_planar/bin
test_area test_area
dpt dpt
# remove build intermediate files
deferred_planarity_test/obj/
deferred_planarity_test/bin/

View File

@ -0,0 +1,34 @@
SRC_DIR := src
OBJ_DIR := obj
BIN_DIR := bin
TARGET := $(BIN_DIR)/dpt_planarizer
SRCS := $(wildcard $(SRC_DIR)/*.cpp)
OBJS := $(SRCS:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
# compiler and flags
CXX := g++
CPPFLAGS := -Iinclude -MMD -MP
CXXFLAGS := -std=c++14 -Wall
LDFLAGS := -lOGDF
build: $(TARGET)
# build target executable
$(TARGET): $(OBJS) | $(BIN_DIR)
$(CXX) $^ -o $@ $(LDFLAGS)
# compile source to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
$(BIN_DIR) $(OBJ_DIR):
mkdir -p $@
# include dependency files
-include $(DEPS)
.PHONY: clean
clean:
rm -r $(BIN_DIR) $(OBJ_DIR)

View File

@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include <ogdf/fileformats/GraphIO.h> #include <ogdf/fileformats/GraphIO.h>
#define START_TEMP 100
using namespace std; using namespace std;
@ -39,20 +40,19 @@ vector<int> sa_solve(string input_file, int k_max) {
int e_new = 0; int e_new = 0;
int delta = 0; int delta = 0;
// initialize terms // initialize terms
double temp = 100; double temp;
for (int k = 0; k < k_max; ++k) { for (int k = 0; k < k_max; ++k) {
temp = temp_decay(k, k_max); temp = START_TEMP * temp_decay(k, k_max);
state_new = generate_mutated_post_order(input_file, state_old); state_new = generate_mutated_post_order(input_file, state_old);
e_new = compute_removed_edge_size(input_file, state_new); e_new = compute_removed_edge_size(input_file, state_new);
delta = e_new - e_old; delta = e_new - e_old;
if (std::exp( -(delta) / temp) > distribution(rng)) { if (std::exp( -(delta) / temp) > distribution(rng)) {
state_old = state_new; state_old = state_new;
e_old = e_new; e_old = e_new;
} }
// std::cout << "temp: " << temp << ", score: " << e_old << std::endl;
} }
return state_old; return state_old;

View File

@ -4,7 +4,7 @@
#include "mps.h" #include "mps.h"
//Empty constructor // constructor can be made empty
maximal_planar_subgraph_finder::maximal_planar_subgraph_finder() {} maximal_planar_subgraph_finder::maximal_planar_subgraph_finder() {}
//Destructor //Destructor

View File

@ -108,7 +108,7 @@ void maximal_planar_subgraph_finder::read_from_gml(string input_file) {
//Output a maximal planar subgraph in the same format as input. // count the number of removed edges
int maximal_planar_subgraph_finder::output_removed_edge_size() { int maximal_planar_subgraph_finder::output_removed_edge_size() {
int sum = 0; int sum = 0;
for (int i = 0; i < _back_edge_list.size(); ++i) { for (int i = 0; i < _back_edge_list.size(); ++i) {

View File

@ -302,9 +302,11 @@ int main(int argc, char* argv[])
std::cout << "Edges removed:" << delEdges->size() << std::endl; std::cout << "Edges removed:" << delEdges->size() << std::endl;
// delete removed edges
for (edge e: *delEdges) { for (edge e: *delEdges) {
// print removed edges // print removed edges
std::cout << e->adjSource() << std::endl; // std::cout << e->adjSource() << std::endl;
G.delEdge(e); G.delEdge(e);
} }

View File

@ -0,0 +1,74 @@
#include <ogdf/basic/STNumbering.h>
#include <ogdf/fileformats/GraphIO.h>
// #include <ogdf/basic/extended_graph_alg.h>
#include <ogdf/planarity/PlanarSubgraphFast.h>
#include <ogdf/planarity/PlanarSubgraphBoyerMyrvold.h>
#include <ogdf/planarity/PlanarSubgraphPC.h>
#include <ogdf/planarity/MaximumPlanarSubgraph.h>
#include <ogdf/planarity/MaximalPlanarSubgraphSimple.h>
#include <iostream>
#include <map>
#include <chrono>
#include <getopt.h>
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
std::cout << "running maximum" << std::endl;
ogdf::MaximumPlanarSubgraph<int> mps;
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;
}

View File

@ -0,0 +1,68 @@
#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
ogdf::MaximalPlanarSubgraphSimple<int> mps(*(new PlanarSubgraphFast<int>));
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;
}