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

Update member identifiers

parent 4dacbf1e
No related merge requests found
#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];
}
#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]++;
}
......@@ -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
......@@ -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
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