Skip to content
Snippets Groups Projects
Commit bb3a8562 authored by p-hamann's avatar p-hamann
Browse files

Extend partition to requirements of bnb

parent 07f7cc63
No related merge requests found
#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)) {
......
......@@ -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
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment