#include "igraph.h" #include "ruby.h" #include "cIGraph.h" /* call-seq: * graph.dijkstra_shortest_paths(varray,weights,mode) -> Array * * Calculates the length of the shortest paths from each of the vertices in * the varray Array to all of the other vertices in the graph given a set of * edge weights given in the weights Array. The result * is returned as an Array of Array. Each top-level Array contains the results * for a vertex in the varray Array. Each entry in the Array is the path length * to another vertex in the graph in vertex order (the order the vertices were * added to the graph. (This should probalby be changed to give a Hash of Hash * to allow easier look up.) */ VALUE cIGraph_dijkstra_shortest_paths(VALUE self, VALUE from, VALUE weights, VALUE mode){ igraph_t *graph; igraph_vs_t vids; igraph_vector_t vidv; igraph_vector_t wghts; igraph_neimode_t pmode = NUM2INT(mode); igraph_matrix_t res; int i; int j; VALUE row; VALUE path_length; VALUE matrix = rb_ary_new(); int n_row; int n_col; Data_Get_Struct(self, igraph_t, graph); n_row = NUM2INT(rb_funcall(from,rb_intern("length"),0)); n_col = igraph_vcount(graph); //matrix to hold the results of the calculations igraph_matrix_init(&res,n_row,n_col); igraph_vector_init(&wghts,RARRAY_LEN(weights)); for(i=0;i Array * * Calculates the paths from the vertex specified as from to each vertex in the * to_array Array. Returns an Array of Arrays. Each top level Array represents * a path and each entry in each Array is a vertex on the path. mode * represents the type of shortest paths to be calculated: IGraph::OUT * the outgoing paths are calculated. IGraph::IN the incoming paths are * calculated. IGraph::ALL the directed graph is considered as an undirected * one for the computation. */ VALUE cIGraph_get_dijkstra_shortest_paths(VALUE self, VALUE from, VALUE to, VALUE mode){ igraph_t *graph; igraph_integer_t from_vid; igraph_vs_t to_vids; igraph_vector_t to_vidv; igraph_neimode_t pmode = NUM2INT(mode); igraph_vector_ptr_t res; igraph_vector_t *path_v; int i; int j; VALUE path; VALUE matrix = rb_ary_new(); int n_paths; Data_Get_Struct(self, igraph_t, graph); n_paths = RARRAY_LEN(to); //vector to hold the results of the calculations igraph_vector_ptr_init(&res,0); for(i=0;i