Feat: reworked node marking to use enums; removed _ref_mark

This commit is contained in:
Richard Wong 2024-02-29 10:58:10 +09:00
parent e35462ef2d
commit 0ea4da9f0d
Signed by: richard
GPG Key ID: 5BD36BA2E9EE33D0
5 changed files with 23 additions and 18 deletions

View File

@ -33,6 +33,12 @@ enum node_type {
AE_VIRTUAL_ROOT = 3 AE_VIRTUAL_ROOT = 3
}; };
enum mark_type {
UNMARKED = 0,
MARKED = 1,
RESERVED = 2,
};
class node class node
{ {
public: public:
@ -116,7 +122,6 @@ public:
//MARK //MARK
void mark(); void mark();
static void init_mark();
void un_mark(); void un_mark();
bool is_marked(); bool is_marked();
@ -146,8 +151,7 @@ private:
vector<node*> _essential_list; vector<node*> _essential_list;
//Mark //Mark
int _mark; mark_type _mark;
static int _ref_mark;
}; };
class maximal_planar_subgraph_finder class maximal_planar_subgraph_finder

View File

@ -31,4 +31,4 @@ $(BIN_DIR) $(OBJ_DIR):
.PHONY: clean .PHONY: clean
clean: clean:
rm -r $(BIN_DIR) $(OBJ_DIR) rm -r $(OBJ_DIR)

View File

@ -13,7 +13,6 @@
#include <vector> #include <vector>
#include <ogdf/fileformats/GraphIO.h> #include <ogdf/fileformats/GraphIO.h>
#define START_TEMP 100
using namespace std; using namespace std;

View File

@ -34,7 +34,13 @@ maximal_planar_subgraph_finder::return_post_order() {
//Determine the post-order-list by a DFS-traversal. //Determine the post-order-list by a DFS-traversal.
void void
maximal_planar_subgraph_finder::postOrderTraversal() { maximal_planar_subgraph_finder::postOrderTraversal() {
node::init_mark(); // node::init_mark(); // set ref_mark
// print out the ref_mark
// std::cout << "normal post order traversal" << std::endl;
// std::cout << "the ref mark is initialized to be:" << std::endl;
// _node_list[0]->print_ref_mark();
// always start with node 0 // always start with node 0
int postOrderID = 0; int postOrderID = 0;
for (int i = 0; i < _node_list.size(); ++i) { for (int i = 0; i < _node_list.size(); ++i) {
@ -50,7 +56,7 @@ maximal_planar_subgraph_finder::postOrderTraversal() {
// return is by reference via _post_order_list // return is by reference via _post_order_list
void void
maximal_planar_subgraph_finder::guidedPostOrderTraversal(vector<int> post_order) { maximal_planar_subgraph_finder::guidedPostOrderTraversal(vector<int> post_order) {
node::init_mark(); // node::init_mark();
vector<int> rev_post_order; vector<int> rev_post_order;
for (int i = post_order.size() - 1; i >= 0; --i) { for (int i = post_order.size() - 1; i >= 0; --i) {
@ -86,7 +92,7 @@ maximal_planar_subgraph_finder::guidedPostOrderTraversal(vector<int> post_order)
// return is by reference via _post_order_list // return is by reference via _post_order_list
void void
maximal_planar_subgraph_finder::mutatedPostOrderTraversal(vector<int> post_order, int mutate_point) { maximal_planar_subgraph_finder::mutatedPostOrderTraversal(vector<int> post_order, int mutate_point) {
node::init_mark(); // node::init_mark();
vector<int> rev_post_order; vector<int> rev_post_order;
for (int i = post_order.size() - 1; i >= 0; --i) { for (int i = post_order.size() - 1; i >= 0; --i) {

View File

@ -5,7 +5,7 @@
#include "mps.h" #include "mps.h"
// #define DEBUG // #define DEBUG
#define DEBUG_MUTATION // #define DEBUG_MUTATION
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// CONSTRUCTOR // CONSTRUCTOR
@ -20,7 +20,7 @@ node::node(node_type t) {
_parent = 0; _parent = 0;
_post_order_index = INT_MAX; _post_order_index = INT_MAX;
_node_id = INT_MAX; _node_id = INT_MAX;
_mark = 0; _mark = UNMARKED;
} }
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
@ -57,7 +57,7 @@ node* node::adj(int i) {return _adj_list[i];}
void node::set_adj_list(vector<node*> vec) {_adj_list = vec;} void node::set_adj_list(vector<node*> vec) {_adj_list = vec;}
void node::DFS_visit(vector<node*> &dfsList, int &index) { void node::DFS_visit(vector<node*> &dfsList, int &index) {
mark(); mark(); // set _mark to _ref_mark
for (int i = 0; i < _adj_list.size(); ++i) { for (int i = 0; i < _adj_list.size(); ++i) {
if (!_adj_list[i]->is_marked()) { if (!_adj_list[i]->is_marked()) {
_adj_list[i]->_parent = this; _adj_list[i]->_parent = this;
@ -358,12 +358,8 @@ void node::add_essential(node* u) {_essential_list.push_back(u);}
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// MARK // MARK
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
void node::mark() {_mark = _ref_mark;} void node::mark() {_mark = MARKED;}
void node::init_mark() {++_ref_mark;} void node::un_mark() {_mark = UNMARKED;}
void node::un_mark() {_mark = 0;} bool node::is_marked() {return _mark == MARKED;}
bool node::is_marked() {return _mark == _ref_mark;}
int node::_ref_mark = 1;