This commit is contained in:
alexgutteridge 2007-08-16 08:17:59 +00:00
parent bf559ec3bb
commit 7077ece40b
7 changed files with 124 additions and 48 deletions

View File

@ -2,7 +2,7 @@
IGraph is a Ruby extension for interfacing with the C igraph library (http://cneurocvs.rmki.kfki.hu/igraph/). igraph is a library for creating and manipulating graphs with a particular emphasis on network analysis functions.
IGraph is currently in alpha status and although the basic graph creation and manipulation functions are implemented the API should be considered subject to change.
IGraph is currently in alpha status and although the basic graph creation and manipulation functions are implemented the API should be considered subject to change. The main documentation can be found at http://igraph.rubyforge.org/igraph/.
All bug reports, feature requests and patches are welcome. Please email alexg (at) kuicr.kyoto-u.ac.jp or use the rubyforge forums: http://rubyforge.org/forum/?group_id=3943

View File

@ -33,18 +33,6 @@ hoe = Hoe.new("igraph",IGraph::VERSION) do |p|
:rdoc_options => ["--exclude", "test/*", "--main", "README.txt", "--inline-source"]
}
task :setup_rb_package => [:clean, :package, :build_manual] do
package_dir = "#{p.name}-#{p.version}"
cp("setup.rb","pkg/#{package_dir}")
cp("manual.pdf","pkg/#{package_dir}")
Dir.chdir("pkg")
system("tar -czf #{p.name}-#{p.version}.tgz #{package_dir}")
Dir.chdir("..")
end
end
hoe.spec.dependencies.delete_if{|dep| dep.name == "hoe"}
@ -62,16 +50,3 @@ file 'ext/igraph.so' => SRC do
end
task :test => [:build_extension]
desc "Build PDF manual"
task :build_manual => ["manual.pdf"]
file "manual.pdf" => ["manual.tex"] do
out = 'Rerun'
while out.match(/Rerun/)
out = `pdflatex manual.tex`
end
end
task :build_manual_clean => [:build_manual] do
system("rm manual.{aux,log,out,toc}")
end

View File

@ -263,34 +263,34 @@ void Init_igraph(){
rb_define_singleton_method(cIGraph, "read_graph_edgelist", cIGraph_read_graph_edgelist, 2); /* in cIGraph_file.c */
rb_define_singleton_method(cIGraph, "read_graph_graphml", cIGraph_read_graph_graphml, 2); /* in cIGraph_file.c */
rb_define_singleton_method(cIGraph, "read_graph_pajek", cIGraph_read_graph_pajek, 2); /* in cIGraph_file.c */
rb_define_singleton_method(cIGraph, "read_graph_pajek", cIGraph_read_graph_pajek, 2); /* in cIGraph_file.c */
rb_define_method(cIGraph, "write_graph_edgelist", cIGraph_write_graph_edgelist, 1); /* in cIGraph_file.c */
rb_define_method(cIGraph, "write_graph_graphml", cIGraph_write_graph_graphml, 1); /* in cIGraph_file.c */
rb_define_method(cIGraph, "write_graph_pajek", cIGraph_write_graph_pajek, 1); /* in cIGraph_file.c */
rb_define_method(cIGraph, "write_graph_pajek", cIGraph_write_graph_pajek, 1); /* in cIGraph_file.c */
rb_define_method(cIGraph, "layout_random", cIGraph_layout_random, 0);
rb_define_method(cIGraph, "layout_circle", cIGraph_layout_circle, 0);
rb_define_method(cIGraph, "layout_fruchterman_reingold", cIGraph_layout_fruchterman_reingold, 6);
rb_define_method(cIGraph, "layout_random", cIGraph_layout_random, 0); /* in cIGraph_layout.c */
rb_define_method(cIGraph, "layout_circle", cIGraph_layout_circle, 0); /* in cIGraph_layout.c */
rb_define_method(cIGraph, "layout_fruchterman_reingold", cIGraph_layout_fruchterman_reingold, 6); /* in cIGraph_layout.c */
//Matrix class
cIGraphMatrix = rb_define_class("IGraphMatrix", rb_cObject);
rb_define_alloc_func(cIGraphMatrix, cIGraph_matrix_alloc);
rb_define_method(cIGraphMatrix, "initialize", cIGraph_matrix_initialize, -1);
rb_define_method(cIGraphMatrix, "initialize_copy", cIGraph_matrix_init_copy, 1);
rb_define_method(cIGraphMatrix, "initialize", cIGraph_matrix_initialize, -1); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "initialize_copy", cIGraph_matrix_init_copy, 1); /* in cIGraph_matrix.c */
//rb_define_singleton_method(cIGraphMatrix, "[]", cIGraph_matrix_initialize, -1);
rb_include_module(cIGraphMatrix, rb_mEnumerable);
rb_define_method (cIGraphMatrix, "each", cIGraph_matrix_each,0);
rb_define_method (cIGraphMatrix, "each", cIGraph_matrix_each,0); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "[]", cIGraph_matrix_get, 2);
rb_define_method(cIGraphMatrix, "[]=", cIGraph_matrix_set, 3);
rb_define_method(cIGraphMatrix, "size", cIGraph_matrix_size, 0);
rb_define_method(cIGraphMatrix, "nrow", cIGraph_matrix_nrow, 0);
rb_define_method(cIGraphMatrix, "ncol", cIGraph_matrix_ncol, 0);
rb_define_method(cIGraphMatrix, "max", cIGraph_matrix_max, 0);
rb_define_method(cIGraphMatrix, "[]", cIGraph_matrix_get, 2); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "[]=", cIGraph_matrix_set, 3); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "size", cIGraph_matrix_size, 0); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "nrow", cIGraph_matrix_nrow, 0); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "ncol", cIGraph_matrix_ncol, 0); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "max", cIGraph_matrix_max, 0); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "*", cIGraph_matrix_multiply, 1);
rb_define_method(cIGraphMatrix, "*", cIGraph_matrix_multiply, 1); /* in cIGraph_matrix.c */
rb_define_method(cIGraphMatrix, "to_a", cIGraph_matrix_toa, 0);
rb_define_method(cIGraphMatrix, "to_a", cIGraph_matrix_toa, 0); /* in cIGraph_matrix.c */
}

