From df2c6a608a5b238e7b2e5265e05e48535e036263 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 6 Jan 2017 16:55:23 -0500 Subject: Refactor - Remove unnecessary include - Improve whitespace - Remove unnecessary variable declaration - Move function call to more logical place --- src/brandes.cc | 7 ++++++- src/dependency_calculator.h | 2 +- src/graph.h | 1 + src/parse.h | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/brandes.cc b/src/brandes.cc index c4c14cd..2d81610 100644 --- a/src/brandes.cc +++ b/src/brandes.cc @@ -48,16 +48,20 @@ void init() { int next_vertex() { std::lock_guard lock(queue_mutex); + if (vertices_to_process.empty()) { return -1; } + int vertex = vertices_to_process.front(); vertices_to_process.pop(); + return vertex; } void update_betweenness(int vertex, DependencyCalculator& dc) { std::lock_guard lock(betweenness_mutex); + for (int v = 0; v < graph.get_number_vertices(); v++) { if (v != vertex ) { betweenness[v] += dc.get_dependency(v); @@ -90,7 +94,8 @@ void print_betweenness() { for (int vertex = 0; vertex < graph.get_number_vertices(); vertex++) { if (graph.has_out_edges(vertex)) { - fout << graph.get_real_vertex(vertex) << " " << betweenness[vertex] << std::endl; + fout << graph.get_real_vertex(vertex) << " " + << betweenness[vertex] << std::endl; } } } diff --git a/src/dependency_calculator.h b/src/dependency_calculator.h index c24f5ef..6141a82 100644 --- a/src/dependency_calculator.h +++ b/src/dependency_calculator.h @@ -3,7 +3,6 @@ #include #include -#include #include #include "graph.h" @@ -23,6 +22,7 @@ public: private: const Graph& graph_; // (V, E) int vertex_; // s + std::stack stack_; // S std::vector> shortest_path_predecessors_; // P std::vector shortest_paths_; // sigma diff --git a/src/graph.h b/src/graph.h index 85c66e7..7978c95 100644 --- a/src/graph.h +++ b/src/graph.h @@ -14,6 +14,7 @@ public: if (vertices_.find(vertex) == vertices_.end()) { vertices_.insert(vertex); orderable_vertices_.push_back(vertex); + graph_.push_back(std::vector()); has_out_edges_.push_back(false); number_vertices_++; diff --git a/src/parse.h b/src/parse.h index 095232a..2265618 100644 --- a/src/parse.h +++ b/src/parse.h @@ -10,10 +10,8 @@ class Parser { public: Parser(std::string filename) : graph_(), input_file_(filename) { - std::string edge; read_file_(); add_vertices_(); - graph_.done_with_vertices(); add_edges_(); } @@ -46,6 +44,8 @@ private: graph_.add_vertex(edge.first); graph_.add_vertex(edge.second); } + + graph_.done_with_vertices(); } void add_edges_() { -- cgit v1.2.3