From bb3a8562fbb72c5266ce3d05321bdf1e8ad073c0 Mon Sep 17 00:00:00 2001 From: p-hamann <p.hamann@dareit.de> Date: Tue, 23 Apr 2019 16:25:08 +0200 Subject: [PATCH] Extend partition to requirements of bnb --- bnb/partition.cpp | 24 ++++++++++++++---------- include/gp-bnb/partition.hpp | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bnb/partition.cpp b/bnb/partition.cpp index 2041bdf..60d402c 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 bea434a..1b20a55 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 -- GitLab