Skip to content

Commit

Permalink
Merge pull request #41 from bdsullivan/testing
Browse files Browse the repository at this point in the history
Merging new feature calculations and improvements from graph-survey
  • Loading branch information
bdsullivan committed Sep 27, 2013
2 parents 18bf5c9 + 5188957 commit 4bf6618
Show file tree
Hide file tree
Showing 33 changed files with 2,370 additions and 610 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ will be identified through a message to standard out.
(sample graphviz command: neato -Tpdf -o tree.pdf tree.dot).
* ./bin/td_viz -f ./sample_graphs/1dc.64.dimacs -t ./sample_graphs/1dc.64.tree -e

###Calculate graph statistics
Generates a set of output files containing the results of your selection of a broad spectrum of graph statistics (run with -h to see all options) when
calculated on the specified input graph. The single value statistics are stored in sample_graphs/pkt-stats.stats, and that file lists where to find any features that create a vector (or more) of data. Note that without BOOST, distance-based features may not be available.
* ./bin/graph_stats -i ./sample_graphs/1dc.64.dimacs -t dimacs -p ./sample_graphs/pkt-stats -m edge_density,degree_dist,global_cc,avg_cc,assortativity,eccentricity,expansion,avg_shortest_path -r

More information on the output formats for the weighted independent set executables is in the README in max_wis.

##Getting Help
Expand Down
55 changes: 53 additions & 2 deletions lib_graphd/inc/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,46 @@
#ifndef HAS_METIS
#define omp_get_num_threads() 1
#define omp_get_thread_num() 0
#define omp_get_max_threads() 1
#endif
#endif

#ifdef HAS_PETSC
#include <petscksp.h>
#endif

#if WIN32
#define strncasecmp strncmp
#endif

#include "GraphInterface.h"
#include "Node.h"
#include "GraphException.h"
#include "Log.h"
#include <string>

#ifdef HAS_BOOST
#include <iostream>
#include <deque>
#include <iterator>

#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/topological_sort.hpp"
#include <boost/graph/dijkstra_shortest_paths.hpp>
#endif

using namespace std;

#define INDDGO_INFINITY INT_MAX - 16

#ifdef HAS_BOOST
typedef boost::property<boost::edge_weight_t, int> EdgeWeightProperty;
typedef boost::property <boost::vertex_centrality_t, double > CentralityMap;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, CentralityMap, EdgeWeightProperty> BoostUndirected;
typedef boost::graph_traits < BoostUndirected >::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits < BoostUndirected >::edge_descriptor edge_descriptor;
#endif //HAS_BOOST