View File

@ -44,6 +44,13 @@ VALUE cIGraph_set_edge_attr(VALUE self, VALUE from, VALUE to, VALUE attr){
}
/* call-seq:
* graph.attributes -> Hash
*
* Returns the graph attributes. This is usually only used when reading in
* graphs from GraphML format. Feel free to use instance variables on the
* graph object if you like (they won't get copied though!).
*/
VALUE cIGraph_graph_attributes(VALUE self){
igraph_t *graph;

View File

@ -89,6 +89,19 @@ VALUE cIGraph_write_graph_edgelist(VALUE self, VALUE file){
}
/* call-seq:
* IGraph.read_graph_graphml(file,index) -> IGraph
*
* Reads a graph from a GraphML file specified as the File object file.
*
* GraphML is an XML-based file format for representing various types of
* graphs. Currently only the most basic import functionality is implemented
* in igraph: it can read GraphML files without nested graphs and hyperedges.
*
* If the GraphML file contains more than one graph, the one specified by
* this index will be loaded. Indices start from zero, so supply zero here
* if your GraphML file contains only a single graph.
*/
VALUE cIGraph_read_graph_graphml(VALUE self, VALUE file, VALUE index){
VALUE string;
@ -110,6 +123,16 @@ VALUE cIGraph_read_graph_graphml(VALUE self, VALUE file, VALUE index){
}
/* call-seq:
* graph.write_graph_graphml(file) -> Integer
*
* Writes the graph to a File in GraphML format
*
* GraphML is an XML-based file format for representing various types of
* graphs. See the GraphML Primer
* (http://graphml.graphdrawing.org/primer/graphml-primer.html) for detailed
* format description.
*/
VALUE cIGraph_write_graph_graphml(VALUE self, VALUE file){
char *buf;
@ -132,6 +155,15 @@ VALUE cIGraph_write_graph_graphml(VALUE self, VALUE file){
}
/* call-seq:
* IGraph.read_graph_pajek(file) -> IGraph
*
* Reads a file in Pajek format
*
* Only a subset of the Pajek format is implemented. This is partially
* because this format is not very well documented, but also because
* igraph does not support some Pajek features, like multigraphs.
*/
VALUE cIGraph_read_graph_pajek(VALUE self, VALUE file){
VALUE string;
@ -153,6 +185,11 @@ VALUE cIGraph_read_graph_pajek(VALUE self, VALUE file){
}
/* call-seq:
* graph.write_graph_pajek(file) -> Integer
*
* Writes a graph to a file in Pajek format.
*/
VALUE cIGraph_write_graph_pajek(VALUE self, VALUE file){
char *buf;

View File

@ -21,6 +21,11 @@ VALUE cIGraph_layout_random(VALUE self){
}
/* call-seq:
* graph.layout_random -> IGraphMatrix
*
* Returns a layout with nodes laid out around a circle.
*/
VALUE cIGraph_layout_circle(VALUE self){
igraph_t *graph;
@ -35,6 +40,16 @@ VALUE cIGraph_layout_circle(VALUE self){
}
/* call-seq:
* graph.layout_random -> IGraphMatrix
*
* Places the vertices on a plane according to the Fruchterman-Reingold
* algorithm.
*
* This is a force-directed layout, see Fruchterman, T.M.J. and Reingold,
* E.M.: Graph Drawing by Force-directed Placement. Software -- Practice and
* Experience, 21/11, 1129--1164, 1991.
*/
VALUE cIGraph_layout_fruchterman_reingold(VALUE self,
VALUE niter,
VALUE maxdelta,

View File

@ -48,14 +48,11 @@ VALUE cIGraph_matrix_init_copy(VALUE copy, VALUE orig){
}
/* call-seq:
* IGraphMatrix[[x,y,...],...] -> IGraphMatrix
* IGraphMatrix.new([[x,y,...],...]) -> IGraphMatrix
*
* IGraphMatrix[[1,2],[3,4]]
*
* Creates a graph with four vertices. Vertex 1 is connected to vertex 2.
* Vertex 3 is connected to vertex 4.
* Creates a new IGraphMatrix object. The argument should be an Array of
* Arrays which each contain the data for a row of the matrix.
*/
VALUE cIGraph_matrix_initialize(int argc, VALUE *argv, VALUE self){
igraph_matrix_t *m;
@ -85,6 +82,11 @@ VALUE cIGraph_matrix_initialize(int argc, VALUE *argv, VALUE self){
}
/* call-seq:
* matrix[i,j] -> Float
*
* Returns the value stored at row i and column j.
*/
VALUE cIGraph_matrix_get(VALUE self, VALUE i, VALUE j){
igraph_matrix_t *m;
@ -94,6 +96,11 @@ VALUE cIGraph_matrix_get(VALUE self, VALUE i, VALUE j){
}
/* call-seq:
* matrix[i,j]= -> Float
*
* Sets the value stored at row i and column j.
*/
VALUE cIGraph_matrix_set(VALUE self, VALUE i, VALUE j, VALUE x){
igraph_matrix_t *m;
@ -104,6 +111,11 @@ VALUE cIGraph_matrix_set(VALUE self, VALUE i, VALUE j, VALUE x){
}
/* call-seq:
* matrix.each{|v| } -> nil
*
* Iterates through each value in the matrix.
*/
VALUE cIGraph_matrix_each(VALUE self){
igraph_matrix_t *m;
@ -122,6 +134,11 @@ VALUE cIGraph_matrix_each(VALUE self){
}
/* call-seq:
* matrix.size -> Integer
*
* Returns the number of elements in the matrix.
*/
VALUE cIGraph_matrix_size(VALUE self){
igraph_matrix_t *m;
@ -131,6 +148,11 @@ VALUE cIGraph_matrix_size(VALUE self){
}
/* call-seq:
* matrix.nrow -> Integer
*
* Returns the number of rows in the matrix.
*/
VALUE cIGraph_matrix_nrow(VALUE self){
igraph_matrix_t *m;
@ -140,6 +162,11 @@ VALUE cIGraph_matrix_nrow(VALUE self){
}
/* call-seq:
* matrix.ncol -> Integer
*
* Returns the number of columns in the matrix.
*/
VALUE cIGraph_matrix_ncol(VALUE self){
igraph_matrix_t *m;
@ -149,6 +176,11 @@ VALUE cIGraph_matrix_ncol(VALUE self){
}
/* call-seq:
* matrix.max -> Float
*
* Returns the value of the maximum element in the matrix.
*/
VALUE cIGraph_matrix_max(VALUE self){
igraph_matrix_t *m;
@ -158,6 +190,11 @@ VALUE cIGraph_matrix_max(VALUE self){
}
/* call-seq:
* matrix * matrix -> IGraphMatrix
*
* Multiples two IGraphMatrix objects together
*/
VALUE cIGraph_matrix_multiply(VALUE self, VALUE x){
igraph_matrix_t *m;
@ -175,6 +212,11 @@ VALUE cIGraph_matrix_multiply(VALUE self, VALUE x){
}
/* call-seq:
* matrix.to_a -> Array
*
* Returns the matrix represented as an Array of Arrays.
*/
VALUE cIGraph_matrix_toa(VALUE self){
igraph_matrix_t *m;