Skip to content

Commit

Permalink
Merge pull request jlothian#24 from spowers/master
Browse files Browse the repository at this point in the history
expansion; doubles; graph stats
  • Loading branch information
jlothian committed Jun 14, 2013
2 parents b079c45 + 5fa77e0 commit 531a201
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 14 deletions.
7 changes: 6 additions & 1 deletion lib_graphd/inc/GraphProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ namespace Graph {
/**
* \brief returns frequency distributions of eccentricities
*/
void eccentricity_dist(Graph *g, vector<int> &ecc, vector<float> &freq_ecc);
void eccentricity_dist(Graph *g, vector<int> &ecc, vector<double> &freq_ecc);

/**
* \brief returns normalized expansion (distance distribution)
*/
void expansion(Graph *g, vector<double> &norm_hops);

/**
* \brief Calculates the diameter of the specified graph
Expand Down
30 changes: 29 additions & 1 deletion lib_graphd/src/GraphProperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ namespace Graph {
* \param[in] ecc vector of eccentricities (empty or pre-computed)
* \param[out] freq_ecc vector of eccentricity frequencies
*/
void GraphProperties::eccentricity_dist(Graph *g, vector<int> &ecc, vector<float> &freq_ecc){
void GraphProperties::eccentricity_dist(Graph *g, vector<int> &ecc, vector<double> &freq_ecc){
const int n = g->get_num_nodes();
int bestAll = 0;

Expand All @@ -768,6 +768,34 @@ namespace Graph {
}
} //eccentricity_dist

/**
* Calcuates the expansion (hop-distance) from each vertex: [see Tangmunarunkit (2002)]
* compute #nodes reachable in h hops starting at each vertex, average, normalize
* \param[in] g input graph
* \param[out] norm_hops normalized distribution
*/
void GraphProperties::expansion(Graph *g, vector<double> &norm_hops){
const int n = g->get_num_nodes();
vector< vector<int> > short_paths = g->get_shortest_path_dist_ref(); //computes if not already
vector <int> hops(n,0); //largest possible dist is n-1
norm_hops.resize(n);

//for each vertex, find the number of vertices reachable for all hops; add to tally
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
hops[ short_paths[i][j] ]++;
}
}

//average (divide by n) and normalize (divide by n-1)
norm_hops[0] = 0.0; //no one is reachable in 0 hops (not counting self)

for(int h = 1; h < n; h++){
norm_hops[h] = (double)hops[h] / (n * (n - 1));
//printf("h = %d and number is %d; norm value is %f\n",h,hops[h],norm_hops[h]);
}
} //expansion

/**
* Calculates the diameter of graph g
* \param[in] g Pointer to a graph
Expand Down
11 changes: 9 additions & 2 deletions util/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ ECC_SRCS = ./src/v_eccentricity.cpp
ECC_OBJ = $(ECC_SRCS:.cpp=.o)
ECC_EXE = $(INDDGO_BIN)/v_eccentricity

all: $(PKT_EXE) $(TD_STATS_EXE) $(E2D_EXE) $(E2A_EXE) $(M2D_EXE) $(G_STATS_EXE) $(TRI_EXE) $(SRT_EXE) $(ECC_EXE)
EXP_SRCS = ./src/expansion.cpp
EXP_OBJ = $(EXP_SRCS:.cpp=.o)
EXP_EXE = $(INDDGO_BIN)/expansion

all: $(PKT_EXE) $(TD_STATS_EXE) $(E2D_EXE) $(E2A_EXE) $(M2D_EXE) $(G_STATS_EXE) $(TRI_EXE) $(SRT_EXE) $(ECC_EXE) $(EXP_EXE)

.cpp.o:
$(CXX) $(CPPFLAGS) $(CFLAGS) -c $(INC_DIR) $< -o $@
Expand Down Expand Up @@ -74,8 +78,11 @@ $(SRT_EXE): $(SRT_OBJ) ../lib/libgraphd.a
$(ECC_EXE): $(ECC_OBJ) ../lib/libgraphd.a
$(CXX) $(CPPFLAGS) $(CFLAGS) $^ $(INC_DIR) $(LIBS) $(LDFLAGS) -o $@

$(EXP_EXE): $(EXP_OBJ) ../lib/libgraphd.a
$(CXX) $(CPPFLAGS) $(CFLAGS) $^ $(INC_DIR) $(LIBS) $(LDFLAGS) -o $@

clean:
-rm -rf $(PKT_OBJ) $(PKT_EXE) $(TD_STATS_OBJ) $(TD_STATS_EXE) $(E2D_OBJ) $(E2D_EXE) $(M2D_EXE) $(M2D_OBJ) $(G_STATS_EXE) $(G_STATS_OBJ) $(TRI_OBJ) $(TRI_EXE) $(SRT_OBJ) $(SRT_EXE) $(ECC_OBJ) $(ECC_EXE) $(E2A_EXE) $(E2A_OBJ)
-rm -rf $(PKT_OBJ) $(PKT_EXE) $(TD_STATS_OBJ) $(TD_STATS_EXE) $(E2D_OBJ) $(E2D_EXE) $(M2D_EXE) $(M2D_OBJ) $(G_STATS_EXE) $(G_STATS_OBJ) $(TRI_OBJ) $(TRI_EXE) $(SRT_OBJ) $(SRT_EXE) $(ECC_OBJ) $(ECC_EXE) $(EXP_OBJ) $(EXP_EXE) $(E2A_EXE) $(E2A_OBJ)

doc: $(DOXYFILE)
doxygen $(DOXYFILE)
Expand Down
69 changes: 69 additions & 0 deletions util/src/expansion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
This file is part of INDDGO.
Copyright (C) 2012, Oak Ridge National Laboratory
This product includes software produced by UT-Battelle, LLC under Contract No.
DE-AC05-00OR22725 with the Department of Energy.
This program is free software; you can redistribute it and/or modify
it under the terms of the New BSD 3-clause software license (LICENSE).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
LICENSE for more details.
For more information please contact the INDDGO developers at:
[email protected]
*/

