diff --git a/bnb/graph.cpp b/bnb/graph.cpp index c9fe03729b8d9f16660b030b10e18caf09be4cc2..314bbdb2c4cb96e0d62a7d636778121ef04a7e41 100644 --- a/bnb/graph.cpp +++ b/bnb/graph.cpp @@ -1,12 +1,12 @@ #include <gp-bnb/graph.hpp> -graph::graph(std::vector<std::vector<unsigned int>> a) : vertices(a.size()), adjacency_list(a) { +graph::graph(std::vector<std::vector<unsigned int>> a) : vertices_(a.size()), adjacency_list_(a) { } unsigned int graph::num_vertices() const { - return vertices; + return vertices_; } std::vector<unsigned int> graph::get_adjacency(vertex_id v) const { - return adjacency_list[v-1]; + return adjacency_list_[v-1]; } diff --git a/bnb/partition.cpp b/bnb/partition.cpp index 0e5791113aee7bea37914cb4abe167fe9ad6ba3a..30547ca81ed8d089973163b632b278849eb4ea7f 100644 --- a/bnb/partition.cpp +++ b/bnb/partition.cpp @@ -1,51 +1,51 @@ #include <gp-bnb/partition.hpp> -partition::partition(graph* g) : supergraph(g), outgoing_edges(0) { +partition::partition(graph* g) : supergraph_(g) { // Assigns all vertices to none for (unsigned int i = 0; i < g->num_vertices(); i++) { - vertex_assignments[i] = none; + vertex_assignments_[i] = none; } // Initializes vertex counting map - vertices[sg_a] = 0; - vertices[sg_b] = 0; - vertices[none] = g->num_vertices(); + vertices_[sg_a] = 0; + vertices_[sg_b] = 0; + vertices_[none] = g->num_vertices(); } unsigned int partition::num_vertices(subgraph sg) { - return vertices[sg]; + return vertices_[sg]; } void partition::assign_vertex(vertex_id v, subgraph sg) { // Returns if v is already assigned to a subgraph - if (vertex_assignments[v-1] != none) { + if (vertex_assignments_[v-1] != none) { return; } - // Increments outgoing edges - for (auto const& target : supergraph->get_adjacency(v)) { - if (vertex_assignments[target-1] == -sg) { - outgoing_edges++; + // Increments current objectives + for (auto const& target : supergraph_->get_adjacency(v)) { + if (vertex_assignments_[target-1] == -sg) { + current_objective_++; } } // Assigns vertex to subgraph - vertex_assignments[v-1] = sg; - vertices[sg]++; - vertices[none]--; + vertex_assignments_[v-1] = sg; + vertices_[sg]++; + vertices_[none]--; } void partition::unassign_vertex(vertex_id v) { - subgraph sg = vertex_assignments[v-1]; + subgraph sg = vertex_assignments_[v-1]; // Returns if v is not assigned to a subgraph if (sg == none) { return; } - // Decrements outgoing edges - for (auto const& target : supergraph->get_adjacency(v)) { - if (vertex_assignments[target-1] == -sg) { - outgoing_edges--; + // Decrements current objectives + for (auto const& target : supergraph_->get_adjacency(v)) { + if (vertex_assignments_[target-1] == -sg) { + current_objective_--; } } // Reverts assignment to subgraph - vertex_assignments[v-1] = none; - vertices[sg]--; - vertices[none]++; + vertex_assignments_[v-1] = none; + vertices_[sg]--; + vertices_[none]++; } diff --git a/include/gp-bnb/graph.hpp b/include/gp-bnb/graph.hpp index df0fdc47b128f57d1061ef7cc56afc6c60e794f1..d4eb1ff8a6e226159cd6c09dd126e3ef546b0cc6 100644 --- a/include/gp-bnb/graph.hpp +++ b/include/gp-bnb/graph.hpp @@ -23,8 +23,8 @@ public: std::vector<unsigned int> get_adjacency(vertex_id v) const; private: - unsigned int vertices; - std::vector<std::vector<unsigned int>> adjacency_list; + unsigned int vertices_; + std::vector<std::vector<unsigned int>> adjacency_list_; }; #endif diff --git a/include/gp-bnb/partition.hpp b/include/gp-bnb/partition.hpp index 793b9079ef460d30f7894d302ee067f70e2380da..ec9ef730b3260e8dc96a452353e3c0ebdab774a5 100644 --- a/include/gp-bnb/partition.hpp +++ b/include/gp-bnb/partition.hpp @@ -31,10 +31,10 @@ public: void unassign_vertex(vertex_id v); private: - graph* supergraph; - std::vector<subgraph> vertex_assignments; - std::map<subgraph,unsigned int> vertices; - unsigned int outgoing_edges; + graph* supergraph_; + std::vector<subgraph> vertex_assignments_; + std::map<subgraph,unsigned int> vertices_; + unsigned int current_objective_ = 0; }; #endif