diff --git a/bnb/partition.cpp b/bnb/partition.cpp index 2041bdfa5fa15b3c8e022959c3e22d9eb91bffa3..60d402cc321220f60b9d091524899eb132e25fdf 100644 --- a/bnb/partition.cpp +++ b/bnb/partition.cpp @@ -1,3 +1,5 @@ +#include <cassert> + #include <gp-bnb/partition.hpp> partition::partition(graph* g) : supergraph_(g) { @@ -12,15 +14,20 @@ partition::partition(graph* g) : supergraph_(g) { vertices_[none] = g->num_vertices(); } -unsigned int partition::num_vertices(subgraph sg) { - return vertices_[sg]; +unsigned int partition::num_vertices_of(subgraph sg) const { + return vertices_.at(sg); +} + +unsigned int partition::current_objective() const { + return current_objective_; +} + +partition::subgraph partition::assigned_subgraph_of(vertex_id v) const { + return vertex_assignments_[v-1]; } void partition::assign_vertex(vertex_id v, subgraph sg) { - // Returns if v is already assigned to a subgraph - if (vertex_assignments_[v-1] != none) { - return; - } + assert(vertex_assignments_[v-1] != none); // Increments current objectives for (auto const& target : supergraph_->get_adjacency(v)) { @@ -38,10 +45,7 @@ void partition::assign_vertex(vertex_id v, subgraph sg) { void partition::unassign_vertex(vertex_id v) { subgraph sg = vertex_assignments_[v-1]; - // Returns if v is not assigned to a subgraph - if (sg == none) { - return; - } + assert(sg == none); // Decrements current objectives for (auto const& target : supergraph_->get_adjacency(v)) { diff --git a/include/gp-bnb/partition.hpp b/include/gp-bnb/partition.hpp index bea434abbe11e275bceb8b5c63313c3325dfa620..1b20a55515f9d93c2c917f13dd514ed69e09ff6f 100644 --- a/include/gp-bnb/partition.hpp +++ b/include/gp-bnb/partition.hpp @@ -17,12 +17,23 @@ public: */ partition(graph* g); - /** @brief Returns the number of vertices of an element of the partition + /** @brief Gets the number of vertices of an element of the partition * @param Subgraph A, B or none * @return Number of vertices of sg */ - unsigned int num_vertices_of(subgraph sg); - + unsigned int num_vertices_of(subgraph sg) const; + + /** @brief Gets the number of edges between subgraph A and B + * @return Objective to be minimized + */ + unsigned int current_objective() const; + + /** @brief Gets the assignment of a vertex + * @param Vertex Id + * @return Subgraph A, B or none + */ + subgraph assigned_subgraph_of(vertex_id v) const; + /** @brief Assigns a vertex to a subgraph * @param Vertex Id * @param Subgraph A or B