Class: IGraph
- Inherits:
-
Object
- Object
- IGraph
- Includes:
- Enumerable, Cliques, Closeness, Community, Components, Connectivity, FileRead, FileWrite, Generate, GenerateRandom, IndependentVertexSets, Isomorphism, KCores, Layout, MinimumCuts, Motifs, Neighborhood, OtherOperations, Randomise, ShortestPaths, Sorting, Spanning, Spectral, Transitivity
- Defined in:
- ext/cIGraph.c
Defined Under Namespace
Modules: Cliques, Closeness, Community, Components, Connectivity, FileRead, FileWrite, Generate, GenerateRandom, IndependentVertexSets, Isomorphism, KCores, Layout, MinimumCuts, Motifs, Neighborhood, OtherOperations, Randomise, ShortestPaths, Sorting, Spanning, Spectral, Transitivity
Constant Summary collapse
- VERSION =
in cIGraph_community.c
rb_str_new2("0.9.1")
- EDGEORDER_ID =
INT2NUM(1)
- EDGEORDER_FROM =
INT2NUM(2)
- EDGEORDER_TO =
INT2NUM(3)
- OUT =
INT2NUM(1)
- IN =
INT2NUM(2)
- ALL =
INT2NUM(3)
- TOTAL =
INT2NUM(4)
- ARBITRARY =
INT2NUM(0)
- MUTUAL =
INT2NUM(1)
- EACH =
INT2NUM(0)
- COLLAPSE =
INT2NUM(1)
- ERDOS_RENYI_GNP =
INT2NUM(0)
- ERDOS_RENYI_GNM =
INT2NUM(1)
Constants included from Generate
Generate::ADJ_DIRECTED, Generate::ADJ_LOWER, Generate::ADJ_MAX, Generate::ADJ_MIN, Generate::ADJ_PLUS, Generate::ADJ_UNDIRECTED, Generate::ADJ_UPPER, Generate::STAR_IN, Generate::STAR_OUT, Generate::STAR_UNDIRECTED, Generate::TREE_IN, Generate::TREE_OUT, Generate::TREE_UNDIRECTED
Constants included from Components
Components::STRONG, Components::WEAK
Constants included from OtherOperations
OtherOperations::GET_ADJACENCY_BOTH, OtherOperations::GET_ADJACENCY_LOWER, OtherOperations::GET_ADJACENCY_UPPER
Constants included from Connectivity
Connectivity::VCONN_NEI_ERROR, Connectivity::VCONN_NEI_IGNORE, Connectivity::VCONN_NEI_INFINITY
Constants included from Community
Community::SPINCOMM_UPDATE_CONFIG, Community::SPINCOMM_UPDATE_SIMPLE
Instance Method Summary collapse
- #[] ⇒ Object (also: #get_edge_attr)
- #[]= ⇒ Object (also: #set_edge_attr)
- #add_edge ⇒ Object
- #add_edges ⇒ Object
- #add_vertex ⇒ Object
- #add_vertices ⇒ Object
- #adjacent ⇒ Object
- #adjacent_edges ⇒ Object
- #adjacent_vertices ⇒ Object
- #are_connected ⇒ Object (also: #are_connected?)
- #attributes ⇒ Object
- #degree ⇒ Object
- #delete_edge ⇒ Object
- #delete_vertex ⇒ Object
- #each_edge ⇒ Object
- #each_edge_eid ⇒ Object
- #each_vertex ⇒ Object (also: #each)
- #ecount ⇒ Object
- #edge ⇒ Object
- #edges ⇒ Object (also: #all_edges)
- #get_eid ⇒ Object
-
#new(edges, directed) ⇒ IGraph
constructor
Creates a new IGraph graph with the edges specified in the edges Array.
-
#initialize_copy(orig) ⇒ Object
Internal method for copying IGraph objects.
- #is_directed? ⇒ Boolean (also: #is_directed)
- #neighbours ⇒ Object (also: #neighbors)
- #nonadjacent_vertices ⇒ Object
- #to_directed ⇒ Object
- #to_undirected ⇒ Object
- #vcount ⇒ Object
- #vertices ⇒ Object (also: #all_vertices)
Methods included from Generate
adjacency, atlas, extended_chordal_ring, full, isoclass_create, lattice, ring, star, tree
Methods included from GenerateRandom
asymmetric_preference_game, barabasi_aging_game, barabasi_game, callaway_traits_game, cited_type_game, citing_cited_type_game, degree_sequence_game, erdos_renyi_game, establishment_game, grg_game, growing_random_game, nonlinear_barabasi_game, preference_game, recent_degree_aging_game, recent_degree_game, watts_strogatz_game
Methods included from Randomise
Methods included from ShortestPaths
#average_path_length, #diameter, #dijkstra_shortest_paths, #get_all_shortest_paths, #get_shortest_paths, #girth, #shortest_paths
Methods included from Neighborhood
#connect_neighborhood, #neighbourhood, #neighbourhood_graphs, #neighbourhood_size
Methods included from Components
#clusters, #decompose, #subcomponent, #subgraph
Methods included from Closeness
#betweenness, #closeness, #constraint, #edge_betweenness, #maxdegree, #pagerank
Methods included from Spanning
#minimum_spanning_tree_prim, #minimum_spanning_tree_unweighted
Methods included from Transitivity
#transitivity, #transitivity_avglocal, #transitivity_local
Methods included from Spectral
Methods included from KCores
Methods included from OtherOperations
#bibcoupling, #cocitation, #density, #get_adjacency, #reciprocity, #simplify
Methods included from Cliques
#clique_number, #cliques, #largest_cliques, #maximal_cliques
Methods included from IndependentVertexSets
#independence_number, #independent_vertex_sets, #largest_independent_vertex_sets, #maximal_independent_vertex_sets
Methods included from Isomorphism
#isoclass, #isoclass_subgraph, #isomorphic, #isomorphic_vf2
Methods included from Motifs
#motifs_randesu, #motifs_randesu_estimate, #motifs_randesu_no
Methods included from Sorting
Methods included from FileRead
read_graph_dimacs, read_graph_edgelist, read_graph_gml, read_graph_graphdb, read_graph_graphml, read_graph_lgl, read_graph_ncol, read_graph_pajek
Methods included from FileWrite
#write_graph_dimacs, #write_graph_edgelist, #write_graph_gml, #write_graph_graphml, #write_graph_lgl, #write_graph_ncol, #write_graph_pajek
Methods included from Layout
#layout_circle, #layout_fruchterman_reingold, #layout_fruchterman_reingold_3d, #layout_grid_fruchterman_reingold, #layout_kamada_kawai, #layout_kamada_kawai_3d, #layout_lgl, layout_merge_dla, #layout_random, #layout_random_3d, #layout_reingold_tilford, #layout_reingold_tilford_circular, #layout_sphere
Methods included from MinimumCuts
#maxflow_value, #mincut, #mincut_value, #st_mincut_value
Methods included from Connectivity
#adhesion, #cohesion, #edge_connectivity, #edge_disjoint_paths, #st_edge_connectivity, #st_vertex_connectivity, #vertex_connectivity, #vertex_disjoint_paths
Methods included from Community
#community_eb_get_merges, #community_edge_betweenness, #community_fastgreedy, #community_leading_eigenvector, #community_leading_eigenvector_naive, #community_leading_eigenvector_step, #community_spinglass, #community_spinglass_single, #community_to_membership, #community_walktrap, #modularity
Constructor Details
#new(edges, directed) ⇒ IGraph
Creates a new IGraph graph with the edges specified in the edges Array. The first two elements define the first edge (the order is from,to for directed graphs). The next two define the second edge and so on. The Array should contain an even number of elements. Graph elements can be any ruby object.
The boolean value directed specifies whether a directed or undirected graph is created.
Example:
IGraph.new([1,2,3,4],true)
Creates a graph with four vertices. Vertex 1 is connected to vertex 2. Vertex 3 is connected to vertex 4.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/cIGraph.c', line 78
VALUE cIGraph_initialize(int argc, VALUE *argv, VALUE self){
igraph_t *graph;
igraph_vector_t edge_v;
VALUE vertex;
VALUE directed;
VALUE edges;
VALUE attrs;
VALUE v_ary;
int vertex_n = 0;
int current_vertex_id;
int i;
igraph_vector_ptr_t vertex_attr;
igraph_vector_ptr_t edge_attr;
igraph_i_attribute_record_t v_attr_rec;
v_attr_rec.name = "__RUBY__";
v_attr_rec.type = IGRAPH_ATTRIBUTE_PY_OBJECT;
v_attr_rec.value = (void*)rb_ary_new();
igraph_i_attribute_record_t e_attr_rec;
e_attr_rec.name = "__RUBY__";
e_attr_rec.type = IGRAPH_ATTRIBUTE_PY_OBJECT;
e_attr_rec.value = (void*)rb_ary_new();
rb_scan_args(argc,argv,"12", &edges, &directed, &attrs);
//Initialize edge vector
IGRAPH_FINALLY(igraph_vector_destroy,&edge_v);
IGRAPH_FINALLY(igraph_vector_ptr_destroy,&vertex_attr);
IGRAPH_FINALLY(igraph_vector_ptr_destroy,&edge_attr);
IGRAPH_CHECK(igraph_vector_init_int(&edge_v,0));
IGRAPH_CHECK(igraph_vector_ptr_init(&vertex_attr,0));
IGRAPH_CHECK(igraph_vector_ptr_init(&edge_attr,0));
Data_Get_Struct(self, igraph_t, graph);
v_ary = rb_ary_new();
if(!directed)
IGRAPH_CHECK(igraph_to_undirected(graph,IGRAPH_TO_UNDIRECTED_COLLAPSE));
//Loop through objects in edge Array
for (i=0; i<RARRAY_LEN(edges); i++) {
vertex = RARRAY_PTR(edges)[i];
if(rb_ary_includes(v_ary,vertex)){
//If @vertices includes this vertex then look up the vertex number
current_vertex_id = NUM2INT(rb_funcall(v_ary,rb_intern("index"),1,vertex));
} else {
//Otherwise add to the list of vertices
rb_ary_push(v_ary,vertex);
current_vertex_id = vertex_n;
vertex_n++;
//Add object to list of vertex attributes
rb_ary_push((VALUE)v_attr_rec.value,vertex);
}
IGRAPH_CHECK(igraph_vector_push_back(&edge_v,current_vertex_id));
if (i % 2){
if (attrs != Qnil){
rb_ary_push((VALUE)e_attr_rec.value,RARRAY_PTR(attrs)[i/2]);
} else {
rb_ary_push((VALUE)e_attr_rec.value,Qnil);
}
}
}
IGRAPH_CHECK(igraph_vector_ptr_push_back(&vertex_attr, &v_attr_rec));
IGRAPH_CHECK(igraph_vector_ptr_push_back(&edge_attr, &e_attr_rec));
if(igraph_vector_size(&edge_v) > 0){
IGRAPH_CHECK(igraph_add_vertices(graph,vertex_n,&vertex_attr));
IGRAPH_CHECK(igraph_add_edges(graph,&edge_v,&edge_attr));
}
igraph_vector_destroy(&edge_v);
igraph_vector_ptr_destroy(&vertex_attr);
igraph_vector_ptr_destroy(&edge_attr);
IGRAPH_FINALLY_CLEAN(3);
return self;
}
|
Instance Method Details
#[] ⇒ Object Also known as: get_edge_attr
#[]= ⇒ Object Also known as: set_edge_attr
#add_edge ⇒ Object
#add_edges ⇒ Object
#add_vertex ⇒ Object
#add_vertices ⇒ Object
#adjacent ⇒ Object
#adjacent_edges ⇒ Object
#adjacent_vertices ⇒ Object
#are_connected ⇒ Object Also known as: are_connected?
#attributes ⇒ Object
#degree ⇒ Object
#delete_edge ⇒ Object
#delete_vertex ⇒ Object
#each_edge ⇒ Object
#each_edge_eid ⇒ Object
#each_vertex ⇒ Object Also known as: each
#ecount ⇒ Object
#edge ⇒ Object
#edges ⇒ Object Also known as: all_edges
#get_eid ⇒ Object
#initialize_copy(orig) ⇒ Object
Internal method for copying IGraph objects.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'ext/cIGraph.c', line 37
VALUE cIGraph_init_copy(VALUE copy, VALUE orig){
igraph_t *orig_graph;
igraph_t *copy_graph;
if (copy == orig)
return copy;
if(TYPE(orig) != T_DATA || RDATA(orig)->dfree != (RUBY_DATA_FUNC)cIGraph_free){
rb_raise(rb_eTypeError, "Wrong argument type.");
}
Data_Get_Struct(copy, igraph_t, copy_graph);
Data_Get_Struct(orig, igraph_t, orig_graph);
IGRAPH_CHECK(igraph_copy(copy_graph,orig_graph));
return copy;
}
|