diff --git a/.idea/dictionaries/hamlet.xml b/.idea/dictionaries/hamlet.xml
new file mode 100644
index 0000000..71ff7a5
--- /dev/null
+++ b/.idea/dictionaries/hamlet.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..e206d70
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/.idea/igraph2.iml b/.idea/igraph2.iml
new file mode 100644
index 0000000..af64c60
--- /dev/null
+++ b/.idea/igraph2.iml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..f26f657
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..35ce8ac
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..9d32e50
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/Rakefile.rb b/Rakefile.rb
index bd631b9..6ff562d 100644
--- a/Rakefile.rb
+++ b/Rakefile.rb
@@ -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'],
diff --git a/ext/cIGraph.c b/ext/cIGraph.c
index 695e7f6..43a869a 100644
--- a/ext/cIGraph.c
+++ b/ext/cIGraph.c
@@ -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");
@@ -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"));
diff --git a/ext/cIGraph.h b/ext/cIGraph.h
index 093fa47..7fd1302 100644
--- a/ext/cIGraph.h
+++ b/ext/cIGraph.h
@@ -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,
@@ -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,
diff --git a/ext/cIGraph_community.c b/ext/cIGraph_community.c
old mode 100644
new mode 100755
index 4ef183b..854ce6b
--- a/ext/cIGraph_community.c
+++ b/ext/cIGraph_community.c
@@ -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.
@@ -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));
@@ -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 Array
+ * graph.community_fastgreedy(weights) -> Array
*
* Finding community structure by greedy optimization of modularity.
* This function implements the fast greedy modularity optimization algorithm
@@ -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));
@@ -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 0 ? &weights_vec : NULL,
merges,&modularity);
modularity_a = rb_ary_new();
@@ -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 0 ? &weights_vec : NULL,
+ NULL,
+ NULL);
+
+
+ max_groupid = 0;
+ for(i=0;i max_groupid)
+ max_groupid = VECTOR(membership)[i];
+ }
+
+ groups = rb_ary_new();
+ for(i=0;i 0 ? &wghts : NULL,pmode);
for(i=0; i 0 ? &wghts : NULL,pmode);
+
+ for(i=0; i