~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to examples/simple/igraph_preference_game.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C -*-  */
 
2
/* 
 
3
   IGraph library.
 
4
   Copyright (C) 2006  Gabor Csardi <csardi@rmki.kfki.hu>
 
5
   MTA RMKI, Konkoly-Thege Miklos st. 29-33, Budapest 1121, Hungary
 
6
   
 
7
   This program is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2 of the License, or
 
10
   (at your option) any later version.
 
11
   
 
12
   This program is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
   
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with this program; if not, write to the Free Software
 
19
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
 
20
   02110-1301 USA
 
21
 
 
22
*/
 
23
 
 
24
#include <igraph.h>
 
25
#include <assert.h>
 
26
 
 
27
int main() {
 
28
  igraph_t g;
 
29
  igraph_vector_t tdist;
 
30
  igraph_matrix_t pmat;
 
31
  igraph_bool_t conn;
 
32
  igraph_vector_bool_t bs;
 
33
  int i, ret;
 
34
  
 
35
  /* Symmetric preference game */
 
36
  igraph_vector_bool_init(&bs, 0);
 
37
 
 
38
  igraph_vector_init_real(&tdist, 3, 1.0, 1.0, 1.0);
 
39
 
 
40
  igraph_matrix_init(&pmat, 3, 3);
 
41
  for (i=0; i<3; i++) MATRIX(pmat, i, i) = 0.2;
 
42
 
 
43
  /* undirected, no loops */
 
44
  IGRAPH_CHECK(igraph_preference_game(&g, 1000, 3, &tdist, &pmat, 0, 0, 0));
 
45
  if (igraph_vcount(&g) != 1000) return 18;
 
46
  if (igraph_is_directed(&g)) return 2;
 
47
  igraph_is_connected(&g, &conn, IGRAPH_STRONG);
 
48
  if (conn) return 3;
 
49
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
50
  if (igraph_vector_bool_sum(&bs)) return 4;
 
51
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
52
  if (igraph_vector_bool_sum(&bs)) return 5;
 
53
  igraph_destroy(&g);
 
54
 
 
55
  for (i=0; i<2; i++) MATRIX(pmat, i, i+1) = 0.1;
 
56
 
 
57
  /* directed, no loops */
 
58
  IGRAPH_CHECK(igraph_preference_game(&g, 1000, 3, &tdist, &pmat, 0, 1, 0));
 
59
  if (igraph_vcount(&g) != 1000) return 17;
 
60
  if (!igraph_is_directed(&g)) return 6;
 
61
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
62
  if (igraph_vector_bool_sum(&bs)) return 7;
 
63
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
64
  if (igraph_vector_bool_sum(&bs)) return 8;
 
65
  igraph_destroy(&g);
 
66
 
 
67
  /* undirected, loops */
 
68
  for (i=0; i<3; i++) MATRIX(pmat, i, i) = 1.0;
 
69
  IGRAPH_CHECK(igraph_preference_game(&g, 100, 3, &tdist, &pmat, 0, 0, 1));
 
70
  if (igraph_vcount(&g) != 100) return 16;
 
71
  if (igraph_ecount(&g) < 1395) return 20;
 
72
  if (igraph_is_directed(&g)) return 9;
 
73
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
74
  if (igraph_vector_bool_sum(&bs) == 0) return 10;
 
75
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
76
  if (igraph_vector_bool_sum(&bs)) return 11;
 
77
  igraph_destroy(&g);
 
78
 
 
79
  /* directed, loops */
 
80
  IGRAPH_CHECK(igraph_preference_game(&g, 100, 3, &tdist, &pmat, 0, 1, 1));
 
81
  if (igraph_vcount(&g) != 100) return 15;
 
82
  if (igraph_ecount(&g) < 2700) return 19;
 
83
  if (!igraph_is_directed(&g)) return 12;
 
84
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
85
  if (igraph_vector_bool_sum(&bs) == 0) return 13;
 
86
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
87
  if (igraph_vector_bool_sum(&bs)) return 14;
 
88
  igraph_destroy(&g);
 
89
 
 
90
  /* Asymmetric preference game */
 
91
 
 
92
  /* directed, no loops */
 
93
  igraph_matrix_resize(&pmat, 2, 2);
 
94
  MATRIX(pmat, 0, 0) = 1; MATRIX(pmat, 0, 1) = 1;
 
95
  MATRIX(pmat, 1, 0) = 1; MATRIX(pmat, 1, 1) = 1;
 
96
  IGRAPH_CHECK(igraph_asymmetric_preference_game(&g, 100, 2, 0, &pmat, 0, 0, 0));
 
97
  if (igraph_vcount(&g) != 100) return 21;
 
98
  if (igraph_ecount(&g) != 9900) return 22;
 
99
  if (!igraph_is_directed(&g)) return 23;
 
100
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
101
  if (igraph_vector_bool_sum(&bs)) return 24;
 
102
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
103
  if (igraph_vector_bool_sum(&bs)) return 25;
 
104
  igraph_destroy(&g);
 
105
 
 
106
  /* directed, loops */
 
107
  igraph_matrix_resize(&pmat, 2, 2);
 
108
  MATRIX(pmat, 0, 0) = 1; MATRIX(pmat, 0, 1) = 1;
 
109
  MATRIX(pmat, 1, 0) = 1; MATRIX(pmat, 1, 1) = 1;
 
110
  IGRAPH_CHECK(igraph_asymmetric_preference_game(&g, 100, 2, 0, &pmat, 0, 0, 1));
 
111
  if (igraph_vcount(&g) != 100) return 26;
 
112
  if (igraph_ecount(&g) != 10000) return 27;
 
113
  if (!igraph_is_directed(&g)) return 28;
 
114
  igraph_is_loop(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
115
  if (igraph_vector_bool_sum(&bs) != 100) return 29;
 
116
  igraph_is_multiple(&g, &bs, igraph_ess_all(IGRAPH_EDGEORDER_ID));
 
117
  if (igraph_vector_bool_sum(&bs)) return 30;
 
118
  igraph_destroy(&g);
 
119
 
 
120
  igraph_vector_destroy(&tdist);
 
121
  igraph_matrix_destroy(&pmat);
 
122
  igraph_vector_bool_destroy(&bs);
 
123
 
 
124
  assert(IGRAPH_FINALLY_STACK_EMPTY);
 
125
 
 
126
  return 0;
 
127
}