You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

cIGraph_generators_random.c 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. #include "igraph.h"
  2. #include "ruby.h"
  3. #include "cIGraph.h"
  4. /* call-seq:
  5. * IGraph::GenerateRandom.grg_game(nodes,radius,torus) -> IGraph
  6. *
  7. * Generating geometric random graphs. A geometric random graph is created by
  8. * dropping points (=vertices) randomly to the unit square and then
  9. * connecting all those pairs which are less than radius apart in Euclidean
  10. * norm.
  11. *
  12. * nodes: The number of vertices in the graph.
  13. *
  14. * radius: The radius within which the vertices will be connected.
  15. * torus: Logical constant, if true periodic boundary conditions will be used,
  16. * ie. the vertices are assumed to be on a torus instead of a square.
  17. */
  18. VALUE cIGraph_grg_game(VALUE self, VALUE nodes, VALUE radius, VALUE torus){
  19. igraph_t *graph;
  20. VALUE new_graph;
  21. new_graph = cIGraph_alloc(cIGraph);
  22. Data_Get_Struct(new_graph, igraph_t, graph);
  23. igraph_destroy(graph);
  24. igraph_grg_game(graph, NUM2INT(nodes), NUM2DBL(radius),
  25. torus == Qtrue ? 1: 0, NULL, NULL);
  26. return new_graph;
  27. }
  28. /* call-seq:
  29. * IGraph::GenerateRandom.barabasi_game(n,m,outpref,directed) -> IGraph
  30. *
  31. * Generates a graph based on the Barabsi-Albert model.
  32. *
  33. * n: The number of vertices in the graph.
  34. * m: The number of outgoing edges generated for each vertex.
  35. *
  36. * outpref: Boolean, if true not only the in- but also the out-degree of a
  37. * vertex increases its citation probability. Ie. the citation probability is
  38. * determined by the total degree of the vertices.
  39. *
  40. * directed: Boolean, whether to generate a directed graph.
  41. */
  42. VALUE cIGraph_barabasi_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE directed){
  43. igraph_t *graph;
  44. VALUE new_graph;
  45. new_graph = cIGraph_alloc(cIGraph);
  46. Data_Get_Struct(new_graph, igraph_t, graph);
  47. igraph_destroy(graph);
  48. igraph_barabasi_game(graph, NUM2INT(nodes), NUM2INT(m), NULL,
  49. outpref == Qtrue ? 1: 0, directed == Qtrue ? 1: 0);
  50. return new_graph;
  51. }
  52. /* call-seq:
  53. * IGraph::GenerateRandom.nonlinear_barabasi_game(n,m,outpref,directed) -> IGraph
  54. *
  55. * Generates graph with non-linear preferential attachment.
  56. *
  57. * This function is very similar to barabasi_game(), only in this game the
  58. * probability that a new vertex attaches to a given old vertex is not
  59. * proportional to the degree of the old node, but some power of the degree
  60. * of the old node.
  61. *
  62. * More precisely the attachment probability is the degree to the power of
  63. * power plus zeroappeal.
  64. *
  65. * This function might generate graphs with multiple edges if the value of m
  66. * is at least two. You can call simplify() to get rid of the multiple
  67. * edges.
  68. *
  69. * n: The number of vertices in the generated graph.
  70. *
  71. * power: The power of the preferential attachment.
  72. *
  73. * m: The number of edges to generate in each time step.
  74. *
  75. * outpref: Logical constant, if TRUE then the preferential attachment is
  76. * based on the total degree of the nodes instead of the in-degree.
  77. *
  78. * zeroappeal: Positive number, the attachment probability for vertices with
  79. * degree zero.
  80. *
  81. * directed: Logical constant, whether to generate a directed graph.
  82. */
  83. VALUE cIGraph_nonlinear_barabasi_game(VALUE self, VALUE nodes, VALUE power, VALUE m, VALUE outpref, VALUE zeroappeal, VALUE directed){
  84. igraph_t *graph;
  85. VALUE new_graph;
  86. new_graph = cIGraph_alloc(cIGraph);
  87. Data_Get_Struct(new_graph, igraph_t, graph);
  88. igraph_destroy(graph);
  89. igraph_nonlinear_barabasi_game(graph, NUM2INT(nodes), NUM2DBL(power),
  90. NUM2INT(m), NULL,
  91. outpref == Qtrue ? 1: 0,
  92. NUM2DBL(zeroappeal),
  93. directed == Qtrue ? 1: 0);
  94. return new_graph;
  95. }
  96. /* call-seq:
  97. * IGraph::GenerateRandom.erdos_renyi_game(type,n,p_or_m,directed,loops) -> IGraph
  98. *
  99. * Generates a random (Erdos-Renyi) graph.
  100. *
  101. * type: The type of the random graph, possible values:
  102. *
  103. * IGraph::ERDOS_RENYI_GNM - G(n,m) graph, m edges are selected uniformly
  104. * randomly in a graph with n vertices.
  105. *
  106. * IGraph::ERDOS_RENYI_GNP - G(n,p) graph, every possible edge is included in
  107. * the graph with probability p.
  108. *
  109. * n: The number of vertices in the graph.
  110. *
  111. * p_or_m: This is the p parameter for G(n,p) graphs and the m parameter
  112. * for G(n,m) graphs.
  113. *
  114. * directed: Logical, whether to generate a directed graph.
  115. *
  116. * loops: Logical, whether to generate loops (self) edges.
  117. */
  118. VALUE cIGraph_erdos_renyi_game(VALUE self, VALUE type, VALUE nodes, VALUE mp, VALUE directed, VALUE loops){
  119. igraph_t *graph;
  120. VALUE new_graph;
  121. new_graph = cIGraph_alloc(cIGraph);
  122. Data_Get_Struct(new_graph, igraph_t, graph);
  123. igraph_destroy(graph);
  124. igraph_erdos_renyi_game(graph, NUM2INT(type), NUM2INT(nodes),
  125. NUM2DBL(mp),
  126. directed == Qtrue ? 1: 0,
  127. loops == Qtrue ? 1: 0);
  128. return new_graph;
  129. }
  130. /* call-seq:
  131. * IGraph::GenerateRandom.watts_strogatz_game(dim,size,nei,p) -> IGraph
  132. *
  133. * The Watts-Strogatz small-world model This function generates a graph
  134. * according to the Watts-Strogatz model of small-world networks. The graph
  135. * is obtained by creating a circular undirected lattice and then rewire the
  136. * edges randomly with a constant probability.
  137. *
  138. * dim: The dimension of the lattice.
  139. *
  140. * size: The size of the lattice along each dimension.
  141. *
  142. * nei: The size of the neighborhood for each vertex.
  143. *
  144. * p: The rewiring probability. A real number between zero and one (inclusive).
  145. */
  146. VALUE cIGraph_watts_strogatz_game(VALUE self, VALUE dim, VALUE size, VALUE nei, VALUE p){
  147. igraph_t *graph;
  148. VALUE new_graph;
  149. new_graph = cIGraph_alloc(cIGraph);
  150. Data_Get_Struct(new_graph, igraph_t, graph);
  151. igraph_destroy(graph);
  152. igraph_watts_strogatz_game(graph, NUM2INT(dim), NUM2INT(size),
  153. NUM2INT(nei), NUM2DBL(p));
  154. return new_graph;
  155. }
  156. /* call-seq:
  157. * IGraph::GenerateRandom.degree_sequence_game(out_deg,in_deg) -> IGraph
  158. *
  159. * Generates a random graph with a given degree sequence
  160. *
  161. * out_deg: The degree sequence for an undirected graph (if in_seq is of
  162. * length zero), or the out-degree sequence of a directed graph (if in_deq is
  163. * not of length zero.
  164. *
  165. * in_deg: It is either a zero-length Array or the in-degree sequence.
  166. */
  167. VALUE cIGraph_degree_sequence_game(VALUE self, VALUE out_deg, VALUE in_deg){
  168. igraph_t *graph;
  169. VALUE new_graph;
  170. igraph_vector_t out_degv;
  171. igraph_vector_t in_degv;
  172. int i;
  173. new_graph = cIGraph_alloc(cIGraph);
  174. Data_Get_Struct(new_graph, igraph_t, graph);
  175. igraph_vector_init(&out_degv,0);
  176. igraph_vector_init(&in_degv,0);
  177. for(i=0;i<RARRAY_LEN(out_deg);i++){
  178. igraph_vector_push_back(&out_degv,NUM2INT(RARRAY_PTR(out_deg)[i]));
  179. }
  180. for(i=0;i<RARRAY_LEN(in_deg);i++){
  181. igraph_vector_push_back(&in_degv,NUM2INT(RARRAY_PTR(in_deg)[i]));
  182. }
  183. igraph_destroy(graph);
  184. igraph_degree_sequence_game(graph, &out_degv, &in_degv, 0);
  185. igraph_vector_destroy(&out_degv);
  186. igraph_vector_destroy(&in_degv);
  187. return new_graph;
  188. }
  189. /* call-seq:
  190. * IGraph::GenerateRandom.growing_random_game(n,m,directed,citation) -> IGraph
  191. *
  192. * Generates a growing random graph.
  193. *
  194. * This function simulates a growing random graph. In each discrete time
  195. * step a new vertex is added and a number of new edges are also added.
  196. * These graphs are known to be different from standard (not growing) random
  197. * graphs.
  198. *
  199. * n: The number of vertices in the graph.
  200. *
  201. * m: The number of edges to add in a time step (ie. after adding a vertex).
  202. *
  203. * directed: Boolean, whether to generate a directed graph.
  204. *
  205. * citation: Boolean, if TRUE, the edges always originate from the most
  206. * recently added vertex.
  207. */
  208. VALUE cIGraph_growing_random_game(VALUE self, VALUE n, VALUE m, VALUE directed, VALUE citation){
  209. igraph_t *graph;
  210. VALUE new_graph;
  211. new_graph = cIGraph_alloc(cIGraph);
  212. Data_Get_Struct(new_graph, igraph_t, graph);
  213. igraph_destroy(graph);
  214. igraph_growing_random_game(graph, NUM2INT(n), NUM2INT(m),
  215. directed == Qtrue ? 1: 0,
  216. citation == Qtrue ? 1: 0);
  217. return new_graph;
  218. }
  219. /* call-seq:
  220. * IGraph::GenerateRandom.callaway_traits_game(nodes,types,edges_per_step,type_dist,pref_matrix,directed) -> IGraph
  221. *
  222. * This function simulates a growing network with vertex types. The different
  223. * types of vertices prefer to connect other types of vertices with a given
  224. * probability.
  225. *
  226. * The simulation goes like this: in each discrete time step a new vertex is
  227. * added to the graph. The type of this vertex is generated based on
  228. * type_dist. Then two vertices are selected uniformly randomly from the
  229. * graph. The probability that they will be connected depends on the types
  230. * of these vertices and is taken from pref_matrix. Then another two vertices
  231. * are selected and this is repeated edges_per_step times in each time step.
  232. *
  233. * nodes: The number of nodes in the graph.
  234. *
  235. * types: Number of node types.
  236. *
  237. * edges_per_step: The number of edges to be add per time step.
  238. *
  239. * type_dist: Array giving the distribution of the vertex types.
  240. *
  241. * pref_matrix: IGraphMatrix giving the connection probabilities for the
  242. * vertex types.
  243. *
  244. * directed: Logical, whether to generate a directed graph.
  245. */
  246. VALUE cIGraph_callaway_traits_game(VALUE self, VALUE nodes, VALUE types, VALUE e_per_step, VALUE type_dist, VALUE pref_matrix, VALUE directed){
  247. igraph_t *graph;
  248. VALUE new_graph;
  249. igraph_vector_t type_distv;
  250. igraph_matrix_t *pref_matrixm;
  251. int i;
  252. new_graph = cIGraph_alloc(cIGraph);
  253. Data_Get_Struct(new_graph, igraph_t, graph);
  254. Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
  255. igraph_vector_init(&type_distv,0);
  256. for(i=0;i<RARRAY_LEN(type_dist);i++){
  257. igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY_PTR(type_dist)[i]));
  258. }
  259. igraph_destroy(graph);
  260. igraph_callaway_traits_game(graph, NUM2INT(nodes), NUM2INT(types),
  261. NUM2INT(e_per_step), &type_distv,
  262. pref_matrixm,
  263. directed == Qtrue ? 1: 0);
  264. igraph_vector_destroy(&type_distv);
  265. return new_graph;
  266. }
  267. /* call-seq:
  268. * IGraph::GenerateRandom.establishment_game(nodes,types,k,type_dist,pref_matrix,directed) -> IGraph
  269. *
  270. * Generates a graph with a simple growing model with vertex types
  271. *
  272. * The simulation goes like this: a single vertex is added at each time step.
  273. * This new vertex tries to connect to k vertices in the graph. The
  274. * probability that such a connection is realized depends on the types of the
  275. * vertices involved.
  276. *
  277. * nodes: The number of vertices in the graph.
  278. *
  279. * types: The number of vertex types.
  280. *
  281. * k: The number of connections tried in each time step.
  282. *
  283. * type_dist: Array giving the distribution of vertex types.
  284. *
  285. * pref_matrix: IGraphMatrix giving the connection probabilities for
  286. * different vertex types.
  287. *
  288. * directed: Logical, whether to generate a directed graph.
  289. */
  290. VALUE cIGraph_establishment_game(VALUE self, VALUE nodes, VALUE types, VALUE k, VALUE type_dist, VALUE pref_matrix, VALUE directed){
  291. igraph_t *graph;
  292. VALUE new_graph;
  293. igraph_vector_t type_distv;
  294. igraph_matrix_t *pref_matrixm;
  295. int i;
  296. new_graph = cIGraph_alloc(cIGraph);
  297. Data_Get_Struct(new_graph, igraph_t, graph);
  298. Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
  299. igraph_vector_init(&type_distv,0);
  300. for(i=0;i<RARRAY_LEN(type_dist);i++){
  301. igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY_PTR(type_dist)[i]));
  302. }
  303. igraph_destroy(graph);
  304. igraph_establishment_game(graph, NUM2INT(nodes), NUM2INT(types),
  305. NUM2INT(k), &type_distv,
  306. pref_matrixm,
  307. directed == Qtrue ? 1: 0);
  308. igraph_vector_destroy(&type_distv);
  309. return new_graph;
  310. }
  311. /* call-seq:
  312. * IGraph::GenerateRandom.preference_game(nodes,types,type_dist,pref_matrixdirected,loops) -> IGraph
  313. *
  314. * Generates a graph with vertex types and connection preferences
  315. *
  316. * This is practically the nongrowing variant of igraph_establishment_game.
  317. * A given number of vertices are generated. Every vertex is assigned to a
  318. * vertex type according to the given type probabilities. Finally, every
  319. * vertex pair is evaluated and an edge is created between them with a
  320. * probability depending on the types of the vertices involved.
  321. *
  322. * nodes: The number of vertices in the graph.
  323. *
  324. * types: The number of vertex types.
  325. *
  326. * type_dist: Vector giving the distribution of vertex types.
  327. *
  328. * pref_matrix: IGraphMatrix giving the connection probabilities for
  329. * different vertex types.
  330. *
  331. * directed: Logical, whether to generate a directed graph. If undirected
  332. * graphs are requested, only the lower left triangle of the preference
  333. * matrix is considered.
  334. *
  335. * loops: Logical, whether loop edges are allowed.
  336. */
  337. VALUE cIGraph_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist, VALUE pref_matrix, VALUE directed, VALUE loops){
  338. igraph_t *graph;
  339. VALUE new_graph;
  340. igraph_vector_t type_distv;
  341. igraph_matrix_t *pref_matrixm;
  342. int i;
  343. new_graph = cIGraph_alloc(cIGraph);
  344. Data_Get_Struct(new_graph, igraph_t, graph);
  345. Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
  346. igraph_vector_init(&type_distv,0);
  347. for(i=0;i<RARRAY_LEN(type_dist);i++){
  348. igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY_PTR(type_dist)[i]));
  349. }
  350. igraph_destroy(graph);
  351. igraph_preference_game(graph, NUM2INT(nodes), NUM2INT(types),
  352. &type_distv,
  353. pref_matrixm,
  354. NULL,
  355. directed == Qtrue ? 1: 0,
  356. loops == Qtrue ? 1 : 0);
  357. igraph_vector_destroy(&type_distv);
  358. return new_graph;
  359. }
  360. /* call-seq:
  361. * IGraph::GenerateRandom.asymmetric_preference_game(nodes,types,type_dist_matrix,pref_matrix,loops) -> IGraph
  362. *
  363. * Generates a graph with asymmetric vertex types and connection preferences
  364. *
  365. * This is the asymmetric variant of preference_game() . A given number of
  366. * vertices are generated. Every vertex is assigned to an "incoming" and an
  367. * "outgoing" vertex type according to the given joint type probabilities.
  368. * Finally, every vertex pair is evaluated and a directed edge is created
  369. * between them with a probability depending on the "outgoing" type of the
  370. * source vertex and the "incoming" type of the target vertex.
  371. *
  372. * nodes: The number of vertices in the graph.
  373. *
  374. * types: The number of vertex types.
  375. *
  376. * type_dist_matrix: IGraphMatrix giving the joint distribution of vertex
  377. * types.
  378. *
  379. * pref_matrix: IGraphMatrix giving the connection probabilities for different
  380. * vertex types.
  381. *
  382. * loops: Logical, whether loop edges are allowed.
  383. */
  384. VALUE cIGraph_asymmetric_preference_game(VALUE self, VALUE nodes, VALUE types, VALUE type_dist_matrix, VALUE pref_matrix, VALUE loops){
  385. igraph_t *graph;
  386. VALUE new_graph;
  387. igraph_matrix_t *type_dist_matrixm;
  388. igraph_matrix_t *pref_matrixm;
  389. new_graph = cIGraph_alloc(cIGraph);
  390. Data_Get_Struct(new_graph, igraph_t, graph);
  391. Data_Get_Struct(pref_matrix, igraph_matrix_t, pref_matrixm);
  392. Data_Get_Struct(type_dist_matrix, igraph_matrix_t, type_dist_matrixm);
  393. igraph_destroy(graph);
  394. igraph_asymmetric_preference_game(graph, NUM2INT(nodes), NUM2INT(types),
  395. type_dist_matrixm,
  396. pref_matrixm,
  397. NULL, NULL,
  398. loops == Qtrue ? 1 : 0);
  399. return new_graph;
  400. }
  401. /* call-seq:
  402. * IGraph::GenerateRandom.recent_degree_game(n,power,window,m,outseq,outpref,zero_appeal,directed) -> IGraph
  403. *
  404. * Stochastic graph generator based on the number of adjacent edges a node
  405. * has gained recently
  406. *
  407. * n: The number of vertices in the graph, this is the same as the number of
  408. * time steps.
  409. *
  410. * power: The exponent, the probability that a node gains a new edge is
  411. * proportional to the number of edges it has gained recently (in the last
  412. * window time steps) to power.
  413. *
  414. * window: Integer constant, the size of the time window to use to count the
  415. * number of recent edges.
  416. *
  417. * m: Integer constant, the number of edges to add per time step
  418. *
  419. * outpref: Logical constant, if true the edges originated by a vertex also
  420. * count as recent adjacent edges. It is false in most cases.
  421. *
  422. * zero_appeal: Constant giving the attractiveness of the vertices which
  423. * haven't gained any edge recently.
  424. * directed: Logical constant, whether to generate a directed graph.
  425. */
  426. VALUE cIGraph_recent_degree_game(VALUE self, VALUE n, VALUE power, VALUE window, VALUE m, VALUE outpref, VALUE zero_appeal, VALUE directed){
  427. igraph_t *graph;
  428. VALUE new_graph;
  429. new_graph = cIGraph_alloc(cIGraph);
  430. Data_Get_Struct(new_graph, igraph_t, graph);
  431. igraph_destroy(graph);
  432. igraph_recent_degree_game(graph, NUM2INT(n), NUM2DBL(power),
  433. NUM2INT(window), NUM2INT(m),
  434. NULL,
  435. outpref == Qtrue ? 1: 0,
  436. NUM2DBL(zero_appeal),
  437. directed == Qtrue ? 1: 0);
  438. return new_graph;
  439. }
  440. /* call-seq:
  441. * IGraph::GenerateRandom.barabasi_aging_game(nodes,m,outpref,pa_exp,aging_exp,aging_bin,zero_deg_appeal,zero_age_appeal,deg_coef,age_coef,directed) -> IGraph
  442. *
  443. * Preferential attachment with aging of vertices.
  444. *
  445. * In this game, the probability that a node gains a new edge is given by
  446. * its (in-)degree (k) and age (l). This probability has a degree dependent
  447. * component multiplied by an age dependent component. The degree dependent
  448. * part is: deg_coef times k to the power of pa_exp plus zero_deg_appeal; and
  449. * the age dependent part is age_coef times l to the power of aging_exp plus
  450. * zero_age_appeal.
  451. *
  452. * The age is based on the number of vertices in the network and the
  453. * aging_bin argument: vertices grew one unit older after each aging_bin
  454. * vertices added to the network.
  455. *
  456. * nodes: The number of vertices in the graph.
  457. *
  458. * m: The number of edges to add in each time step.
  459. *
  460. * outpref: Logical constant, whether the edges initiated by a vertex
  461. * contribute to the probability to gain a new edge.
  462. *
  463. * pa_exp: The exponent of the preferential attachment, a small positive
  464. * number usually, the value 1 yields the classic linear preferential
  465. * attachment.
  466. *
  467. * aging_exp: The exponent of the aging, this is a negative number usually.
  468. *
  469. * aging_bin: Integer constant, the number of vertices to add before vertices
  470. * in the network grew one unit older.
  471. *
  472. * zero_deg_appeal: The degree dependent part of the attractiveness of the
  473. * zero degree vertices.
  474. *
  475. * zero_age_appeal: The age dependent part of the attractiveness of the
  476. * vertices of age zero. This parameter is usually zero.
  477. *
  478. * deg_coef: The coefficient for the degree.
  479. *
  480. * age_coef: The coefficient for the age.
  481. *
  482. * directed: Logical constant, whether to generate a directed graph.
  483. */
  484. VALUE cIGraph_barabasi_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE zero_deg_appeal, VALUE zero_age_appeal, VALUE deg_coef, VALUE age_coef, VALUE directed){
  485. igraph_t *graph;
  486. VALUE new_graph;
  487. new_graph = cIGraph_alloc(cIGraph);
  488. Data_Get_Struct(new_graph, igraph_t, graph);
  489. igraph_destroy(graph);
  490. igraph_barabasi_aging_game(graph, NUM2INT(nodes), NUM2INT(m),
  491. NULL,
  492. outpref == Qtrue ? 1: 0,
  493. NUM2DBL(pa_exp), NUM2DBL(aging_exp),
  494. NUM2INT(aging_bin),
  495. NUM2DBL(zero_deg_appeal),
  496. NUM2DBL(zero_age_appeal),
  497. NUM2DBL(deg_coef),
  498. NUM2DBL(age_coef),
  499. directed == Qtrue ? 1: 0);
  500. return new_graph;
  501. }
  502. /* call-seq:
  503. * IGraph::GenerateRandom.recent_degree_aging_game(nodes,m,outpref,pa_exp,aging_exp,aging_bin,time_window,zero_appeal,directed) -> IGraph
  504. *
  505. * Preferential attachment based on the number of edges gained recently, with
  506. * aging of vertices
  507. *
  508. * This game is very similar to igraph_barabasi_aging_game(), except that
  509. * instead of the total number of adjacent edges the number of edges gained
  510. * in the last time_window time steps are counted.
  511. *
  512. * The degree dependent part of the attractiveness is given by k to the power
  513. * of pa_exp plus zero_appeal; the age dependent part is l to the power to
  514. * aging_exp. k is the number of edges gained in the last time_window time
  515. * steps, l is the age of the vertex.
  516. *
  517. * nodes: The number of vertices in the graph.
  518. *
  519. * m: The number of edges to add in each time step.
  520. *
  521. * outpref: Logical constant, whether the edges initiated by a vertex
  522. * contribute to the probability to gain a new edge.
  523. *
  524. * pa_exp: The exponent of the preferential attachment, a small positive
  525. * number usually, the value 1 yields the classic linear preferential
  526. * attachment.
  527. *
  528. * aging_exp: The exponent of the aging, this is a negative number usually.
  529. *
  530. * aging_bin: Integer constant, the number of vertices to add before vertices
  531. * in the network grew one unit older.
  532. *
  533. * zero_appeal: The degree dependent part of the attractiveness of the
  534. * zero degree vertices.
  535. *
  536. * time_window: The time window to use to count the number of adjacent edges
  537. * for the vertices.
  538. *
  539. * directed: Logical constant, whether to generate a directed graph.
  540. */
  541. VALUE cIGraph_recent_degree_aging_game(VALUE self, VALUE nodes, VALUE m, VALUE outpref, VALUE pa_exp, VALUE aging_exp, VALUE aging_bin, VALUE time_window, VALUE zero_appeal, VALUE directed){
  542. igraph_t *graph;
  543. VALUE new_graph;
  544. new_graph = cIGraph_alloc(cIGraph);
  545. Data_Get_Struct(new_graph, igraph_t, graph);
  546. igraph_destroy(graph);
  547. igraph_recent_degree_aging_game(graph, NUM2INT(nodes), NUM2INT(m),
  548. NULL,
  549. outpref == Qtrue ? 1: 0,
  550. NUM2DBL(pa_exp), NUM2DBL(aging_exp),
  551. NUM2INT(aging_bin),
  552. NUM2INT(time_window),
  553. NUM2DBL(zero_appeal),
  554. directed == Qtrue ? 1: 0);
  555. return new_graph;
  556. }
  557. /* call-seq:
  558. * IGraph::GenerateRandom.cited_type_game(nodes,types,pref,edges_per_step_directed) -> IGraph
  559. *
  560. * Function to create a network based on some vertex categories. This function
  561. * creates a citation network, in each step a single vertex and edges_per_step
  562. * citating edges are added, nodes with different categories (may) have
  563. * different probabilities to get cited, as given by the pref vector.
  564. *
  565. * Note that this function might generate networks with multiple edges if
  566. * edges_per_step is greater than one. You might want to call
  567. * igraph_simplify() on the result to remove multiple edges.
  568. *
  569. * nodes: The number of vertices in the network.
  570. *
  571. * types: Numeric Array giving the categories of the vertices, so it should
  572. * contain nodes non-negative integer numbers. Types are numbered from zero.
  573. *
  574. * pref: The attractivity of the different vertex categories in an Array. Its
  575. * length should be the maximum element in types plus one (types are numbered
  576. * from zero).
  577. *
  578. * edges_per_step: Integer constant, the number of edges to add in each time
  579. * step.
  580. *
  581. * directed: Logical constant, whether to create a directed network.
  582. */
  583. VALUE cIGraph_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed){
  584. igraph_t *graph;
  585. VALUE new_graph;
  586. igraph_vector_t type_distv;
  587. igraph_vector_t prefv;
  588. int i;
  589. new_graph = cIGraph_alloc(cIGraph);
  590. Data_Get_Struct(new_graph, igraph_t, graph);
  591. igraph_vector_init(&type_distv,0);
  592. igraph_vector_init(&prefv,0);
  593. for(i=0;i<RARRAY_LEN(types);i++){
  594. igraph_vector_push_back(&type_distv,NUM2DBL(RARRAY_PTR(types)[i]));
  595. }
  596. for(i=0;i<RARRAY_LEN(pref);i++){
  597. igraph_vector_push_back(&prefv,NUM2DBL(RARRAY_PTR(pref)[i]));
  598. }
  599. igraph_destroy(graph);
  600. igraph_cited_type_game(graph, NUM2INT(nodes),
  601. &type_distv,
  602. &prefv,
  603. NUM2INT(e_per_s),
  604. directed == Qtrue ? 1: 0);
  605. igraph_vector_destroy(&type_distv);
  606. igraph_vector_destroy(&prefv);
  607. return new_graph;
  608. }
  609. /* call-seq:
  610. * IGraph::GenerateRandom.citing_cited_type_game(nodes,types,pref,edges_per_step_directed) -> IGraph
  611. *
  612. * This game is similar to igraph_cited_type_game() but here the category of
  613. * the citing vertex is also considered.
  614. *
  615. * An evolving citation network is modeled here, a single vertex and its
  616. * edges_per_step citation are added in each time step. The odds the a given
  617. * vertex is cited by the new vertex depends on the category of both the
  618. * citing and the cited vertex and is given in the pref matrix. The categories
  619. * of the citing vertex correspond to the rows, the categories of the cited
  620. * vertex to the columns of this matrix. Ie. the element in row i and column
  621. * j gives the probability that a j vertex is cited, if the category of the
  622. * citing vertex is i.
  623. *
  624. * Note that this function might generate networks with multiple edges if
  625. * edges_per_step is greater than one. You might want to call
  626. * igraph_simplify() on the result to remove multiple edges.
  627. *
  628. * nodes: The number of vertices in the network.
  629. *
  630. * types: A numeric IGraphMatrix of length nodes, containing the categories
  631. * of the vertices. The categories are numbered from zero.
  632. *
  633. * pref: The preference IGraphMatrix, a square matrix is required, both the
  634. * number of rows and columns should be the maximum element in types plus
  635. * one (types are numbered from zero).
  636. *
  637. * edges_per_step: Integer constant, the number of edges to add in each time
  638. * step.
  639. *
  640. * directed: Logical constant, whether to create a directed network.
  641. */
  642. VALUE cIGraph_citing_cited_type_game(VALUE self, VALUE nodes, VALUE types, VALUE pref, VALUE e_per_s, VALUE directed){
  643. igraph_t *graph;
  644. VALUE new_graph;
  645. igraph_vector_t typev;
  646. igraph_matrix_t *prefm;
  647. int i;
  648. new_graph = cIGraph_alloc(cIGraph);
  649. Data_Get_Struct(new_graph, igraph_t, graph);
  650. Data_Get_Struct(pref, igraph_matrix_t, prefm);
  651. igraph_vector_init(&typev,0);
  652. for(i=0;i<RARRAY_LEN(types);i++){
  653. igraph_vector_push_back(&typev,NUM2INT(RARRAY_PTR(types)[i]));
  654. }
  655. printf("ok\n");
  656. igraph_destroy(graph);
  657. igraph_citing_cited_type_game(graph, NUM2INT(nodes),
  658. &typev,
  659. prefm,
  660. NUM2INT(e_per_s),
  661. directed == Qtrue ? 1: 0);
  662. printf("death\n");
  663. igraph_vector_destroy(&typev);
  664. return new_graph;
  665. }

Ruby binding for the igraph library.