Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/dictionaries/hamlet.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/igraph2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class IGraph
#rescue RuntimeError
#end

hoe = Hoe.new("igraph",IGraph::VERSION) do |p|
hoe = Hoe.spec("igraph") do |p|

p.author = "Alex Gutteridge"
p.email = "ag357@cam.ac.uk"
p.url = "http://igraph.rubyforge.org/"

p.description = p.paragraphs_of("README.txt",1..3)[0]
p.summary = p.paragraphs_of("README.txt",1)[0]
p.changes = p.paragraphs_of("History.txt",0..1).join("\n\n")

p.clean_globs = ["ext/*.o","ext/*.so","ext/Makefile","ext/mkmf.log","**/*~","email.txt","manual.{aux,log,out,toc,pdf}"]
p.rdoc_pattern = /(^ext\/.*\.c$|^README|^History|^License)/

#p.rdoc_pattern = /(^ext\/.*\.c$|^README|^History|^License)/

p.spec_extras = {
:extensions => ['ext/extconf.rb'],
:require_paths => ['test'],
Expand Down
4 changes: 3 additions & 1 deletion ext/cIGraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ void Init_igraph(){
rb_define_method(cIGraph_shortestpaths, "girth", cIGraph_girth, 0); /* in cIGraph_shortest_paths.c */

rb_define_method(cIGraph_shortestpaths, "dijkstra_shortest_paths", cIGraph_dijkstra_shortest_paths, 3); /* in cIGraph_dijkstra.c */
rb_define_method(cIGraph_shortestpaths, "get_dijkstra_shortest_paths", cIGraph_get_dijkstra_shortest_paths, 4); /* in cIGraph_dijkstra.c */

/* Functions for querying the neighborhood of vertices */
cIGraph_neighborhoodm = rb_define_module_under(cIGraph, "Neighborhood");
Expand Down Expand Up @@ -554,7 +555,8 @@ void Init_igraph(){
rb_define_method(cIGraph_community, "community_leading_eigenvector_step", cIGraph_community_leading_eigenvector_step, 2); /* in cIGraph_community.c */ rb_define_method(cIGraph_community, "community_walktrap", cIGraph_community_walktrap, 2); /* in cIGraph_community.c */
rb_define_method(cIGraph_community, "community_edge_betweenness", cIGraph_community_edge_betweenness, 1); /* in cIGraph_community.c */
rb_define_method(cIGraph_community, "community_eb_get_merges", cIGraph_community_eb_get_merges, 1); /* in cIGraph_community.c */
rb_define_method(cIGraph_community, "community_fastgreedy", cIGraph_community_fastgreedy, 0); /* in cIGraph_community.c */
rb_define_method(cIGraph_community, "community_fastgreedy", cIGraph_community_fastgreedy, 1); /* in cIGraph_community.c */
rb_define_method(cIGraph_community, "community_label_propagation", cIGraph_community_label_propagation, 1); /* in cIGraph_community.c */

rb_define_const(cIGraph, "VERSION", rb_str_new2("0.9.1"));

Expand Down
4 changes: 3 additions & 1 deletion ext/cIGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ VALUE cIGraph_diameter (VALUE self, VALUE directed, VALUE unconn);
VALUE cIGraph_girth (VALUE self);

VALUE cIGraph_dijkstra_shortest_paths(VALUE self, VALUE from, VALUE weights, VALUE mode);
VALUE cIGraph_get_dijkstra_shortest_paths(VALUE self, VALUE from, VALUE to, VALUE weights, VALUE mode);
int igraph_dijkstra_shortest_paths(const igraph_t *graph,
igraph_matrix_t *res,
const igraph_vs_t from,
Expand Down Expand Up @@ -313,7 +314,8 @@ VALUE cIGraph_community_edge_betweenness (VALUE self,
VALUE directed);
VALUE cIGraph_community_eb_get_merges (VALUE self,
VALUE edges);
VALUE cIGraph_community_fastgreedy (VALUE self);
VALUE cIGraph_community_fastgreedy (VALUE self,VALUE weights);
VALUE cIGraph_community_label_propagation (VALUE self,VALUE weights);

//Attributes
int cIGraph_attribute_init(igraph_t *graph,
Expand Down
107 changes: 100 additions & 7 deletions ext/cIGraph_community.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ VALUE cIGraph_modularity(VALUE self, VALUE groups){
}

/* call-seq:
* graph.community_to_membership(merge,steps) -> Array
* graph.community_to_membership(merge,steps,nodes) -> Array
*
* Create membership vector from community structure dendrogram This function
* creates a membership vector from a community structure dendrogram.
Expand Down Expand Up @@ -458,10 +458,10 @@ igraph_arpack_options_init(&arpack_opt);
*
*/


VALUE cIGraph_community_walktrap(VALUE self, VALUE weights, VALUE steps){

igraph_t *graph;

igraph_vector_t weights_vec;
igraph_vector_t modularity;
igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t));
Expand All @@ -473,8 +473,8 @@ VALUE cIGraph_community_walktrap(VALUE self, VALUE weights, VALUE steps){
Data_Get_Struct(self, igraph_t, graph);

igraph_matrix_init(merges,0,0);
igraph_vector_init(&weights_vec,0);
igraph_vector_init(&modularity,0);
igraph_vector_init(&weights_vec,RARRAY_LEN(weights));

for(i=0;i<RARRAY_LEN(weights);i++){
VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
Expand Down Expand Up @@ -615,7 +615,7 @@ VALUE cIGraph_community_eb_get_merges(VALUE self, VALUE edges){
}

/* call-seq:
* graph.community_fastgreedy() -> Array
* graph.community_fastgreedy(weights) -> Array
*
* Finding community structure by greedy optimization of modularity.
* This function implements the fast greedy modularity optimization algorithm
Expand All @@ -625,10 +625,10 @@ VALUE cIGraph_community_eb_get_merges(VALUE self, VALUE edges){
*
*/

VALUE cIGraph_community_fastgreedy(VALUE self){
VALUE cIGraph_community_fastgreedy(VALUE self, VALUE weights){

igraph_t *graph;

igraph_vector_t weights_vec;
igraph_vector_t modularity;
igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t));

Expand All @@ -640,8 +640,13 @@ VALUE cIGraph_community_fastgreedy(VALUE self){

igraph_matrix_init(merges,0,0);
igraph_vector_init(&modularity,0);
igraph_vector_init(&weights_vec,RARRAY_LEN(weights));

igraph_community_fastgreedy(graph,NULL,
for(i=0;i<RARRAY_LEN(weights);i++){
VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
}

igraph_community_fastgreedy(graph,igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL,
merges,&modularity);

modularity_a = rb_ary_new();
Expand All @@ -655,7 +660,95 @@ VALUE cIGraph_community_fastgreedy(VALUE self){
modularity_a);

igraph_vector_destroy(&modularity);
igraph_vector_destroy(&weights_vec);

return res;

}

/* call-seq:
* graph.community_label_propagation(weights) -> Array
*
Community detection based on label propagation This function implements the community detection method described in:
Raghavan, U.N. and Albert, R. and Kumara, S.: Near linear time algorithm to detect community structures in large-scale
networks. Phys Rev E 76, 036106. (2007). This version extends the original method by the ability to take edge weights
into consideration and also by allowing some labels to be fixed.

Arguments:

weights:

The weight vector, it should contain a positive weight for all the edges
*
*/

VALUE cIGraph_community_label_propagation(VALUE self, VALUE weights){

igraph_t *graph;

igraph_vector_t membership;
igraph_vector_t weights_vec;
igraph_matrix_t *merges = malloc(sizeof(igraph_matrix_t));

igraph_arpack_options_t arpack_opt;
igraph_arpack_options_init(&arpack_opt);


int i,groupid,max_groupid;

VALUE groups, group, res;

Data_Get_Struct(self, igraph_t, graph);

igraph_matrix_init(merges,0,0);
igraph_vector_init(&membership,0);
igraph_vector_init(&weights_vec,RARRAY_LEN(weights));


for(i=0;i<RARRAY_LEN(weights);i++){
VECTOR(weights_vec)[i] = NUM2DBL(RARRAY_PTR(weights)[i]);
}


igraph_community_label_propagation(graph,
&membership,
igraph_vector_size(&weights_vec) > 0 ? &weights_vec : NULL,
NULL,
NULL);


max_groupid = 0;
for(i=0;i<igraph_vector_size(&membership);i++){
if(VECTOR(membership)[i] > max_groupid)
max_groupid = VECTOR(membership)[i];
}

groups = rb_ary_new();
for(i=0;i<max_groupid+1;i++){
rb_ary_push(groups,rb_ary_new());
}

for(i=0;i<igraph_vector_size(&membership);i++){

groupid = VECTOR(membership)[i];

if(groupid == -1)
groupid = 0;

group = RARRAY_PTR(groups)[groupid];
rb_ary_push(group,cIGraph_get_vertex_object(self, i));
}

res = rb_ary_new3(2,groups,
Data_Wrap_Struct(cIGraphMatrix, 0,
cIGraph_matrix_free, merges));

igraph_vector_destroy(&membership);
igraph_vector_destroy(&weights_vec);

return res;

}



Loading