Skip to content

Commit

Permalink
Implement biconnected statistics file output
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm2468 committed Jul 7, 2022
1 parent b088e45 commit 6c16a90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions biconnected.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "biconnected.h"

#include <stack>
#include <fstream>

namespace snu {
std::string BiconnectedComponents::statName() {
Expand Down Expand Up @@ -36,6 +37,7 @@ bool BiconnectedComponents::calculateUndirectedStat(USGraph &graph, bool verify)
max_conn_bcc = 0;
for (auto &pair : graph.id_to_vertex) {
long long cbcc = getMetadata(pair.second)->num_connected_bcc;
connected_bcc[pair.first] = cbcc;
if (cbcc > 1) {
num_arp++;
if (cbcc > max_conn_bcc) {
Expand Down Expand Up @@ -71,6 +73,14 @@ void BiconnectedComponents::writeToHTMLStat(FILE *fp, bool directed) {
num_arp, num_bcc, size_lbcc, max_conn_bcc);
}

bool BiconnectedComponents::writeToFileStat(std::string graph_name, bool directed) {
std::ofstream fout(graph_name + "_Biconnected.txt");
for (auto [nodeId, val] : connected_bcc) {
fout << nodeId << ' ' << val << '\n';
}
return true;
}

// This is the algorithm presented by Hopcroft and Tarjan (1973).
// It has been modified to avoid recursion (to prevent stack overflows)
void BiconnectedComponents::countBcc(USGraph &graph) {
Expand Down
4 changes: 4 additions & 0 deletions biconnected.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BICONNECTED_H
#define BICONNECTED_H

#include <map>
#include "graph.h"
#include "stat.h"

Expand All @@ -12,6 +13,7 @@ class BiconnectedComponents : public UndirectedStat {
protected:
virtual bool calculateUndirectedStat(USGraph &graph, bool verify) override;
virtual void writeToHTMLStat(FILE *fp, bool directed) override;
virtual bool writeToFileStat(std::string graph_name, bool directed) override;

private:
void countBcc(USGraph &graph);
Expand All @@ -22,6 +24,8 @@ class BiconnectedComponents : public UndirectedStat {
long long num_bcc; // number of biconnected components
long long max_conn_bcc; // maximum number of bcc's connected to a single arp
long long size_lbcc; // largest size of biconnected components

std::map<Graph::Vid, long long> connected_bcc;
};
} // namespace snu

Expand Down

0 comments on commit 6c16a90

Please sign in to comment.