namespace Graph {
class Graph : public GraphInterface
{
Expand All @@ -69,7 +96,17 @@ namespace Graph {
vector<int> xadj;
vector<int> adjncy;
vector<int> adj_vec;
vector< vector<int> > apsp_dist;
vector< vector<int> > *apsp_dist;

// Currently this is only calculated if you have Boost.
vector<double> betweenness;
#ifdef HAS_BOOST
BoostUndirected *boost_graph;
#endif //HAS_BOOST

#ifdef HAS_PETSC
Mat PetscMat;
#endif

public:
Graph();
Expand All @@ -95,7 +132,9 @@ namespace Graph {
/** \brief Try to pre-allocate memory for node and degree vectors **/
void resize(int n);
/** \brief set shortest path distances **/
void set_shortest_path_dist(vector< vector<int> > apsp_dist);
void set_shortest_path_dist(vector< vector<int> > *apsp_dist);
/** \brief set betweenness centrality vector **/
void set_betweenness(vector<double> bc);

vector<int> get_adj_vec() const;
vector<int> *get_adj_vec_ptr();
Expand All @@ -113,8 +152,12 @@ namespace Graph {
int get_num_edges() const;
int get_num_edges_in_subgraph(list<int> *vertices);
int get_num_nodes() const;
int get_num_connected_components() const;
vector<int> get_xadj() const;

/** \brief get a const ref to the betweenness vector **/
const vector<double> &get_betweenness_ref();

virtual bool is_edge(int i, int j) const;
bool is_canonical() const;
bool is_simple() const;
Expand Down Expand Up @@ -152,6 +195,14 @@ namespace Graph {
/** \brief get shortest path distances from vertex u to all **/
const vector<int> &get_u_shortest_path_dist(int u);

inline Node *get_node_inline(int i){
if(i > capacity){
FERROR("%s: element is out of bounds", __FUNCTION__);
throw GraphException("element is out of bounds\n");
}
return &nodes[i];
}

friend class GraphUtil;
friend class GraphProperties;
friend class GraphDisplay;
Expand Down
8 changes: 8 additions & 0 deletions lib_graphd/inc/GraphCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ namespace Graph {
// Specialized induced subgraph functionality for components. Sets num_connected_components to 1.
virtual VertexWeightedGraph *create_component(VertexWeightedGraph *g,
list<int> *members, bool make_simple);
/**
* \brief Create an induced subgraph on g
*/
virtual Graph *create_induced_subgraph(Graph *g, list<int> *members, bool make_simple);
/**
* \brief Create a component graph of g
*/
virtual Graph *create_component(Graph *g, list<int> *members, bool make_simple);

// Recursive and non-recursive functions that create all connected components of the graph,
// which it places in the given vector
Expand Down
6 changes: 6 additions & 0 deletions lib_graphd/inc/GraphCreatorFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
#ifndef GRAPHCREATORFILE_H_
#define GRAPHCREATORFILE_H_

#ifdef HAS_BOOST
#ifdef HAS_GTEST
#define GTEST_HAS_TR1_TUPLE 0
#endif
#endif

#include "GraphCreator.h"
#include "GraphReader.h"
#include <string>
Expand Down
15 changes: 14 additions & 1 deletion lib_graphd/inc/GraphDecomposition.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@
#include <list>
#include <vector>
#include <algorithm>

#ifdef HAS_BOOST
#ifdef HAS_GTEST
#define GTEST_HAS_TR1_TUPLE 0
#endif
#include <boost/math/special_functions/zeta.hpp>
#endif

#ifndef HAS_BOOST
#include <stdint.h>
#endif


#include <set>
#include <map>
#include <limits.h>
Expand Down Expand Up @@ -117,7 +130,7 @@ static const char EO_NAMES[][30] = {
// Include header files
#include "GraphDecomposition.h"
#include "Graph.h"
#include "Graph.h"
//#include "Graph.h"
#include "DIMACSGraphReader.h"
#include "DIMACSGraphWriter.h"
#include "GraphDisplay.h"
Expand Down
49 changes: 49 additions & 0 deletions lib_graphd/inc/GraphProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
#define GRAPHPROPERTIES_H_
#include "GraphDecomposition.h"

#ifdef HAS_BOOST
#ifdef HAS_GTEST
#define GTEST_HAS_TR1_TUPLE 0
#endif
#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/topological_sort.hpp"
#include "boost/graph/betweenness_centrality.hpp"
#endif

using namespace std;

namespace Graph {
Expand Down Expand Up @@ -72,6 +81,24 @@ namespace Graph {
*/
void paths_dijkstra_single(Graph *g, vector<int> &p, int source);

#ifdef HAS_BOOST
/**
* \brief returns shortest paths from source to all other nodes
*/
void paths_dijkstra_boost_single(Graph *g, vector<int> &dists, vector<vertex_descriptor> &preds, int source);

/**
* \brief returns shortest paths from all nodes to all nodes
*/
void paths_dijkstra_boost_all(Graph *g, vector< vector<int> > &p);

/**
* \brief calculations betweenness centrality for all vertices
*/
void betweenness_centrality(Graph *g, vector<double> &bc);

#endif

/**
* \brief returns shortest paths from all nodes to all nodes
*/
Expand Down Expand Up @@ -112,15 +139,37 @@ namespace Graph {
*/
void avg_degree(Graph *g, float &ad);

/**
* \brief Calculates the average shortest path length of the specified graph
*/
void avg_path_length(Graph *g, double &pl);

/**
* \brief Calculates the degree distribution of the specified graph
*/
void deg_dist(Graph *g, vector<int> &dist);

#ifdef HAS_BOOST
/**
* \brief Fits the degree distribution of the specified graph to a power law distribution
*/
void powerlaw(Graph *g, int &xmin, double &alpha, double &KS, double start = 1.5, double inc = 0.01, double end = 3.5);
#endif

/**
* \brief Returns the degree assortativity coefficient of a graph
*/
void deg_assortativity(Graph *g, double &coeff);

/**
* \brief Returns the delta hyperbolicity of a graph
*/
void delta_hyperbolicity(Graph *g, double &max_delta, vector<vector<double> > &delta);

/**
* \brief Calculates the eign spectrum. By default it does the top 5 and bottom 5.
*/
void eigen_spectrum(Graph *g, vector<double> &eigen_values, int spread = 5);
};
}

Expand Down
30 changes: 26 additions & 4 deletions lib_graphd/inc/GraphUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ namespace Graph {
void populate_CRS(Graph *g);
void free_CRS(Graph *g);

#ifdef HAS_BOOST
/**
* \brief Populate the boost version of the graph
*/
void populate_boost(Graph *g);
#endif

//uses V as a vertex separator of G. Returns the number of components in G\V, and fills in members with their vertex lists..
int vertex_separator(Graph *g, list<int> *V,
vector<list<int> *> *members);
Expand All @@ -83,13 +90,28 @@ namespace Graph {
//Find the eccentricity of each vertex and store it in ecc.
void find_ecc(Graph *g, vector<int> *ecc);

//Find the k-core number of each vertex and store it in kcore.
//Return degeneracy.
/**
* \brief Find the k-core number of each vertex and store it in kcore. Return degeneracy.
*/
int find_kcore(Graph *g, vector<int> *kcore);

//Calculate the maximum distance between nodes within a subset of vertices
//given as a list
/**
* \brief Calculate max distance between nodes in subset list
*/
int subset_max_dist(Graph *g, vector<int> subset);
/**
* \brief Populate adjacency matrix as a Petsc Matrix
*/
void populate_PetscMat(Graph *g);
/**
* \brief Releases PetscMat.
*/
void free_PetscMat(Graph *g);

/**
* \brief returns a new graph that is the largest component of g
*/
Graph *get_largest_component_graph(Graph *g);
};

void create_largestcomponent_graph(char *graph_file, VertexWeightedGraph *&G);
Expand Down
44 changes: 44 additions & 0 deletions lib_graphd/inc/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,51 @@ const char *eo_name(int eo_id);
std::string str_to_up(std::string s);
void split(const std::string& s, char sep, vector<int>& v); // used in metisgraph reader

/**
* \brief write a degree distribution out to a file
*/
void write_degree_distribution(string filename, const vector<int> &dist);

/**
* \brief write an eccentricity distribution out to a file
*/
void write_eccentricity_distribution(string filename, const vector<double> &dist);

/**
* \brief write a k_core list out to a file
*/
void write_kcores(string filename, const vector<int> &kcores);

/**
* \brief write an eccentricity list out to a file
*/
void write_eccentricity(string filename, const vector<int> &ecc);

/**
* \brief write a betweenness centrality list out to a file
*/
void write_betweenness(string filename, const vector<double> &bc);

/**
* \brief write a delta hyperbolicity distribution out to a file
*/
void write_delta_hyperbolicity(string filename, const vector< vector<double> > &delta);

/**
* \brief write an expansion list out to a file
*/
void write_expansion(string filename, const vector<double> &expansion);

/**
* \brief Write an all pairs shortest path matrix out to file.
*/
void write_apsp_matrix(string filename, vector< vector<int> > &apsp);

/**
* \brief Reads an all pairs shortest path matrix from file
*/
void read_apsp_matrix(string filename, vector< vector<int> > &apsp);

int_int mylog2(int x);

#endif /* UTIL_H_ */
Loading

0 comments on commit 4bf6618

Please sign in to comment.