#include "GraphReader.h"
#include "GraphProperties.h"
#include <ctime>

using namespace std;

void usage(const char *s){
fprintf(stderr, "Usage: %s filename\n", s);
}

int main(int argc, char **argv){
//usage check
if((argc == 1) ||
((argc == 2) && (strcmp(argv[1],"-h") == 0)) ||
((argc == 2) && (strcmp(argv[1], "--help") == 0))){
usage(argv[0]);
exit(-1);
}

Graph::Graph *g;

clock_t begin, end;

Graph::GraphProperties prop;
Graph::GraphReader ngr;

//create the graph object
g = new Graph::Graph();

//read the graph from the filename, assume it is an edgelist
ngr.read_graph(g, argv[1], "Edge", false);
//ngr.read_graph(g, argv[1], "ADJLIST", false);
printf("Read %d vertices and %d edges\n", g->get_num_nodes(), g->get_num_edges());

printf("Simplifying graph\n");
begin = clock();
prop.make_simple(g); //remove self loops and duplicate edges
end = clock();
printf("Time: %f\n", double(end - begin) / CLOCKS_PER_SEC);

//compute normalized expansion
begin = clock();
vector<double> norm_hops;
prop.expansion(g, norm_hops);
end = clock();
printf("Alg Time (expansion): %f\n", double(end - begin) / CLOCKS_PER_SEC);
} // main

12 changes: 6 additions & 6 deletions util/src/gen_pkt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int main(int argc, char **argv){
ktree_p = atoi(argv[i + 1]);
}
if(strcmp(argv[i],"-o") == 0){
out_format = string(argv[i+1]);
out_format = string(argv[i + 1]);
}
if(strcmp(argv[i],"-s") == 0){
seed = atoi(argv[i + 1]);
Expand All @@ -106,23 +106,23 @@ int main(int argc, char **argv){
prefix = argv[i + 1];
}
if(strcmp(argv[i],"-fe") == 0){
prefix = argv[i+1];
prefix = argv[i + 1];
exact_filename = true;
}
if(strcmp(argv[i],"-m") ==0){
if(strcmp(argv[i],"-m") == 0){
timings = true;
}
if(strcmp(argv[i],"-r") == 0){
random = true;
}
}

if(true == exact_filename && t != 1 ){
if((true == exact_filename) && (t != 1)){
cerr << "Error: cannot specify both -t and -fe flags\n";
exit(1);
}

if("adjlist" != out_format && "dimacs" != out_format){
if(("adjlist" != out_format) && ("dimacs" != out_format)){
cerr << "Error: only allowed output formats are: adjlist, dimacs\n";
exit(1);
}
Expand Down Expand Up @@ -170,7 +170,7 @@ int main(int argc, char **argv){
//write it to a file
if(!exact_filename){
sprintf(filename, "%s.%d.%d.%d_%d.dimacs", prefix, ktree_n,ktree_k,ktree_p, i);
}
}
else {
strncpy(filename,prefix, 99);
}
Expand Down
21 changes: 18 additions & 3 deletions util/src/graph_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void print_time(string prefix, ORB_t start, ORB_t end){
cout << prefix + ": " << ORB_seconds(end, start) << "\n";
}

const string allowed_methods ("edge_density,avg_degree,degree_dist,global_cc,avg_cc,local_ccs,shortest_paths,assortativity");
const string allowed_methods ("edge_density,avg_degree,degree_dist,global_cc,avg_cc,local_ccs,shortest_paths,assortativity,eccentricity,eccentricity_dist");

/**
* Creates a map from a comma-separated string
Expand Down Expand Up @@ -139,9 +139,9 @@ int main(int argc, char **argv){
print_time("Time(read_graph)", t1, t2);

double global_cc, avg_cc, assortativity;
vector<double> local_cc;
vector<double> local_cc, freq_ecc;
float edge_density, avg_degree;
vector<int> deg_dist;
vector<int> deg_dist, ecc;
vector< vector<int> > shortest_path_distances;

outfile.open(outfilename.c_str());
Expand Down Expand Up @@ -218,6 +218,21 @@ int main(int argc, char **argv){
ORB_read(t2);
print_time("Time(shortest_paths_dijkstra)", t1, t2);
}
if(req_methods["eccentricity"] == true){
cout << "Calculating eccentricities\n";
ORB_read(t1);
gp.eccentricity(&g, ecc);
ORB_read(t2);
print_time("Time(eccentricity)",t1,t2);
}
if(req_methods["eccentricity_dist"] == true){
cout << "Calculating distribution of eccentricities\n";
ORB_read(t1);
gp.eccentricity_dist(&g, ecc, freq_ecc);
ORB_read(t2);
print_time("Time(eccentricity distribution)",t1,t2);
}

outfile.close();
exit(0);
} // main
Expand Down
2 changes: 1 addition & 1 deletion util/src/v_eccentricity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, char **argv){

//compute eccentricity distribution
begin = clock();
vector<float> ecc_dist;
vector<double> ecc_dist;
prop.eccentricity_dist(g,ecc, ecc_dist);
end = clock();
printf("Alg Time (freq dist eccentricity): %f\n", double(end - begin) / CLOCKS_PER_SEC);
Expand Down

0 comments on commit 531a201

Please sign in to comment.