Add graph references
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2008-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g, g2;
|
||||
igraph_adjlist_t adjlist;
|
||||
igraph_bool_t iso;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a directed out-tree, convert it into an adjacency list
|
||||
* representation, then reconstruct the graph from the tree and check
|
||||
* whether the two are isomorphic (they should be) */
|
||||
|
||||
igraph_kary_tree(&g, 42, 3, IGRAPH_TREE_OUT);
|
||||
igraph_adjlist_init(&g, &adjlist, IGRAPH_OUT, IGRAPH_LOOPS_ONCE, IGRAPH_MULTIPLE);
|
||||
igraph_adjlist(&g2, &adjlist, IGRAPH_OUT, /* duplicate = */ 0);
|
||||
igraph_isomorphic(&g, &g2, &iso);
|
||||
if (!iso) {
|
||||
return 1;
|
||||
}
|
||||
igraph_adjlist_destroy(&adjlist);
|
||||
igraph_destroy(&g2);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2008-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_vector_t weights;
|
||||
igraph_real_t weights_data_0[] = { 0, 2, 1, 0, 5, 2, 1, 1, 0, 2, 2, 8, 1, 1, 3, 1, 1, 4, 2, 1 };
|
||||
igraph_real_t weights_data_1[] = { 6, 7, 8, -4, -2, -3, 9, 2, 7 };
|
||||
igraph_real_t weights_data_2[] = { 6, 7, 2, -4, -2, -3, 9, 2, 7 };
|
||||
igraph_matrix_t res;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Graph with only positive weights */
|
||||
igraph_small(&g, 10, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 2, 0, 3, 1, 2, 1, 4, 1, 5,
|
||||
2, 3, 2, 6, 3, 2, 3, 6,
|
||||
4, 5, 4, 7, 5, 6, 5, 8, 5, 9,
|
||||
7, 5, 7, 8, 8, 9,
|
||||
5, 2,
|
||||
2, 1,
|
||||
-1);
|
||||
|
||||
weights = igraph_vector_view(weights_data_0,
|
||||
sizeof(weights_data_0) / sizeof(weights_data_0[0]));
|
||||
|
||||
igraph_matrix_init(&res, 0, 0);
|
||||
igraph_distances_bellman_ford(&g, &res, igraph_vss_all(), igraph_vss_all(),
|
||||
&weights, IGRAPH_OUT);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
igraph_matrix_destroy(&res);
|
||||
igraph_destroy(&g);
|
||||
|
||||
printf("\n");
|
||||
|
||||
/***************************************/
|
||||
|
||||
/* Graph with negative weights */
|
||||
igraph_small(&g, 5, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 3, 1, 3, 1, 4, 2, 1, 3, 2, 3, 4, 4, 0, 4, 2, -1);
|
||||
|
||||
weights = igraph_vector_view(weights_data_1,
|
||||
sizeof(weights_data_1) / sizeof(weights_data_1[0]));
|
||||
|
||||
igraph_matrix_init(&res, 0, 0);
|
||||
igraph_distances_bellman_ford(&g, &res, igraph_vss_all(),
|
||||
igraph_vss_all(), &weights, IGRAPH_OUT);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
/***************************************/
|
||||
|
||||
/* Same graph with negative cycle */
|
||||
igraph_set_error_handler(igraph_error_handler_ignore);
|
||||
weights = igraph_vector_view(weights_data_2,
|
||||
sizeof(weights_data_2) / sizeof(weights_data_2[0]));
|
||||
if (igraph_distances_bellman_ford(&g, &res, igraph_vss_all(),
|
||||
igraph_vss_all(),
|
||||
&weights, IGRAPH_OUT) != IGRAPH_ENEGCYCLE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
igraph_matrix_destroy(&res);
|
||||
igraph_destroy(&g);
|
||||
|
||||
if (!IGRAPH_FINALLY_STACK_EMPTY) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
0 0 0 1 5 2 1 13 3 5
|
||||
Inf 0 0 1 5 2 1 13 3 5
|
||||
Inf 1 0 1 6 3 1 14 4 6
|
||||
Inf 1 0 0 6 3 1 14 4 6
|
||||
Inf 5 4 5 0 2 3 8 3 5
|
||||
Inf 3 2 3 8 0 1 16 1 3
|
||||
Inf Inf Inf Inf Inf Inf 0 Inf Inf Inf
|
||||
Inf 4 3 4 9 1 2 0 1 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf 0 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0
|
||||
|
||||
0 2 4 7 -2
|
||||
-2 0 2 5 -4
|
||||
-4 -2 0 3 -6
|
||||
-7 -5 -3 0 -9
|
||||
2 4 6 9 0
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_matrix_t m;
|
||||
igraph_vector_t x, y, z;
|
||||
igraph_real_t xz, xx;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_init_real(&x, 3, 1.0, 2.0, 3.0);
|
||||
igraph_vector_init_real(&y, 4, 4.0, 5.0, 6.0, 7.0);
|
||||
igraph_vector_init_real(&z, 3, -1.0, 0.0, 0.5);
|
||||
|
||||
igraph_matrix_init(&m, 4, 3);
|
||||
MATRIX(m, 0, 0) = 1;
|
||||
MATRIX(m, 0, 1) = 2;
|
||||
MATRIX(m, 0, 2) = 3;
|
||||
MATRIX(m, 1, 0) = 2;
|
||||
MATRIX(m, 1, 1) = 3;
|
||||
MATRIX(m, 1, 2) = 4;
|
||||
MATRIX(m, 2, 0) = 3;
|
||||
MATRIX(m, 2, 1) = 4;
|
||||
MATRIX(m, 2, 2) = 5;
|
||||
MATRIX(m, 3, 0) = 4;
|
||||
MATRIX(m, 3, 1) = 5;
|
||||
MATRIX(m, 3, 2) = 6;
|
||||
|
||||
/* Compute 2 m.x + 3 y and store it in y. */
|
||||
igraph_blas_dgemv(/* transpose= */ 0, /* alpha= */ 2, &m, &x, /* beta= */ 3, &y);
|
||||
igraph_vector_print(&y);
|
||||
|
||||
/* Compute the squared norm of x, as well as the dor product of x and z. */
|
||||
igraph_blas_ddot(&x, &x, &xx);
|
||||
igraph_blas_ddot(&x, &z, &xz);
|
||||
printf("x.x = %g, x.z = %g\n", xx, xz);
|
||||
|
||||
igraph_matrix_destroy(&m);
|
||||
igraph_vector_destroy(&z);
|
||||
igraph_vector_destroy(&y);
|
||||
igraph_vector_destroy(&x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
40 55 70 85
|
||||
x.x = 14, x.z = 0.5
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_matrix_t a, b, c;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_matrix_init(&a, 2, 2);
|
||||
MATRIX(a, 0, 0) = 1;
|
||||
MATRIX(a, 0, 1) = 2;
|
||||
MATRIX(a, 1, 0) = 3;
|
||||
MATRIX(a, 1, 1) = 4;
|
||||
|
||||
igraph_matrix_init(&b, 2, 2);
|
||||
MATRIX(b, 0, 0) = 5;
|
||||
MATRIX(b, 0, 1) = 6;
|
||||
MATRIX(b, 1, 0) = 7;
|
||||
MATRIX(b, 1, 1) = 8;
|
||||
|
||||
igraph_matrix_init(&c, 2, 2);
|
||||
|
||||
igraph_blas_dgemm(1, 1, 0.5, &a, &b, 0, &c);
|
||||
igraph_matrix_printf(&c, "%g");
|
||||
|
||||
igraph_matrix_destroy(&a);
|
||||
igraph_matrix_destroy(&b);
|
||||
igraph_matrix_destroy(&c);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
11.5 15.5
|
||||
17 23
|
||||
@@ -0,0 +1,135 @@
|
||||
/* igraph library.
|
||||
Copyright (C) 2007-2021 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Prints graph, vertex and edge attributes stored in a graph. */
|
||||
void print_attributes(const igraph_t *g) {
|
||||
igraph_vector_int_t gtypes, vtypes, etypes;
|
||||
igraph_strvector_t gnames, vnames, enames;
|
||||
igraph_int_t i, j;
|
||||
|
||||
igraph_vector_int_init(>ypes, 0);
|
||||
igraph_vector_int_init(&vtypes, 0);
|
||||
igraph_vector_int_init(&etypes, 0);
|
||||
igraph_strvector_init(&gnames, 0);
|
||||
igraph_strvector_init(&vnames, 0);
|
||||
igraph_strvector_init(&enames, 0);
|
||||
|
||||
igraph_cattribute_list(g,
|
||||
&gnames, >ypes,
|
||||
&vnames, &vtypes,
|
||||
&enames, &etypes);
|
||||
|
||||
/* graph attributes */
|
||||
for (i = 0; i < igraph_strvector_size(&gnames); i++) {
|
||||
printf("%s=", igraph_strvector_get(&gnames, i));
|
||||
if (VECTOR(gtypes)[i] == IGRAPH_ATTRIBUTE_NUMERIC) {
|
||||
igraph_real_printf(GAN(g, igraph_strvector_get(&gnames, i)));
|
||||
putchar(' ');
|
||||
} else {
|
||||
printf("\"%s\" ", GAS(g, igraph_strvector_get(&gnames, i)));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/* vertex attributes */
|
||||
for (i = 0; i < igraph_vcount(g); i++) {
|
||||
printf("Vertex %" IGRAPH_PRId ": ", i);
|
||||
for (j = 0; j < igraph_strvector_size(&vnames); j++) {
|
||||
printf("%s=", igraph_strvector_get(&vnames, j));
|
||||
if (VECTOR(vtypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
|
||||
igraph_real_printf(VAN(g, igraph_strvector_get(&vnames, j), i));
|
||||
putchar(' ');
|
||||
} else {
|
||||
printf("\"%s\" ", VAS(g, igraph_strvector_get(&vnames, j), i));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* edge attributes */
|
||||
for (i = 0; i < igraph_ecount(g); i++) {
|
||||
printf("Edge %" IGRAPH_PRId " (%" IGRAPH_PRId "-%" IGRAPH_PRId "): ", i, IGRAPH_FROM(g, i), IGRAPH_TO(g, i));
|
||||
for (j = 0; j < igraph_strvector_size(&enames); j++) {
|
||||
printf("%s=", igraph_strvector_get(&enames, j));
|
||||
if (VECTOR(etypes)[j] == IGRAPH_ATTRIBUTE_NUMERIC) {
|
||||
igraph_real_printf(EAN(g, igraph_strvector_get(&enames, j), i));
|
||||
putchar(' ');
|
||||
} else {
|
||||
printf("\"%s\" ", EAS(g, igraph_strvector_get(&enames, j), i));
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
igraph_strvector_destroy(&enames);
|
||||
igraph_strvector_destroy(&vnames);
|
||||
igraph_strvector_destroy(&gnames);
|
||||
igraph_vector_int_destroy(&etypes);
|
||||
igraph_vector_int_destroy(&vtypes);
|
||||
igraph_vector_int_destroy(>ypes);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_t y;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Turn on attribute handling. */
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
igraph_small(&graph, 3, IGRAPH_DIRECTED, 0,1, 1,2, -1);
|
||||
|
||||
/* Set graph attributes. */
|
||||
/* numeric */
|
||||
SETGAN(&graph, "id", 10);
|
||||
/* string */
|
||||
SETGAS(&graph, "name", "toy");
|
||||
/* boolean */
|
||||
SETGAB(&graph, "is_regular", false);
|
||||
|
||||
/* Set edge string attribute. */
|
||||
SETEAS(&graph, "color", 1, "RED");
|
||||
|
||||
/* Set vertex attributes as vector. */
|
||||
igraph_vector_init(&y, igraph_vcount(&graph));
|
||||
igraph_vector_fill(&y, 1.23);
|
||||
SETVANV(&graph, "y", &y);
|
||||
igraph_vector_destroy(&y);
|
||||
|
||||
/* Set single vertex numeric attribute. */
|
||||
SETVAN(&graph, "y", 0, -1);
|
||||
|
||||
/* Delete graph attribute. */
|
||||
DELGA(&graph, "is_regular");
|
||||
|
||||
/* Print the final result. */
|
||||
print_attributes(&graph);
|
||||
|
||||
/* Delete all remaining attributes. */
|
||||
DELALL(&graph);
|
||||
|
||||
/* Destroy the graph. */
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
id=10 name="toy"
|
||||
Vertex 0: y=-1
|
||||
Vertex 1: y=1.23
|
||||
Vertex 2: y=1.23
|
||||
Edge 0 (0-1): color=""
|
||||
Edge 1 (1-2): color="RED"
|
||||
@@ -0,0 +1,70 @@
|
||||
/* igraph library.
|
||||
Copyright (C) 2007-2022 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_vector_t y;
|
||||
igraph_warning_handler_t* oldwarnhandler;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Turn on attribute handling. */
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
/* Create a graph, add some attributes and save it as a GraphML file. */
|
||||
igraph_famous(&g, "Petersen");
|
||||
SETGAS(&g, "name", "Petersen's graph");
|
||||
SETGAN(&g, "vertices", igraph_vcount(&g));
|
||||
SETGAN(&g, "edges", igraph_ecount(&g));
|
||||
SETGAB(&g, "famous", true);
|
||||
|
||||
igraph_vector_init_range(&y, 1, igraph_vcount(&g) + 1);
|
||||
SETVANV(&g, "id", &y);
|
||||
igraph_vector_destroy(&y);
|
||||
|
||||
SETVAS(&g, "name", 0, "foo");
|
||||
SETVAS(&g, "name", 1, "foobar");
|
||||
|
||||
SETVAB(&g, "is_first", 0, true);
|
||||
|
||||
igraph_vector_init_range(&y, 1, igraph_ecount(&g) + 1);
|
||||
SETEANV(&g, "id", &y);
|
||||
igraph_vector_destroy(&y);
|
||||
|
||||
SETEAS(&g, "name", 0, "FOO");
|
||||
SETEAS(&g, "name", 1, "FOOBAR");
|
||||
|
||||
SETEAB(&g, "is_first", 0, true);
|
||||
|
||||
/* Turn off the warning handler temporarily because the GML writer will
|
||||
* print warnings about boolean attributes being converted to numbers, and
|
||||
* we don't care about these. */
|
||||
oldwarnhandler = igraph_set_warning_handler(igraph_warning_handler_ignore);
|
||||
igraph_write_graph_gml(&g, stdout, IGRAPH_WRITE_GML_DEFAULT_SW, 0, "");
|
||||
igraph_set_warning_handler(oldwarnhandler);
|
||||
|
||||
/* Back to business. */
|
||||
igraph_write_graph_graphml(&g, stdout, /*prefixattr=*/ true);
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
Version 1
|
||||
graph
|
||||
[
|
||||
directed 0
|
||||
name "Petersen's graph"
|
||||
vertices 10
|
||||
edges 15
|
||||
famous 1
|
||||
node
|
||||
[
|
||||
id 1
|
||||
name "foo"
|
||||
isfirst 1
|
||||
]
|
||||
node
|
||||
[
|
||||
id 2
|
||||
name "foobar"
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 3
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 4
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 5
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 6
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 7
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 8
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 9
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 10
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 2
|
||||
target 1
|
||||
id 1
|
||||
name "FOO"
|
||||
isfirst 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 5
|
||||
target 1
|
||||
id 2
|
||||
name "FOOBAR"
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 6
|
||||
target 1
|
||||
id 3
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 3
|
||||
target 2
|
||||
id 4
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 7
|
||||
target 2
|
||||
id 5
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 4
|
||||
target 3
|
||||
id 6
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 8
|
||||
target 3
|
||||
id 7
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 5
|
||||
target 4
|
||||
id 8
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 9
|
||||
target 4
|
||||
id 9
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 5
|
||||
id 10
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 8
|
||||
target 6
|
||||
id 11
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 9
|
||||
target 6
|
||||
id 12
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 9
|
||||
target 7
|
||||
id 13
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 7
|
||||
id 14
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 8
|
||||
id 15
|
||||
name ""
|
||||
isfirst 0
|
||||
]
|
||||
]
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="g_name" for="graph" attr.name="name" attr.type="string"/>
|
||||
<key id="g_vertices" for="graph" attr.name="vertices" attr.type="double"/>
|
||||
<key id="g_edges" for="graph" attr.name="edges" attr.type="double"/>
|
||||
<key id="g_famous" for="graph" attr.name="famous" attr.type="boolean"/>
|
||||
<key id="v_id" for="node" attr.name="id" attr.type="double"/>
|
||||
<key id="v_name" for="node" attr.name="name" attr.type="string"/>
|
||||
<key id="v_is_first" for="node" attr.name="is_first" attr.type="boolean"/>
|
||||
<key id="e_id" for="edge" attr.name="id" attr.type="double"/>
|
||||
<key id="e_name" for="edge" attr.name="name" attr.type="string"/>
|
||||
<key id="e_is_first" for="edge" attr.name="is_first" attr.type="boolean"/>
|
||||
<graph id="G" edgedefault="undirected">
|
||||
<data key="g_name">Petersen's graph</data>
|
||||
<data key="g_vertices">10</data>
|
||||
<data key="g_edges">15</data>
|
||||
<data key="g_famous">true</data>
|
||||
<node id="n0">
|
||||
<data key="v_id">1</data>
|
||||
<data key="v_name">foo</data>
|
||||
<data key="v_is_first">true</data>
|
||||
</node>
|
||||
<node id="n1">
|
||||
<data key="v_id">2</data>
|
||||
<data key="v_name">foobar</data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n2">
|
||||
<data key="v_id">3</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n3">
|
||||
<data key="v_id">4</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n4">
|
||||
<data key="v_id">5</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n5">
|
||||
<data key="v_id">6</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n6">
|
||||
<data key="v_id">7</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n7">
|
||||
<data key="v_id">8</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n8">
|
||||
<data key="v_id">9</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<node id="n9">
|
||||
<data key="v_id">10</data>
|
||||
<data key="v_name"></data>
|
||||
<data key="v_is_first">false</data>
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_id">1</data>
|
||||
<data key="e_name">FOO</data>
|
||||
<data key="e_is_first">true</data>
|
||||
</edge>
|
||||
<edge source="n0" target="n4">
|
||||
<data key="e_id">2</data>
|
||||
<data key="e_name">FOOBAR</data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n0" target="n5">
|
||||
<data key="e_id">3</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_id">4</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n6">
|
||||
<data key="e_id">5</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_id">6</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n7">
|
||||
<data key="e_id">7</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n3" target="n4">
|
||||
<data key="e_id">8</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n3" target="n8">
|
||||
<data key="e_id">9</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n4" target="n9">
|
||||
<data key="e_id">10</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n5" target="n7">
|
||||
<data key="e_id">11</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n5" target="n8">
|
||||
<data key="e_id">12</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n6" target="n8">
|
||||
<data key="e_id">13</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n6" target="n9">
|
||||
<data key="e_id">14</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
<edge source="n7" target="n9">
|
||||
<data key="e_id">15</data>
|
||||
<data key="e_name"></data>
|
||||
<data key="e_is_first">false</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
igraph_error_t mf(const igraph_vector_t *input, igraph_real_t *output) {
|
||||
*output = 0.0;
|
||||
return IGRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
static void simplify_write_destroy(igraph_t *g, igraph_attribute_combination_t *comb) {
|
||||
igraph_simplify(g, /*remove_multiple=*/ true, /*remove_loops=*/ true, comb);
|
||||
igraph_write_graph_graphml(g, stdout, /*prefixattr=*/ true);
|
||||
igraph_attribute_combination_destroy(comb);
|
||||
igraph_destroy(g);
|
||||
}
|
||||
|
||||
static void weight_test(igraph_t *g, igraph_attribute_combination_type_t weight_attr) {
|
||||
igraph_t g2;
|
||||
igraph_attribute_combination_t comb;
|
||||
|
||||
igraph_copy(&g2, g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"weight", weight_attr,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g, g2;
|
||||
igraph_vector_t weight;
|
||||
igraph_attribute_combination_t comb;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
igraph_small(&g, 4, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 1, 0, 1,
|
||||
1, 2, 2, 3,
|
||||
-1);
|
||||
|
||||
igraph_vector_init_range(&weight, 1, igraph_ecount(&g) + 1);
|
||||
SETEANV(&g, "weight", &weight);
|
||||
igraph_vector_destroy(&weight);
|
||||
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_SUM);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_PROD);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MIN);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MAX);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_FIRST);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_LAST);
|
||||
weight_test(&g, IGRAPH_ATTRIBUTE_COMBINE_MEAN);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_copy(&g2, &g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"weight", IGRAPH_ATTRIBUTE_COMBINE_FUNCTION, mf,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_copy(&g2, &g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_MEAN,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">6</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">6</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">1</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">3</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">1</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">3</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">2</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">0</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">0</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">0</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_weight">2</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_weight">4</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_weight">5</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2021 The igraph development team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
static void simplify_write_destroy(igraph_t *g, igraph_attribute_combination_t *comb) {
|
||||
igraph_simplify(g, /*remove_multiple=*/ true, /*remove_loops=*/ true, comb);
|
||||
igraph_write_graph_graphml(g, stdout, /*prefixattr=*/ true);
|
||||
igraph_attribute_combination_destroy(comb);
|
||||
igraph_destroy(g);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g, g2;
|
||||
igraph_attribute_combination_t comb;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
igraph_small(&g, 4, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 1, 0, 1,
|
||||
1, 2, 2, 3,
|
||||
-1);
|
||||
|
||||
SETEAS(&g, "color", 0, "green");
|
||||
SETEAS(&g, "color", 1, "red");
|
||||
SETEAS(&g, "color", 2, "blue");
|
||||
SETEAS(&g, "color", 3, "white");
|
||||
SETEAS(&g, "color", 4, "black");
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_copy(&g2, &g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
|
||||
"color", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_copy(&g2, &g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_LAST,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_copy(&g2, &g);
|
||||
igraph_attribute_combination(&comb,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
|
||||
"color", IGRAPH_ATTRIBUTE_COMBINE_CONCAT,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
simplify_write_destroy(&g2, &comb);
|
||||
|
||||
/* ****************************************************** */
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_color" for="edge" attr.name="color" attr.type="string"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_color">green</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_color">white</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_color">black</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_color" for="edge" attr.name="color" attr.type="string"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_color">blue</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_color">white</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_color">black</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_color" for="edge" attr.name="color" attr.type="string"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<node id="n2">
|
||||
</node>
|
||||
<node id="n3">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_color">greenredblue</data>
|
||||
</edge>
|
||||
<edge source="n1" target="n2">
|
||||
<data key="e_color">green</data>
|
||||
</edge>
|
||||
<edge source="n2" target="n3">
|
||||
<data key="e_color">green</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t graph;
|
||||
igraph_real_t cent;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create an undirected star graph, which is the most centralized graph
|
||||
* with several common centrality scores. */
|
||||
printf("undirected star graph:\n");
|
||||
igraph_star(&graph, 10, IGRAPH_STAR_UNDIRECTED, /*center=*/ 0);
|
||||
|
||||
igraph_centralization_degree(&graph, /*res=*/ NULL,
|
||||
/*mode=*/ IGRAPH_ALL, IGRAPH_NO_LOOPS,
|
||||
¢, /*theoretical_max=*/ NULL,
|
||||
/*normalized=*/ true);
|
||||
printf("degree centralization: %g\n", cent);
|
||||
|
||||
igraph_centralization_betweenness(&graph, /*res=*/ NULL,
|
||||
IGRAPH_UNDIRECTED, ¢,
|
||||
/*theoretical_max=*/ NULL,
|
||||
/*normalized=*/ true);
|
||||
printf("betweenness centralization: %g\n", cent);
|
||||
|
||||
|
||||
igraph_centralization_closeness(&graph, /*res=*/ NULL,
|
||||
IGRAPH_ALL, ¢,
|
||||
/*theoretical_max=*/ NULL,
|
||||
/*normalized=*/ true);
|
||||
printf("closeness centralization: %g\n", cent);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
/* With eigenvector centrality, the most centralized structure is
|
||||
* a graph containing a single edge. */
|
||||
printf("\ngraph with single edge:\n");
|
||||
igraph_small(&graph, /*n=*/ 10, IGRAPH_UNDIRECTED,
|
||||
0,1, -1);
|
||||
|
||||
igraph_centralization_eigenvector_centrality(
|
||||
&graph,
|
||||
/*vector=*/ NULL,
|
||||
/*value=*/ NULL,
|
||||
/*mode=*/ IGRAPH_ALL,
|
||||
/*options=*/ NULL,
|
||||
¢,
|
||||
/*theoretical_max=*/ NULL,
|
||||
/*normalized=*/ true);
|
||||
printf("eigenvector centralization: %g\n", cent);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
undirected star graph:
|
||||
degree centralization: 1
|
||||
betweenness centralization: 1
|
||||
closeness centralization: 1
|
||||
|
||||
graph with single edge:
|
||||
eigenvector centralization: 1
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
igraph_vector_int_list_t blocks;
|
||||
igraph_vector_int_t cohesion;
|
||||
igraph_vector_int_t parent;
|
||||
igraph_t block_tree;
|
||||
igraph_int_t i;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_famous(&g, "zachary");
|
||||
igraph_vector_int_list_init(&blocks, 0);
|
||||
igraph_vector_int_init(&cohesion, 0);
|
||||
igraph_vector_int_init(&parent, 0);
|
||||
|
||||
igraph_cohesive_blocks(&g, &blocks, &cohesion, &parent,
|
||||
&block_tree);
|
||||
|
||||
printf("Blocks:\n");
|
||||
for (i = 0; i < igraph_vector_int_list_size(&blocks); i++) {
|
||||
igraph_vector_int_t *sg = igraph_vector_int_list_get_ptr(&blocks, i);
|
||||
printf(" ");
|
||||
igraph_vector_int_print(sg);
|
||||
}
|
||||
printf("Cohesion:\n ");
|
||||
igraph_vector_int_print(&cohesion);
|
||||
printf("Parents:\n ");
|
||||
igraph_vector_int_print(&parent);
|
||||
printf("Block graph:\n");
|
||||
igraph_write_graph_edgelist(&block_tree, stdout);
|
||||
|
||||
igraph_vector_int_list_destroy(&blocks);
|
||||
igraph_vector_int_destroy(&cohesion);
|
||||
igraph_vector_int_destroy(&parent);
|
||||
igraph_destroy(&block_tree);
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
Blocks:
|
||||
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
||||
0 1 2 3 7 8 9 12 13 14 15 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
||||
0 4 5 6 10 16
|
||||
0 1 2 3 7
|
||||
0 1 2 8 30 32 33
|
||||
0 4 5 6 10
|
||||
0 1 2 3 13
|
||||
2 23 24 25 27 28 29 31 32 33
|
||||
Cohesion:
|
||||
1 2 2 4 3 3 4 3
|
||||
Parents:
|
||||
-1 0 0 1 1 2 1 1
|
||||
Block graph:
|
||||
0 1
|
||||
0 2
|
||||
1 3
|
||||
1 4
|
||||
1 6
|
||||
1 7
|
||||
2 5
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2017-2025 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t colors;
|
||||
igraph_bool_t valid_coloring;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Setting a seed makes the result of erdos_renyi_game_gnm deterministic. */
|
||||
igraph_rng_seed(igraph_rng_default(), 42);
|
||||
|
||||
/* IGRAPH_UNDIRECTED and IGRAPH_NO_LOOPS are both equivalent to 0/FALSE, but
|
||||
communicate intent better in this context. */
|
||||
igraph_erdos_renyi_game_gnm(&graph, 1000, 10000, IGRAPH_UNDIRECTED, IGRAPH_SIMPLE_SW, IGRAPH_EDGE_UNLABELED);
|
||||
|
||||
/* As with all igraph functions, the vector in which the result is returned must
|
||||
be initialized in advance. */
|
||||
igraph_vector_int_init(&colors, 0);
|
||||
igraph_vertex_coloring_greedy(&graph, &colors, IGRAPH_COLORING_GREEDY_COLORED_NEIGHBORS);
|
||||
|
||||
/* Verify that the colouring is valid, i.e. no two adjacent vertices have the same colour. */
|
||||
igraph_is_vertex_coloring(&graph, &colors, &valid_coloring);
|
||||
IGRAPH_ASSERT(valid_coloring);
|
||||
|
||||
/* Destroy data structure when we are done. */
|
||||
igraph_vector_int_destroy(&colors);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
|
||||
#include <igraph.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t edges;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a directed graph with no vertices or edges. */
|
||||
igraph_empty(&graph, 0, IGRAPH_DIRECTED);
|
||||
|
||||
/* Add 5 vertices. Vertex IDs will range from 0 to 4, inclusive. */
|
||||
igraph_add_vertices(&graph, 5, NULL);
|
||||
|
||||
/* Add 5 edges, specified as 5 consecutive pairs of vertex IDs
|
||||
* stored in an integer vector. */
|
||||
igraph_vector_int_init_int(&edges, 10,
|
||||
0,1, 0,2, 3,1, 2,1, 0,4);
|
||||
igraph_add_edges(&graph, &edges, NULL);
|
||||
|
||||
igraph_vector_int_destroy(&edges);
|
||||
|
||||
/* Now the graph has 5 vertices and 5 edges. */
|
||||
assert(igraph_vcount(&graph) == 5);
|
||||
assert(igraph_ecount(&graph) == 5);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2008-2022 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t graph;
|
||||
igraph_real_t weights_data[] = { 0, 2, 1, 0, 5, 2, 1, 1, 0, 2, 2, 8, 1, 1, 3, 1, 1, 4, 2, 1 };
|
||||
const igraph_vector_t weights =
|
||||
igraph_vector_view(weights_data, sizeof(weights_data) / sizeof(weights_data[0]));
|
||||
igraph_matrix_t res;
|
||||
igraph_real_t cutoff;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_small(&graph, 10, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 2, 0, 3, 1, 2, 1, 4, 1, 5,
|
||||
2, 3, 2, 6, 3, 2, 3, 6,
|
||||
4, 5, 4, 7, 5, 6, 5, 8, 5, 9,
|
||||
7, 5, 7, 8, 8, 9,
|
||||
5, 2,
|
||||
2, 1,
|
||||
-1);
|
||||
|
||||
igraph_matrix_init(&res, 0, 0);
|
||||
|
||||
printf("Unweighted distances:\n\n");
|
||||
|
||||
igraph_distances(&graph, NULL, &res, igraph_vss_all(), igraph_vss_all(), IGRAPH_OUT);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
cutoff = 3; /* distances longer than this will be returned as infinity */
|
||||
printf("\nUnweighted distances with a cutoff of %g:\n\n", cutoff);
|
||||
igraph_distances_cutoff(&graph, NULL, &res, igraph_vss_all(), igraph_vss_all(), IGRAPH_OUT, cutoff);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
printf("\nWeighted distances:\n\n");
|
||||
|
||||
igraph_distances(&graph, &weights, &res, igraph_vss_all(), igraph_vss_all(), IGRAPH_OUT);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
cutoff = 8; /* distances longer than this will be returned as infinity */
|
||||
printf("\nWeighted distances with a cutoff of %g:\n\n", cutoff);
|
||||
igraph_distances_cutoff(&graph, &weights, &res, igraph_vss_all(), igraph_vss_all(), IGRAPH_OUT, cutoff);
|
||||
igraph_matrix_print(&res);
|
||||
|
||||
igraph_matrix_destroy(&res);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
Unweighted distances:
|
||||
|
||||
0 1 1 1 2 2 2 3 3 3
|
||||
Inf 0 1 2 1 1 2 2 2 2
|
||||
Inf 1 0 1 2 2 1 3 3 3
|
||||
Inf 2 1 0 3 3 1 4 4 4
|
||||
Inf 3 2 3 0 1 2 1 2 2
|
||||
Inf 2 1 2 3 0 1 4 1 1
|
||||
Inf Inf Inf Inf Inf Inf 0 Inf Inf Inf
|
||||
Inf 3 2 3 4 1 2 0 1 2
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf 0 1
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0
|
||||
|
||||
Unweighted distances with a cutoff of 3:
|
||||
|
||||
0 1 1 1 2 2 2 3 3 3
|
||||
Inf 0 1 2 1 1 2 2 2 2
|
||||
Inf 1 0 1 2 2 1 3 3 3
|
||||
Inf 2 1 0 3 3 1 Inf Inf Inf
|
||||
Inf 3 2 3 0 1 2 1 2 2
|
||||
Inf 2 1 2 3 0 1 Inf 1 1
|
||||
Inf Inf Inf Inf Inf Inf 0 Inf Inf Inf
|
||||
Inf 3 2 3 Inf 1 2 0 1 2
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf 0 1
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0
|
||||
|
||||
Weighted distances:
|
||||
|
||||
0 0 0 1 5 2 1 13 3 5
|
||||
Inf 0 0 1 5 2 1 13 3 5
|
||||
Inf 1 0 1 6 3 1 14 4 6
|
||||
Inf 1 0 0 6 3 1 14 4 6
|
||||
Inf 5 4 5 0 2 3 8 3 5
|
||||
Inf 3 2 3 8 0 1 16 1 3
|
||||
Inf Inf Inf Inf Inf Inf 0 Inf Inf Inf
|
||||
Inf 4 3 4 9 1 2 0 1 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf 0 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0
|
||||
|
||||
Weighted distances with a cutoff of 8:
|
||||
|
||||
0 0 0 1 5 2 1 Inf 3 5
|
||||
Inf 0 0 1 5 2 1 Inf 3 5
|
||||
Inf 1 0 1 6 3 1 Inf 4 6
|
||||
Inf 1 0 0 6 3 1 Inf 4 6
|
||||
Inf 5 4 5 0 2 3 8 3 5
|
||||
Inf 3 2 3 8 0 1 Inf 1 3
|
||||
Inf Inf Inf Inf Inf Inf 0 Inf Inf Inf
|
||||
Inf 4 3 4 Inf 1 2 0 1 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf 0 4
|
||||
Inf Inf Inf Inf Inf Inf Inf Inf Inf 0
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g, domtree;
|
||||
igraph_vector_int_t dom;
|
||||
igraph_vector_int_t leftout;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_int_init(&dom, 0);
|
||||
igraph_vector_int_init(&leftout, 0);
|
||||
|
||||
igraph_small(&g, 10, IGRAPH_DIRECTED,
|
||||
0, 9,
|
||||
1, 0, 1, 2,
|
||||
2, 3, 2, 7,
|
||||
3, 1,
|
||||
4, 1, 4, 3,
|
||||
5, 2, 5, 3, 5, 4, 5, 8,
|
||||
6, 5, 6, 9,
|
||||
8, 7,
|
||||
-1);
|
||||
|
||||
igraph_dominator_tree(&g, /*root=*/ 9, &dom, &domtree,
|
||||
&leftout, /*mode=*/ IGRAPH_IN);
|
||||
igraph_vector_int_print(&dom);
|
||||
igraph_vector_int_print(&leftout);
|
||||
igraph_write_graph_edgelist(&domtree, stdout);
|
||||
|
||||
igraph_vector_int_destroy(&dom);
|
||||
igraph_vector_int_destroy(&leftout);
|
||||
igraph_destroy(&domtree);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
9 0 3 1 1 1 9 -2 -2 -1
|
||||
7 8
|
||||
0 9
|
||||
1 0
|
||||
2 3
|
||||
3 1
|
||||
4 1
|
||||
5 1
|
||||
6 9
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
FILE *ifile;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
ifile = fopen("karate.gml", "r");
|
||||
if (ifile == 0) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
igraph_read_graph_gml(&g, ifile);
|
||||
fclose(ifile);
|
||||
|
||||
if (igraph_is_directed(&g)) {
|
||||
printf("directed\n");
|
||||
} else {
|
||||
printf("undirected\n");
|
||||
}
|
||||
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
printf("-----------------\n");
|
||||
igraph_write_graph_dot(&g, stdout);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
undirected
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
0 5
|
||||
0 6
|
||||
0 7
|
||||
0 8
|
||||
0 10
|
||||
0 11
|
||||
0 12
|
||||
0 13
|
||||
0 17
|
||||
0 19
|
||||
0 21
|
||||
0 31
|
||||
1 2
|
||||
1 3
|
||||
1 7
|
||||
1 13
|
||||
1 17
|
||||
1 19
|
||||
1 21
|
||||
1 30
|
||||
2 3
|
||||
2 7
|
||||
2 8
|
||||
2 9
|
||||
2 13
|
||||
2 27
|
||||
2 28
|
||||
2 32
|
||||
3 7
|
||||
3 12
|
||||
3 13
|
||||
4 6
|
||||
4 10
|
||||
5 6
|
||||
5 10
|
||||
5 16
|
||||
6 16
|
||||
8 30
|
||||
8 32
|
||||
8 33
|
||||
9 33
|
||||
13 33
|
||||
14 32
|
||||
14 33
|
||||
15 32
|
||||
15 33
|
||||
18 32
|
||||
18 33
|
||||
19 33
|
||||
20 32
|
||||
20 33
|
||||
22 32
|
||||
22 33
|
||||
23 25
|
||||
23 27
|
||||
23 29
|
||||
23 32
|
||||
23 33
|
||||
24 25
|
||||
24 27
|
||||
24 31
|
||||
25 31
|
||||
26 29
|
||||
26 33
|
||||
27 33
|
||||
28 31
|
||||
28 33
|
||||
29 32
|
||||
29 33
|
||||
30 32
|
||||
30 33
|
||||
31 32
|
||||
31 33
|
||||
32 33
|
||||
-----------------
|
||||
/* Created by igraph @VERSION@ */
|
||||
graph {
|
||||
0;
|
||||
1;
|
||||
2;
|
||||
3;
|
||||
4;
|
||||
5;
|
||||
6;
|
||||
7;
|
||||
8;
|
||||
9;
|
||||
10;
|
||||
11;
|
||||
12;
|
||||
13;
|
||||
14;
|
||||
15;
|
||||
16;
|
||||
17;
|
||||
18;
|
||||
19;
|
||||
20;
|
||||
21;
|
||||
22;
|
||||
23;
|
||||
24;
|
||||
25;
|
||||
26;
|
||||
27;
|
||||
28;
|
||||
29;
|
||||
30;
|
||||
31;
|
||||
32;
|
||||
33;
|
||||
|
||||
1 -- 0;
|
||||
2 -- 0;
|
||||
2 -- 1;
|
||||
3 -- 0;
|
||||
3 -- 1;
|
||||
3 -- 2;
|
||||
4 -- 0;
|
||||
5 -- 0;
|
||||
6 -- 0;
|
||||
6 -- 4;
|
||||
6 -- 5;
|
||||
7 -- 0;
|
||||
7 -- 1;
|
||||
7 -- 2;
|
||||
7 -- 3;
|
||||
8 -- 0;
|
||||
8 -- 2;
|
||||
9 -- 2;
|
||||
10 -- 0;
|
||||
10 -- 4;
|
||||
10 -- 5;
|
||||
11 -- 0;
|
||||
12 -- 0;
|
||||
12 -- 3;
|
||||
13 -- 0;
|
||||
13 -- 1;
|
||||
13 -- 2;
|
||||
13 -- 3;
|
||||
16 -- 5;
|
||||
16 -- 6;
|
||||
17 -- 0;
|
||||
17 -- 1;
|
||||
19 -- 0;
|
||||
19 -- 1;
|
||||
21 -- 0;
|
||||
21 -- 1;
|
||||
25 -- 23;
|
||||
25 -- 24;
|
||||
27 -- 2;
|
||||
27 -- 23;
|
||||
27 -- 24;
|
||||
28 -- 2;
|
||||
29 -- 23;
|
||||
29 -- 26;
|
||||
30 -- 1;
|
||||
30 -- 8;
|
||||
31 -- 0;
|
||||
31 -- 24;
|
||||
31 -- 25;
|
||||
31 -- 28;
|
||||
32 -- 2;
|
||||
32 -- 8;
|
||||
32 -- 14;
|
||||
32 -- 15;
|
||||
32 -- 18;
|
||||
32 -- 20;
|
||||
32 -- 22;
|
||||
32 -- 23;
|
||||
32 -- 29;
|
||||
32 -- 30;
|
||||
32 -- 31;
|
||||
33 -- 8;
|
||||
33 -- 9;
|
||||
33 -- 13;
|
||||
33 -- 14;
|
||||
33 -- 15;
|
||||
33 -- 18;
|
||||
33 -- 19;
|
||||
33 -- 20;
|
||||
33 -- 22;
|
||||
33 -- 23;
|
||||
33 -- 26;
|
||||
33 -- 27;
|
||||
33 -- 28;
|
||||
33 -- 29;
|
||||
33 -- 30;
|
||||
33 -- 31;
|
||||
33 -- 32;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_dqueue_t q;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* igraph_dqueue_init, igraph_dqueue_destroy, igraph_dqueue_empty */
|
||||
igraph_dqueue_init(&q, 5);
|
||||
if (!igraph_dqueue_empty(&q)) {
|
||||
return 1;
|
||||
}
|
||||
igraph_dqueue_destroy(&q);
|
||||
|
||||
/* igraph_dqueue_push, igraph_dqueue_pop */
|
||||
igraph_dqueue_init(&q, 4);
|
||||
igraph_dqueue_push(&q, 1);
|
||||
igraph_dqueue_push(&q, 2);
|
||||
igraph_dqueue_push(&q, 3);
|
||||
igraph_dqueue_push(&q, 4);
|
||||
if (igraph_dqueue_pop(&q) != 1) {
|
||||
return 2;
|
||||
}
|
||||
if (igraph_dqueue_pop(&q) != 2) {
|
||||
return 3;
|
||||
}
|
||||
if (igraph_dqueue_pop(&q) != 3) {
|
||||
return 4;
|
||||
}
|
||||
if (igraph_dqueue_pop(&q) != 4) {
|
||||
return 5;
|
||||
}
|
||||
igraph_dqueue_destroy(&q);
|
||||
|
||||
/* igraph_dqueue_clear, igraph_dqueue_size */
|
||||
igraph_dqueue_init(&q, 0);
|
||||
if (igraph_dqueue_size(&q) != 0) {
|
||||
return 6;
|
||||
}
|
||||
igraph_dqueue_clear(&q);
|
||||
if (igraph_dqueue_size(&q) != 0) {
|
||||
return 7;
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
igraph_dqueue_push(&q, i);
|
||||
}
|
||||
igraph_dqueue_clear(&q);
|
||||
if (igraph_dqueue_size(&q) != 0) {
|
||||
return 8;
|
||||
}
|
||||
igraph_dqueue_destroy(&q);
|
||||
|
||||
/* TODO: igraph_dqueue_full */
|
||||
|
||||
/* igraph_dqueue_head, igraph_dqueue_back, igraph_dqueue_pop_back */
|
||||
igraph_dqueue_init(&q, 0);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
igraph_dqueue_push(&q, i);
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (igraph_dqueue_head(&q) != 0) {
|
||||
return 9;
|
||||
}
|
||||
if (igraph_dqueue_back(&q) != 9 - i) {
|
||||
return 10;
|
||||
}
|
||||
if (igraph_dqueue_pop_back(&q) != 9 - i) {
|
||||
return 11;
|
||||
}
|
||||
}
|
||||
igraph_dqueue_destroy(&q);
|
||||
|
||||
/* print */
|
||||
igraph_dqueue_init(&q, 4);
|
||||
igraph_dqueue_push(&q, 1);
|
||||
igraph_dqueue_push(&q, 2);
|
||||
igraph_dqueue_push(&q, 3);
|
||||
igraph_dqueue_push(&q, 4);
|
||||
igraph_dqueue_pop(&q);
|
||||
igraph_dqueue_pop(&q);
|
||||
igraph_dqueue_push(&q, 5);
|
||||
igraph_dqueue_push(&q, 6);
|
||||
igraph_dqueue_print(&q);
|
||||
|
||||
igraph_dqueue_clear(&q);
|
||||
igraph_dqueue_print(&q);
|
||||
|
||||
igraph_dqueue_destroy(&q);
|
||||
|
||||
if (IGRAPH_FINALLY_STACK_SIZE() != 0) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
3 4 5 6
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels:
|
||||
george, sally, jim, billy, jane
|
||||
data:
|
||||
1 2
|
||||
1 3
|
||||
2 3
|
||||
3 1
|
||||
4 3
|
||||
@@ -0,0 +1,9 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels embedded:
|
||||
data:
|
||||
george sally
|
||||
george jim
|
||||
sally jim
|
||||
billy george
|
||||
jane jim
|
||||
@@ -0,0 +1,11 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels:
|
||||
george, sally, jim, billy, jane
|
||||
labels embedded:
|
||||
data:
|
||||
george sally
|
||||
george jim
|
||||
sally jim
|
||||
billy george
|
||||
jane jim
|
||||
@@ -0,0 +1,10 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels:
|
||||
george, sally, jim, billy, jane
|
||||
data:
|
||||
1 2
|
||||
1 3 -1
|
||||
2 3
|
||||
3 1 -1
|
||||
4 3
|
||||
@@ -0,0 +1,9 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels embedded:
|
||||
data:
|
||||
george sally 0.1
|
||||
george jim 0.5
|
||||
sally jim
|
||||
billy george 1
|
||||
jane jim
|
||||
@@ -0,0 +1,11 @@
|
||||
DL n=5
|
||||
format = edgelist1
|
||||
labels:
|
||||
george, sally, jim, billy, jane
|
||||
labels embedded:
|
||||
data:
|
||||
george sally
|
||||
george jim 2
|
||||
sally jim
|
||||
billy george 1
|
||||
jane jim 1e-5
|
||||
@@ -0,0 +1,6 @@
|
||||
DL n=4
|
||||
format = edgelist1
|
||||
data:
|
||||
1 2
|
||||
2 3
|
||||
2 4
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t graph;
|
||||
igraph_vector_t vector, weights;
|
||||
igraph_real_t value;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a star graph, with vertex 0 at the center, and associated edge weights. */
|
||||
igraph_star(&graph, 10, IGRAPH_STAR_UNDIRECTED, 0);
|
||||
igraph_vector_init_range(&weights, 1, igraph_ecount(&graph)+1);
|
||||
|
||||
/* Initialize the vector where the result will be stored. */
|
||||
igraph_vector_init(&vector, 0);
|
||||
|
||||
/* Compute eigenvector centrality. */
|
||||
igraph_eigenvector_centrality(&graph, &vector, &value, IGRAPH_OUT,
|
||||
&weights, /*options=*/ NULL);
|
||||
|
||||
/* Print results. */
|
||||
printf("eigenvalue: %g\n", value);
|
||||
printf("eigenvector:\n");
|
||||
igraph_vector_print(&vector);
|
||||
|
||||
/* Free allocated data structures. */
|
||||
igraph_vector_destroy(&vector);
|
||||
igraph_vector_destroy(&weights);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
eigenvalue: 16.8819
|
||||
eigenvector:
|
||||
1 0.0592349 0.11847 0.177705 0.23694 0.296174 0.355409 0.414644 0.473879 0.533114
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <limits.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g, gbar;
|
||||
igraph_int_t k1, k2 = INT_MAX;
|
||||
igraph_real_t tmpk;
|
||||
igraph_int_t i, j, n;
|
||||
igraph_maxflow_stats_t stats;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_famous(&g, "meredith");
|
||||
igraph_even_tarjan_reduction(&g, &gbar, /*capacity=*/ NULL);
|
||||
|
||||
igraph_vertex_connectivity(&g, &k1, /* checks= */ false);
|
||||
|
||||
n = igraph_vcount(&g);
|
||||
for (i = 0; i < n; i++) {
|
||||
for (j = i + 1; j < n; j++) {
|
||||
igraph_bool_t conn;
|
||||
igraph_are_adjacent(&g, i, j, &conn);
|
||||
if (conn) {
|
||||
continue;
|
||||
}
|
||||
igraph_maxflow_value(&gbar, &tmpk,
|
||||
/* source= */ i + n,
|
||||
/* target= */ j,
|
||||
/* capacity= */ 0,
|
||||
&stats);
|
||||
if (tmpk < k2) {
|
||||
k2 = tmpk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
igraph_destroy(&gbar);
|
||||
igraph_destroy(&g);
|
||||
|
||||
if (k1 != k2) {
|
||||
printf("k1 = %" IGRAPH_PRId " while k2 = %" IGRAPH_PRId "\n", k1, k2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_real_t flow;
|
||||
igraph_vector_t capacity;
|
||||
igraph_int_t source, target;
|
||||
FILE *infile;
|
||||
igraph_maxflow_stats_t stats;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_init(&capacity, 0);
|
||||
|
||||
/***************/
|
||||
infile = fopen("ak-4102.max", "r");
|
||||
igraph_read_graph_dimacs_flow(
|
||||
&g, infile, 0, 0, &source, &target, &capacity, IGRAPH_DIRECTED);
|
||||
fclose(infile);
|
||||
|
||||
igraph_maxflow_value(&g, &flow, source, target, &capacity, &stats);
|
||||
|
||||
if (flow != 8207) {
|
||||
return 1;
|
||||
}
|
||||
igraph_destroy(&g);
|
||||
/***************/
|
||||
|
||||
/* /\***************\/ */
|
||||
/* infile=fopen("ak-8198.max", "r"); */
|
||||
/* igraph_read_graph_dimacs_flow(&g, infile, 0, 0, &source, &target, &capacity, */
|
||||
/* IGRAPH_DIRECTED); */
|
||||
/* fclose(infile); */
|
||||
|
||||
/* t=timer(); */
|
||||
/* igraph_maxflow_value(&g, &flow, source, target, &capacity, &stats); */
|
||||
/* t=timer()-t; */
|
||||
/* printf("8198: %g (time %.10f)\n", flow, t); */
|
||||
/* igraph_destroy(&g); */
|
||||
/* /\***************\/ */
|
||||
|
||||
/* /\***************\/ */
|
||||
/* infile=fopen("ak-16390.max", "r"); */
|
||||
/* igraph_read_graph_dimacs_flow(&g, infile, 0, 0, &source, &target, &capacity, */
|
||||
/* IGRAPH_DIRECTED); */
|
||||
/* fclose(infile); */
|
||||
|
||||
/* t=timer(); */
|
||||
/* igraph_maxflow_value(&g, &flow, source, target, &capacity, &stats); */
|
||||
/* t=timer()-t; */
|
||||
/* printf("16390: %g (time %.10f)\n", flow, t); */
|
||||
/* igraph_destroy(&g); */
|
||||
/* /\***************\/ */
|
||||
|
||||
/* /\***************\/ */
|
||||
/* infile=fopen("ak-32774.max", "r"); */
|
||||
/* igraph_read_graph_dimacs_flow(&g, infile, 0, 0, &source, &target, &capacity, */
|
||||
/* IGRAPH_DIRECTED); */
|
||||
/* fclose(infile); */
|
||||
|
||||
/* t=timer(); */
|
||||
/* igraph_maxflow_value(&g, &flow, source, target, &capacity, &stats); */
|
||||
/* t=timer()-t; */
|
||||
/* printf("32774: %g (time %.10f)\n", flow, t); */
|
||||
/* igraph_destroy(&g); */
|
||||
/* /\***************\/ */
|
||||
|
||||
/* /\***************\/ */
|
||||
/* infile=fopen("ak-65542.max", "r"); */
|
||||
/* igraph_read_graph_dimacs_flow(&g, infile, 0, 0, &source, &target, &capacity, */
|
||||
/* IGRAPH_DIRECTED); */
|
||||
/* fclose(infile); */
|
||||
|
||||
/* t=timer(); */
|
||||
/* igraph_maxflow_value(&g, &flow, source, target, &capacity, &stats); */
|
||||
/* t=timer()-t; */
|
||||
/* printf("65542: %g (time %.10f)\n", flow, t); */
|
||||
/* igraph_destroy(&g); */
|
||||
/* /\***************\/ */
|
||||
|
||||
igraph_vector_destroy(&capacity);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_setup();
|
||||
|
||||
igraph_t g;
|
||||
igraph_real_t flow_value;
|
||||
igraph_vector_int_t cut;
|
||||
igraph_vector_t capacity;
|
||||
igraph_vector_int_t partition, partition2;
|
||||
igraph_vector_t flow;
|
||||
igraph_int_t i;
|
||||
igraph_maxflow_stats_t stats;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_small(&g, 6, IGRAPH_DIRECTED,
|
||||
0, 1, 1, 2, 2, 3, 0, 5, 5, 4, 4, 3, 3, 0, -1);
|
||||
igraph_vector_init_int_end(&capacity, -1, 3, 1, 2, 10, 1, 3, 2, -1);
|
||||
igraph_vector_int_init(&cut, 0);
|
||||
igraph_vector_int_init(&partition, 0);
|
||||
igraph_vector_int_init(&partition2, 0);
|
||||
igraph_vector_init(&flow, 0);
|
||||
|
||||
igraph_maxflow(&g, &flow_value, &flow, &cut, &partition, &partition2,
|
||||
/*source=*/ 0, /*target=*/ 2, &capacity, &stats);
|
||||
|
||||
igraph_int_t nc = igraph_vector_int_size(&cut);
|
||||
printf("flow value: %g\n", (double) flow_value);
|
||||
printf("flow: ");
|
||||
igraph_vector_print(&flow);
|
||||
printf("first partition: ");
|
||||
igraph_vector_int_print(&partition);
|
||||
printf("second partition: ");
|
||||
igraph_vector_int_print(&partition2);
|
||||
printf("edges in the cut: ");
|
||||
for (i = 0; i < nc; i++) {
|
||||
igraph_int_t edge = VECTOR(cut)[i];
|
||||
igraph_int_t from = IGRAPH_FROM(&g, edge);
|
||||
igraph_int_t to = IGRAPH_TO(&g, edge);
|
||||
printf("%" IGRAPH_PRId "-%" IGRAPH_PRId " (%g), ", from, to, VECTOR(capacity)[edge]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
igraph_vector_int_destroy(&cut);
|
||||
igraph_vector_int_destroy(&partition2);
|
||||
igraph_vector_int_destroy(&partition);
|
||||
igraph_vector_destroy(&capacity);
|
||||
igraph_vector_destroy(&flow);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
flow value: 1
|
||||
flow: 1 1 0 0 0 0 0
|
||||
first partition: 0 1 3 4 5
|
||||
second partition: 2
|
||||
edges in the cut: 1-2 (1),
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
FILE *ifile;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Turn on attribute handling. */
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
/* Read a Pajek file. */
|
||||
ifile = fopen("links.net", "r");
|
||||
if (ifile == 0) {
|
||||
return 10;
|
||||
}
|
||||
igraph_read_graph_pajek(&g, ifile);
|
||||
fclose(ifile);
|
||||
|
||||
/* Write it in edgelist format. */
|
||||
printf("The graph:\n");
|
||||
printf("Vertices: %" IGRAPH_PRId "\n", igraph_vcount(&g));
|
||||
printf("Edges: %" IGRAPH_PRId "\n", igraph_ecount(&g));
|
||||
printf("Directed: %i\n", igraph_is_directed(&g) ? 1 : 0);
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
The graph:
|
||||
Vertices: 4
|
||||
Edges: 7
|
||||
Directed: 1
|
||||
0 0
|
||||
0 1
|
||||
0 2
|
||||
1 0
|
||||
2 2
|
||||
2 3
|
||||
3 1
|
||||
@@ -0,0 +1,7 @@
|
||||
DL N = 5
|
||||
Data:
|
||||
0 1 1 1 1
|
||||
1 0 1 0 0
|
||||
1 1 0 0 1
|
||||
1 0 0 0 0
|
||||
1 0 1 0 0
|
||||
@@ -0,0 +1,10 @@
|
||||
dl n=5
|
||||
format = fullmatrix
|
||||
labels:
|
||||
barry,david,lin,pat,russ
|
||||
data:
|
||||
0 1 1 1 0
|
||||
1 0 0 0 1
|
||||
1 0 0 1 0
|
||||
1 0 1 0 1
|
||||
0 1 0 1 0
|
||||
@@ -0,0 +1,12 @@
|
||||
dl n=5
|
||||
format = fullmatrix
|
||||
labels:
|
||||
barry,david
|
||||
lin,pat
|
||||
russ
|
||||
data:
|
||||
0 1 1 1 0
|
||||
1 0 0 0 1
|
||||
1 0 0 1 0
|
||||
1 0 1 0 1
|
||||
0 1 0 1 0
|
||||
@@ -0,0 +1,10 @@
|
||||
dl n=5
|
||||
format = fullmatrix
|
||||
labels embedded
|
||||
data:
|
||||
larry david lin pat russ
|
||||
Larry 0 1 1 1 0
|
||||
david 1 0 0 0 1
|
||||
Lin 1 0 0 1 0
|
||||
Pat 1 0 1 0 1
|
||||
Russ 0 1 0 1 0
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
FILE *ifile;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
ifile = fopen("karate.gml", "r");
|
||||
if (ifile == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
igraph_read_graph_gml(&graph, ifile);
|
||||
fclose(ifile);
|
||||
|
||||
printf("The graph is %s.\n", igraph_is_directed(&graph) ? "directed" : "undirected");
|
||||
|
||||
/* Output as edge list */
|
||||
printf("\n-----------------\n");
|
||||
igraph_write_graph_edgelist(&graph, stdout);
|
||||
|
||||
/* Output as GML */
|
||||
printf("\n-----------------\n");
|
||||
igraph_write_graph_gml(&graph, stdout,IGRAPH_WRITE_GML_DEFAULT_SW, 0, "");
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
The graph is undirected.
|
||||
|
||||
-----------------
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
0 5
|
||||
0 6
|
||||
0 7
|
||||
0 8
|
||||
0 10
|
||||
0 11
|
||||
0 12
|
||||
0 13
|
||||
0 17
|
||||
0 19
|
||||
0 21
|
||||
0 31
|
||||
1 2
|
||||
1 3
|
||||
1 7
|
||||
1 13
|
||||
1 17
|
||||
1 19
|
||||
1 21
|
||||
1 30
|
||||
2 3
|
||||
2 7
|
||||
2 8
|
||||
2 9
|
||||
2 13
|
||||
2 27
|
||||
2 28
|
||||
2 32
|
||||
3 7
|
||||
3 12
|
||||
3 13
|
||||
4 6
|
||||
4 10
|
||||
5 6
|
||||
5 10
|
||||
5 16
|
||||
6 16
|
||||
8 30
|
||||
8 32
|
||||
8 33
|
||||
9 33
|
||||
13 33
|
||||
14 32
|
||||
14 33
|
||||
15 32
|
||||
15 33
|
||||
18 32
|
||||
18 33
|
||||
19 33
|
||||
20 32
|
||||
20 33
|
||||
22 32
|
||||
22 33
|
||||
23 25
|
||||
23 27
|
||||
23 29
|
||||
23 32
|
||||
23 33
|
||||
24 25
|
||||
24 27
|
||||
24 31
|
||||
25 31
|
||||
26 29
|
||||
26 33
|
||||
27 33
|
||||
28 31
|
||||
28 33
|
||||
29 32
|
||||
29 33
|
||||
30 32
|
||||
30 33
|
||||
31 32
|
||||
31 33
|
||||
32 33
|
||||
|
||||
-----------------
|
||||
Version 1
|
||||
graph
|
||||
[
|
||||
directed 0
|
||||
node
|
||||
[
|
||||
id 0
|
||||
]
|
||||
node
|
||||
[
|
||||
id 1
|
||||
]
|
||||
node
|
||||
[
|
||||
id 2
|
||||
]
|
||||
node
|
||||
[
|
||||
id 3
|
||||
]
|
||||
node
|
||||
[
|
||||
id 4
|
||||
]
|
||||
node
|
||||
[
|
||||
id 5
|
||||
]
|
||||
node
|
||||
[
|
||||
id 6
|
||||
]
|
||||
node
|
||||
[
|
||||
id 7
|
||||
]
|
||||
node
|
||||
[
|
||||
id 8
|
||||
]
|
||||
node
|
||||
[
|
||||
id 9
|
||||
]
|
||||
node
|
||||
[
|
||||
id 10
|
||||
]
|
||||
node
|
||||
[
|
||||
id 11
|
||||
]
|
||||
node
|
||||
[
|
||||
id 12
|
||||
]
|
||||
node
|
||||
[
|
||||
id 13
|
||||
]
|
||||
node
|
||||
[
|
||||
id 14
|
||||
]
|
||||
node
|
||||
[
|
||||
id 15
|
||||
]
|
||||
node
|
||||
[
|
||||
id 16
|
||||
]
|
||||
node
|
||||
[
|
||||
id 17
|
||||
]
|
||||
node
|
||||
[
|
||||
id 18
|
||||
]
|
||||
node
|
||||
[
|
||||
id 19
|
||||
]
|
||||
node
|
||||
[
|
||||
id 20
|
||||
]
|
||||
node
|
||||
[
|
||||
id 21
|
||||
]
|
||||
node
|
||||
[
|
||||
id 22
|
||||
]
|
||||
node
|
||||
[
|
||||
id 23
|
||||
]
|
||||
node
|
||||
[
|
||||
id 24
|
||||
]
|
||||
node
|
||||
[
|
||||
id 25
|
||||
]
|
||||
node
|
||||
[
|
||||
id 26
|
||||
]
|
||||
node
|
||||
[
|
||||
id 27
|
||||
]
|
||||
node
|
||||
[
|
||||
id 28
|
||||
]
|
||||
node
|
||||
[
|
||||
id 29
|
||||
]
|
||||
node
|
||||
[
|
||||
id 30
|
||||
]
|
||||
node
|
||||
[
|
||||
id 31
|
||||
]
|
||||
node
|
||||
[
|
||||
id 32
|
||||
]
|
||||
node
|
||||
[
|
||||
id 33
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 1
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 2
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 2
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 3
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 3
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 3
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 4
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 5
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 6
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 6
|
||||
target 4
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 6
|
||||
target 5
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 7
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 7
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 7
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 7
|
||||
target 3
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 8
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 8
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 9
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 4
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 10
|
||||
target 5
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 11
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 12
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 12
|
||||
target 3
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 13
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 13
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 13
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 13
|
||||
target 3
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 16
|
||||
target 5
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 16
|
||||
target 6
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 17
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 17
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 19
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 19
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 21
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 21
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 25
|
||||
target 23
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 25
|
||||
target 24
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 27
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 27
|
||||
target 23
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 27
|
||||
target 24
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 28
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 29
|
||||
target 23
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 29
|
||||
target 26
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 30
|
||||
target 1
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 30
|
||||
target 8
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 31
|
||||
target 0
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 31
|
||||
target 24
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 31
|
||||
target 25
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 31
|
||||
target 28
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 2
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 8
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 14
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 15
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 18
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 20
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 22
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 23
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 29
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 30
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 32
|
||||
target 31
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 8
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 9
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 13
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 14
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 15
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 18
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 19
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 20
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 22
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 23
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 26
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 27
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 28
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 29
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 30
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 31
|
||||
]
|
||||
edge
|
||||
[
|
||||
source 33
|
||||
target 32
|
||||
]
|
||||
]
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2022 The igraph development team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h> /* unlink */
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
const char *infilename = "test.graphml";
|
||||
const char *outfilename = "test2.graphml";
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Set up attribute handling, so graph attributes can be imported
|
||||
* from the GraphML file. */
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
/* Problems in the GraphML file may cause igraph to print warnings.
|
||||
* If this is not desired, set a silent warning handler: */
|
||||
igraph_set_warning_handler(&igraph_warning_handler_ignore);
|
||||
|
||||
/* Read the contents of a GraphML file. */
|
||||
|
||||
/* GraphML */
|
||||
FILE *infile = fopen("test.graphml", "r");
|
||||
if (! infile) {
|
||||
fprintf(stderr, "Could not open input file '%s'.", infilename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* GraphML support is an optional feature in igraph. If igraph was compiled
|
||||
* without GraphML support, igraph_read_graph_graphml() returns IGRAPH_UNIMPLEMENTED.
|
||||
* We temporarily disable the default error handler so we can test for this condition. */
|
||||
igraph_error_handler_t *oldhandler = igraph_set_error_handler(igraph_error_handler_ignore);
|
||||
igraph_error_t ret = igraph_read_graph_graphml(&graph, infile, 0);
|
||||
if (ret == IGRAPH_UNIMPLEMENTED) {
|
||||
fprintf(stderr, "igraph was compiled without GraphML support.");
|
||||
exit(77);
|
||||
}
|
||||
if (ret != IGRAPH_SUCCESS) {
|
||||
fprintf(stderr, "Unexpected error while reading GraphML.");
|
||||
exit(1);
|
||||
}
|
||||
igraph_set_error_handler(oldhandler);
|
||||
|
||||
|
||||
fclose(infile);
|
||||
|
||||
/* Write it back into another file. */
|
||||
|
||||
FILE *outfile = fopen(outfilename, "w");
|
||||
if (outfile) {
|
||||
igraph_write_graph_graphml(&graph, outfile, true);
|
||||
fclose(outfile);
|
||||
|
||||
/* Clean up after ourselves */
|
||||
unlink(outfilename);
|
||||
} else {
|
||||
fprintf(stderr, "Could not write output file '%s'.", outfilename);
|
||||
}
|
||||
|
||||
/* Destroy the graph */
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_vector_int_list_t partitions;
|
||||
igraph_vector_int_list_t cuts;
|
||||
igraph_real_t value;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_small(&g, 5, IGRAPH_DIRECTED,
|
||||
0, 1, 1, 2, 2, 3, 3, 4,
|
||||
-1);
|
||||
|
||||
igraph_vector_int_list_init(&partitions, 0);
|
||||
igraph_vector_int_list_init(&cuts, 0);
|
||||
igraph_all_st_mincuts(&g, &value, &cuts, &partitions,
|
||||
/*source=*/ 0, /*target=*/ 4,
|
||||
/*capacity=*/ 0);
|
||||
|
||||
igraph_int_t i, e, m, n = igraph_vector_int_list_size(&partitions);
|
||||
printf("Found %" IGRAPH_PRId " cuts, value: %g\n", n, value);
|
||||
for (i = 0; i < n; i++) {
|
||||
igraph_vector_int_t *vec = igraph_vector_int_list_get_ptr(&partitions, i);
|
||||
igraph_vector_int_t *vec2 = igraph_vector_int_list_get_ptr(&cuts, i);
|
||||
printf("Partition %" IGRAPH_PRId ": ", i);
|
||||
igraph_vector_int_print(vec);
|
||||
if (vec2) {
|
||||
printf("Cut %" IGRAPH_PRId ":\n", i);
|
||||
m = igraph_vector_int_size(vec2);
|
||||
for (e = 0; e < m; e++) {
|
||||
igraph_int_t from = IGRAPH_FROM(&g, VECTOR(*vec2)[e]), to = IGRAPH_TO(&g, VECTOR(*vec2)[e]);
|
||||
printf(" %" IGRAPH_PRId " -> %" IGRAPH_PRId "\n", from, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
igraph_vector_int_list_destroy(&partitions);
|
||||
igraph_vector_int_list_destroy(&cuts);
|
||||
printf("\n");
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
igraph_t g;
|
||||
igraph_int_t vcount = 1000;
|
||||
igraph_real_t pf = 0.2;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Seed random number generator to ensure reproducibility. */
|
||||
igraph_rng_seed(igraph_rng_default(), 42);
|
||||
|
||||
printf("Forest fire model network with %" IGRAPH_PRId " vertices and %g forward burning probability.\n\n",
|
||||
vcount, pf);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
igraph_real_t assortativity;
|
||||
|
||||
/* Generate graph from the forest fire model. */
|
||||
igraph_forest_fire_game(&g, vcount, pf, 1.0, 1, IGRAPH_UNDIRECTED);
|
||||
|
||||
/* Compute assortativity. */
|
||||
igraph_assortativity_degree(&g, &assortativity, /* ignore edge directions */ IGRAPH_UNDIRECTED);
|
||||
printf("Assortativity before rewiring = %g\n", assortativity);
|
||||
|
||||
/* Randomize the graph while preserving the degrees. */
|
||||
igraph_rewire(&g, 20 * igraph_ecount(&g), IGRAPH_SIMPLE_SW, NULL);
|
||||
|
||||
/* Re-compute assortativity. Did it change? */
|
||||
igraph_assortativity_degree(&g, &assortativity, /* ignore edge directions */ IGRAPH_UNDIRECTED);
|
||||
printf("Assortativity after rewiring = %g\n\n", assortativity);
|
||||
|
||||
igraph_destroy(&g);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Forest fire model network with 1000 vertices and 0.2 forward burning probability.
|
||||
|
||||
Assortativity before rewiring = 0.164775
|
||||
Assortativity after rewiring = -0.0244963
|
||||
|
||||
Assortativity before rewiring = 0.204558
|
||||
Assortativity after rewiring = -0.0115178
|
||||
|
||||
Assortativity before rewiring = 0.25205
|
||||
Assortativity after rewiring = -0.0198939
|
||||
|
||||
Assortativity before rewiring = 0.136678
|
||||
Assortativity after rewiring = 0.00245584
|
||||
|
||||
Assortativity before rewiring = 0.262014
|
||||
Assortativity after rewiring = -0.00207304
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_int_t nodes = 120, types = 4;
|
||||
igraph_matrix_t pref_matrix;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_matrix_init(&pref_matrix, types, types);
|
||||
|
||||
igraph_rng_seed(igraph_rng_default(), 42);
|
||||
printf("Randomly generated graph with %" IGRAPH_PRId " nodes and %" IGRAPH_PRId " vertex types\n\n", nodes, types);
|
||||
|
||||
/* Generate preference matrix giving connection probabilities for different vertex types */
|
||||
for (igraph_int_t i = 0; i < types; i++) {
|
||||
for (igraph_int_t j = 0; j < types; j++) {
|
||||
MATRIX(pref_matrix, i, j) = (i == j ? 0.1: 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
igraph_vector_int_t node_type_vec;
|
||||
igraph_vector_int_init(&node_type_vec, nodes);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
igraph_real_t assortativity;
|
||||
igraph_t g;
|
||||
|
||||
/* Generate undirected graph with 1000 nodes and 50 vertex types */
|
||||
igraph_preference_game(&g, nodes, types, /* type_dist= */ NULL, /* fixed_sizes= */ 1, &pref_matrix, &node_type_vec, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||||
|
||||
igraph_assortativity_nominal(&g, NULL, &node_type_vec, &assortativity, IGRAPH_UNDIRECTED, 1);
|
||||
printf("Assortativity before rewiring = %g\n", assortativity);
|
||||
|
||||
/* Rewire graph */
|
||||
igraph_rewire(&g, 10 * igraph_ecount(&g), IGRAPH_SIMPLE_SW, NULL);
|
||||
|
||||
igraph_assortativity_nominal(&g, NULL, &node_type_vec, &assortativity, IGRAPH_UNDIRECTED, 1);
|
||||
printf("Assortativity after rewiring = %g\n\n", assortativity);
|
||||
|
||||
igraph_destroy(&g);
|
||||
}
|
||||
igraph_vector_int_destroy(&node_type_vec);
|
||||
igraph_matrix_destroy(&pref_matrix);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Randomly generated graph with 120 nodes and 4 vertex types
|
||||
|
||||
Assortativity before rewiring = 0.690908
|
||||
Assortativity after rewiring = -0.0376672
|
||||
|
||||
Assortativity before rewiring = 0.669352
|
||||
Assortativity after rewiring = -0.0178763
|
||||
|
||||
Assortativity before rewiring = 0.722101
|
||||
Assortativity after rewiring = 0.0421349
|
||||
|
||||
Assortativity before rewiring = 0.704048
|
||||
Assortativity after rewiring = -0.0244487
|
||||
|
||||
Assortativity before rewiring = 0.668842
|
||||
Assortativity after rewiring = 0.000612194
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_atlas(&g, 45);
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
printf("\n");
|
||||
igraph_destroy(&g);
|
||||
|
||||
igraph_atlas(&g, 0);
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
printf("\n");
|
||||
igraph_destroy(&g);
|
||||
|
||||
igraph_atlas(&g, 1252);
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
printf("\n");
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
0 4
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
2 3
|
||||
2 4
|
||||
3 4
|
||||
|
||||
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
0 5
|
||||
0 6
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
1 5
|
||||
1 6
|
||||
2 3
|
||||
2 4
|
||||
2 5
|
||||
2 6
|
||||
3 4
|
||||
3 5
|
||||
3 6
|
||||
4 5
|
||||
4 6
|
||||
5 6
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_attribute_combination_t comb;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_set_attribute_table(&igraph_cattribute_table);
|
||||
|
||||
igraph_small(&graph, 2, IGRAPH_DIRECTED,
|
||||
0,1, 0,1,
|
||||
-1);
|
||||
|
||||
SETEAB(&graph, "type", 0, true);
|
||||
SETEAB(&graph, "type", 1, false);
|
||||
|
||||
igraph_attribute_combination(&comb,
|
||||
"weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
|
||||
"type", IGRAPH_ATTRIBUTE_COMBINE_FIRST,
|
||||
"", IGRAPH_ATTRIBUTE_COMBINE_IGNORE,
|
||||
IGRAPH_NO_MORE_ATTRIBUTES);
|
||||
igraph_simplify(&graph, /*remove_multiple=*/ true, /*remove_loops=*/ true, &comb);
|
||||
igraph_write_graph_graphml(&graph, stdout, /*prefixattr=*/ true);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
igraph_attribute_combination_destroy(&comb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
|
||||
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
|
||||
<!-- Created by igraph -->
|
||||
<key id="e_type" for="edge" attr.name="type" attr.type="boolean"/>
|
||||
<graph id="G" edgedefault="directed">
|
||||
<node id="n0">
|
||||
</node>
|
||||
<node id="n1">
|
||||
</node>
|
||||
<edge source="n0" target="n1">
|
||||
<data key="e_type">true</data>
|
||||
</edge>
|
||||
</graph>
|
||||
</graphml>
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_real_t result;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a random preferential attachment graph. */
|
||||
igraph_barabasi_game(&graph, 30, /*power=*/ 1, 30, NULL, /*outpref=*/ false, /*A=*/ 1,
|
||||
IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG,
|
||||
/*start_from=*/ NULL);
|
||||
|
||||
/* Compute the average shortest path length. */
|
||||
igraph_average_path_length(&graph, /*weights=*/ NULL, &result,
|
||||
/*unconn_pairs=*/ NULL, IGRAPH_UNDIRECTED, /*unconn=*/ true);
|
||||
printf("Average length of all-pairs shortest paths: %g\n", result);
|
||||
|
||||
/* Destroy no-longer-needed objects. */
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard st, Cambridge MA, 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_t knn, knnk;
|
||||
igraph_vector_t weights;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_famous(&graph, "Zachary");
|
||||
|
||||
igraph_vector_init(&knn, 0);
|
||||
igraph_vector_init(&knnk, 0);
|
||||
|
||||
igraph_avg_nearest_neighbor_degree(&graph, igraph_vss_all(),
|
||||
IGRAPH_ALL, IGRAPH_ALL,
|
||||
&knn, &knnk, /*weights=*/ NULL);
|
||||
|
||||
printf("knn: ");
|
||||
igraph_vector_print(&knn);
|
||||
printf("knn(k): ");
|
||||
igraph_vector_print(&knnk);
|
||||
|
||||
igraph_vector_init_range(&weights, 0, igraph_ecount(&graph));
|
||||
|
||||
igraph_avg_nearest_neighbor_degree(&graph, igraph_vss_all(),
|
||||
IGRAPH_ALL, IGRAPH_ALL,
|
||||
&knn, &knnk, &weights);
|
||||
igraph_vector_destroy(&weights);
|
||||
|
||||
printf("knn: ");
|
||||
igraph_vector_print(&knn);
|
||||
printf("knn(k): ");
|
||||
igraph_vector_print(&knnk);
|
||||
|
||||
igraph_vector_destroy(&knn);
|
||||
igraph_vector_destroy(&knnk);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
knn: 4.3125 5.77778 6.6 7.66667 7.66667 6.25 6.25 10.25 11.8 13.5 7.66667 16 11 11.6 14.5 14.5 4 12.5 14.5 14 14.5 12.5 14.5 8 4.33333 4.66667 10.5 8.75 11 9 10.75 9 5.08333 3.82353
|
||||
knn(k): 16 12.4091 8.22222 8.54167 10.4667 8.33333 NaN NaN 5.77778 6.6 NaN 5.08333 NaN NaN NaN 4.3125 3.82353
|
||||
knn: 3.45833 4.28205 5.4346 5.55634 4 3.42373 3.52991 8.64198 11.1104 14.2192 4.73171 16 8.32558 11.6143 14.5269 14.5258 4 11.625 14.5248 14.8953 14.5234 11.7222 14.5225 8.05085 4.34921 4.67935 10.5489 8.81395 11.2892 9.30741 12.0664 8.31319 5.35303 4.05771
|
||||
knn(k): 16 12.4884 7.07042 8.37055 9.71906 7.53953 NaN NaN 4.28205 5.4346 NaN 5.35303 NaN NaN NaN 3.45833 4.05771
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_vector_int_t v;
|
||||
igraph_vector_int_t v2, v3;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_barabasi_game(&g, 10, /*power=*/ 1, 2, 0, 0, /*A=*/ 1, 1,
|
||||
IGRAPH_BARABASI_BAG, /*start_from=*/ 0);
|
||||
if (igraph_ecount(&g) != 18) {
|
||||
return 1;
|
||||
}
|
||||
if (igraph_vcount(&g) != 10) {
|
||||
return 2;
|
||||
}
|
||||
if (!igraph_is_directed(&g)) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
igraph_vector_int_init(&v, 0);
|
||||
igraph_get_edgelist(&g, &v, 0);
|
||||
for (igraph_int_t i = 0; i < igraph_ecount(&g); i++) {
|
||||
if (VECTOR(v)[2 * i] <= VECTOR(v)[2 * i + 1]) {
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
igraph_vector_int_destroy(&v);
|
||||
igraph_destroy(&g);
|
||||
|
||||
/* out-degree sequence */
|
||||
igraph_vector_int_init_int(&v3, 10, 0, 1, 3, 3, 4, 5, 6, 7, 8, 9);
|
||||
|
||||
igraph_barabasi_game(&g, 10, /*power=*/ 1, 0, &v3, 0, /*A=*/ 1, 1,
|
||||
IGRAPH_BARABASI_BAG, /*start_from=*/ 0);
|
||||
if (igraph_ecount(&g) != igraph_vector_int_sum(&v3)) {
|
||||
return 5;
|
||||
}
|
||||
igraph_vector_int_init(&v2, 0);
|
||||
igraph_degree(&g, &v2, igraph_vss_all(), IGRAPH_OUT, IGRAPH_LOOPS);
|
||||
for (igraph_int_t i = 0; i < igraph_vcount(&g); i++) {
|
||||
if (VECTOR(v3)[i] != VECTOR(v2)[i]) {
|
||||
igraph_vector_int_print(&v3);
|
||||
printf("\n");
|
||||
igraph_vector_int_print(&v2);
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
igraph_vector_int_destroy(&v3);
|
||||
igraph_vector_int_destroy(&v2);
|
||||
igraph_destroy(&g);
|
||||
|
||||
/* outpref, we cannot really test this quantitatively,
|
||||
would need to set random seed */
|
||||
igraph_barabasi_game(&g, 10, /*power=*/ 1, 2, 0, 1, /*A=*/ 1, 1,
|
||||
IGRAPH_BARABASI_BAG, /*start_from=*/ 0);
|
||||
igraph_vector_int_init(&v, 0);
|
||||
igraph_get_edgelist(&g, &v, 0);
|
||||
for (igraph_int_t i = 0; i < igraph_ecount(&g); i++) {
|
||||
if (VECTOR(v)[2 * i] <= VECTOR(v)[2 * i + 1]) {
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
if (!igraph_is_directed(&g)) {
|
||||
return 8;
|
||||
}
|
||||
igraph_vector_int_destroy(&v);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2010-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
igraph_bool_t simple;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_barabasi_game(/* graph= */ &g,
|
||||
/* n= */ 100,
|
||||
/* power= */ 1.0,
|
||||
/* m= */ 2,
|
||||
/* outseq= */ 0,
|
||||
/* outpref= */ 0,
|
||||
/* A= */ 1.0,
|
||||
/* directed= */ IGRAPH_DIRECTED,
|
||||
/* algo= */ IGRAPH_BARABASI_PSUMTREE,
|
||||
/* start_from= */ 0);
|
||||
|
||||
if (igraph_ecount(&g) != 197) {
|
||||
return 1;
|
||||
}
|
||||
if (igraph_vcount(&g) != 100) {
|
||||
return 2;
|
||||
}
|
||||
igraph_is_simple(&g, &simple, IGRAPH_DIRECTED);
|
||||
if (!simple) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
/* ============================== */
|
||||
|
||||
igraph_barabasi_game(/* graph= */ &g,
|
||||
/* n= */ 100,
|
||||
/* power= */ 1.0,
|
||||
/* m= */ 2,
|
||||
/* outseq= */ 0,
|
||||
/* outpref= */ 0,
|
||||
/* A= */ 1.0,
|
||||
/* directed= */ IGRAPH_DIRECTED,
|
||||
/* algo= */ IGRAPH_BARABASI_PSUMTREE_MULTIPLE,
|
||||
/* start_from= */ 0);
|
||||
|
||||
if (igraph_ecount(&g) != 198) {
|
||||
return 4;
|
||||
}
|
||||
if (igraph_vcount(&g) != 100) {
|
||||
return 5;
|
||||
}
|
||||
igraph_is_simple(&g, &simple, IGRAPH_DIRECTED);
|
||||
if (simple) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
/* ============================== */
|
||||
|
||||
igraph_barabasi_game(/* graph= */ &g,
|
||||
/* n= */ 100,
|
||||
/* power= */ 1.0,
|
||||
/* m= */ 2,
|
||||
/* outseq= */ 0,
|
||||
/* outpref= */ 0,
|
||||
/* A= */ 1.0,
|
||||
/* directed= */ IGRAPH_DIRECTED,
|
||||
/* algo= */ IGRAPH_BARABASI_BAG,
|
||||
/* start_from= */ 0);
|
||||
|
||||
if (igraph_ecount(&g) != 198) {
|
||||
return 7;
|
||||
}
|
||||
if (igraph_vcount(&g) != 100) {
|
||||
return 8;
|
||||
}
|
||||
igraph_is_simple(&g, &simple, IGRAPH_DIRECTED);
|
||||
if (simple) {
|
||||
return 9;
|
||||
}
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2021 The igraph development team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t graph, ring;
|
||||
igraph_vector_int_t order, rank, father, pred, succ, dist;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a disjoint union of two rings */
|
||||
igraph_ring(&ring, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
|
||||
igraph_disjoint_union(&graph, &ring, &ring);
|
||||
igraph_destroy(&ring);
|
||||
|
||||
/* Initialize the vectors where the result will be stored. Any of these
|
||||
* can be omitted and replaced with a null pointer when calling
|
||||
* igraph_bfs() */
|
||||
igraph_vector_int_init(&order, 0);
|
||||
igraph_vector_int_init(&rank, 0);
|
||||
igraph_vector_int_init(&father, 0);
|
||||
igraph_vector_int_init(&pred, 0);
|
||||
igraph_vector_int_init(&succ, 0);
|
||||
igraph_vector_int_init(&dist, 0);
|
||||
|
||||
/* Now call the BFS function */
|
||||
igraph_bfs(&graph, /*root=*/0, /*roots=*/ NULL, /*neimode=*/ IGRAPH_OUT,
|
||||
/*unreachable=*/ 1, /*restricted=*/ NULL,
|
||||
&order, &rank, &father, &pred, &succ, &dist,
|
||||
/*callback=*/ NULL, /*extra=*/ NULL);
|
||||
|
||||
/* Print the results */
|
||||
igraph_vector_int_print(&order);
|
||||
igraph_vector_int_print(&rank);
|
||||
igraph_vector_int_print(&father);
|
||||
igraph_vector_int_print(&pred);
|
||||
igraph_vector_int_print(&succ);
|
||||
igraph_vector_int_print(&dist);
|
||||
|
||||
/* Cleam up after ourselves */
|
||||
igraph_vector_int_destroy(&order);
|
||||
igraph_vector_int_destroy(&rank);
|
||||
igraph_vector_int_destroy(&father);
|
||||
igraph_vector_int_destroy(&pred);
|
||||
igraph_vector_int_destroy(&succ);
|
||||
igraph_vector_int_destroy(&dist);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
0 1 9 2 8 3 7 4 6 5 10 11 19 12 18 13 17 14 16 15
|
||||
0 1 3 5 7 9 8 6 4 2 10 11 13 15 17 19 18 16 14 12
|
||||
-1 0 1 2 3 4 7 8 9 0 -1 10 11 12 13 14 17 18 19 10
|
||||
-1 0 9 8 7 6 4 3 2 1 -1 10 19 18 17 16 14 13 12 11
|
||||
1 9 8 7 6 -1 5 4 3 2 11 19 18 17 16 -1 15 14 13 12
|
||||
0 1 2 3 4 5 4 3 2 1 0 1 2 3 4 5 4 3 2 1
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2021 The igraph development team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
igraph_error_t bfs_callback(const igraph_t *graph,
|
||||
igraph_int_t vid,
|
||||
igraph_int_t pred,
|
||||
igraph_int_t succ,
|
||||
igraph_int_t rank,
|
||||
igraph_int_t dist,
|
||||
void *extra) {
|
||||
IGRAPH_UNUSED(graph);
|
||||
IGRAPH_UNUSED(pred);
|
||||
IGRAPH_UNUSED(succ);
|
||||
IGRAPH_UNUSED(rank);
|
||||
IGRAPH_UNUSED(dist);
|
||||
printf(" %" IGRAPH_PRId "", vid);
|
||||
return IGRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph, ring;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a disjoint union of two rings */
|
||||
igraph_ring(&ring, 10, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/ 1);
|
||||
igraph_disjoint_union(&graph, &ring, &ring);
|
||||
igraph_destroy(&ring);
|
||||
|
||||
/* Now call the BFS function */
|
||||
printf("(");
|
||||
igraph_bfs(&graph, /*root=*/0, /*roots=*/ 0, /*neimode=*/ IGRAPH_OUT,
|
||||
/*unreachable=*/ 1, /*restricted=*/ 0,
|
||||
/*order=*/ 0, /*rank=*/ 0, /*father=*/ 0, /*pred=*/ 0,
|
||||
/*succ=*/ 0, /*dist=*/ 0,
|
||||
/*callback=*/ bfs_callback, /*extra=*/ 0);
|
||||
printf(" )\n");
|
||||
|
||||
/* Cleam up after ourselves */
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
( 0 1 9 2 8 3 7 4 6 5 10 11 19 12 18 13 17 14 16 15 )
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2009-2021 The igraph development team
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
igraph_vector_int_t vids, layers, parents;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_ring(&g, 10, IGRAPH_UNDIRECTED, 0, 0);
|
||||
|
||||
igraph_vector_int_init(&vids, 0);
|
||||
igraph_vector_int_init(&layers, 0);
|
||||
igraph_vector_int_init(&parents, 0);
|
||||
|
||||
igraph_bfs_simple(&g, 0, IGRAPH_ALL, &vids, &layers, &parents);
|
||||
|
||||
igraph_vector_int_print(&vids);
|
||||
igraph_vector_int_print(&layers);
|
||||
igraph_vector_int_print(&parents);
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
igraph_vector_int_destroy(&vids);
|
||||
igraph_vector_int_destroy(&layers);
|
||||
igraph_vector_int_destroy(&parents);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
0 1 2 3 4 5 6 7 8 9 10
|
||||
-1 0 1 2 3 4 5 6 7 8
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2024 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
/* Prints a vector of edge IDs as u--v vertex pairs. */
|
||||
void print_edge_vector(const igraph_t *graph, const igraph_vector_int_t *edges) {
|
||||
const igraph_int_t n = igraph_vector_int_size(edges);
|
||||
for (igraph_int_t i=0; i < n; i++) {
|
||||
igraph_int_t edge = VECTOR(*edges)[i];
|
||||
printf("%" IGRAPH_PRId "--%" IGRAPH_PRId " ", IGRAPH_FROM(graph, edge), IGRAPH_TO(graph, edge));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_list_t component_vertices, component_edges;
|
||||
igraph_int_t no;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create an example graph. */
|
||||
igraph_small(&graph, 7, IGRAPH_UNDIRECTED,
|
||||
0,1, 1,2, 2,3, 3,0,
|
||||
2,4, 4,5, 5,2,
|
||||
0,6,
|
||||
0,7,
|
||||
-1);
|
||||
|
||||
/* The data structures that the result will be written to must be initialized first. */
|
||||
igraph_vector_int_list_init(&component_vertices, 0);
|
||||
igraph_vector_int_list_init(&component_edges, 0);
|
||||
|
||||
igraph_biconnected_components(&graph, &no, NULL, &component_edges, &component_vertices, NULL);
|
||||
|
||||
printf("Number of components: %" IGRAPH_PRId "\n", no);
|
||||
for (igraph_int_t i=0; i < no; i++) {
|
||||
printf("\n");
|
||||
printf("Component %" IGRAPH_PRId ":\n", i);
|
||||
printf("Vertices: ");
|
||||
igraph_vector_int_print(igraph_vector_int_list_get_ptr(&component_vertices, i));
|
||||
printf("Edges: ");
|
||||
print_edge_vector(&graph, igraph_vector_int_list_get_ptr(&component_edges, i));
|
||||
}
|
||||
|
||||
/* Destroy data structures after we no longer need them. */
|
||||
|
||||
igraph_vector_int_list_destroy(&component_edges);
|
||||
igraph_vector_int_list_destroy(&component_vertices);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
Number of components: 4
|
||||
|
||||
Component 0:
|
||||
Vertices: 5 4 2
|
||||
Edges: 5--2 5--4 4--2
|
||||
|
||||
Component 1:
|
||||
Vertices: 3 2 1 0
|
||||
Edges: 3--0 3--2 2--1 1--0
|
||||
|
||||
Component 2:
|
||||
Vertices: 6 0
|
||||
Edges: 6--0
|
||||
|
||||
Component 3:
|
||||
Vertices: 7 0
|
||||
Edges: 7--0
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2008-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g;
|
||||
igraph_int_t edges_array[] = {0, 1, 1, 2, 3, 4, 5, 6, 6, 5, 1, 4, 1, 6, 0, 3 };
|
||||
igraph_vector_int_t edges =
|
||||
igraph_vector_int_view(edges_array, sizeof(edges_array) / sizeof(edges_array[0]));
|
||||
igraph_vector_bool_t types;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_bool_init(&types, igraph_vector_int_max(&edges) + 1);
|
||||
for (igraph_int_t i = 0; i < igraph_vector_bool_size(&types); i++) {
|
||||
VECTOR(types)[i] = i % 2;
|
||||
}
|
||||
igraph_create_bipartite(&g, &types, &edges, IGRAPH_DIRECTED);
|
||||
igraph_write_graph_edgelist(&g, stdout);
|
||||
igraph_vector_bool_destroy(&types);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
0 1
|
||||
0 3
|
||||
1 2
|
||||
1 4
|
||||
1 6
|
||||
3 4
|
||||
5 6
|
||||
6 5
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t g, p1, p2;
|
||||
igraph_vector_bool_t types;
|
||||
igraph_vector_int_t mult1, mult2;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_int_init(&mult1, 0);
|
||||
igraph_vector_int_init(&mult2, 0);
|
||||
|
||||
igraph_small(&g, 0, IGRAPH_UNDIRECTED, 0,1, 1,2, 0,3, 3,2, 2,4, 4,5, -1);
|
||||
igraph_vector_bool_init_int(&types, 6, 0, 1, 0, 1, 1, 0);
|
||||
|
||||
igraph_bipartite_projection(&g, &types, &p1, &p2, &mult1, &mult2, /*probe1=*/ 1);
|
||||
|
||||
igraph_write_graph_edgelist(&p1, stdout);
|
||||
printf("\n");
|
||||
igraph_write_graph_edgelist(&p2, stdout);
|
||||
printf("\n");
|
||||
|
||||
igraph_vector_int_print(&mult1);
|
||||
igraph_vector_int_print(&mult2);
|
||||
|
||||
igraph_vector_int_destroy(&mult1);
|
||||
igraph_vector_int_destroy(&mult2);
|
||||
igraph_destroy(&p1);
|
||||
igraph_destroy(&p2);
|
||||
igraph_destroy(&g);
|
||||
igraph_vector_bool_destroy(&types);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int compare_vectors(const igraph_vector_int_t *v1, const igraph_vector_int_t *v2) {
|
||||
igraph_int_t s1, s2, i;
|
||||
|
||||
s1 = igraph_vector_int_size(v1);
|
||||
s2 = igraph_vector_int_size(v2);
|
||||
if (s1 < s2) {
|
||||
return -1;
|
||||
}
|
||||
if (s1 > s2) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < s1; ++i) {
|
||||
if (VECTOR(*v1)[i] < VECTOR(*v2)[i]) {
|
||||
return -1;
|
||||
}
|
||||
if (VECTOR(*v1)[i] > VECTOR(*v2)[i]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Takes a pointer vector of vectors. Sorts each vector, then sorts the pointer vector */
|
||||
void canonicalize_list(igraph_vector_int_list_t *list) {
|
||||
igraph_int_t len = igraph_vector_int_list_size(list);
|
||||
for (igraph_int_t i = 0; i < len; ++i) {
|
||||
igraph_vector_int_sort(igraph_vector_int_list_get_ptr(list, i));
|
||||
}
|
||||
igraph_vector_int_list_sort(list, &compare_vectors);
|
||||
}
|
||||
|
||||
struct userdata {
|
||||
igraph_int_t i;
|
||||
igraph_vector_int_list_t *list;
|
||||
};
|
||||
|
||||
igraph_error_t handler(const igraph_vector_int_t *clique, void *arg) {
|
||||
struct userdata *ud;
|
||||
igraph_bool_t cont;
|
||||
|
||||
ud = (struct userdata *) arg;
|
||||
cont = 1; /* true */
|
||||
|
||||
if (compare_vectors(clique, igraph_vector_int_list_get_ptr(ud->list, ud->i)) != 0) {
|
||||
printf("igraph_cliques() and igraph_cliques_callback() give different results.\n");
|
||||
cont = 0; /* false */
|
||||
}
|
||||
|
||||
ud->i += 1;
|
||||
|
||||
return cont ? IGRAPH_SUCCESS : IGRAPH_STOP;
|
||||
}
|
||||
|
||||
void test_callback(const igraph_t *graph) {
|
||||
igraph_vector_int_list_t list;
|
||||
struct userdata ud;
|
||||
|
||||
igraph_vector_int_list_init(&list, 0);
|
||||
igraph_cliques(graph, &list, 0, 0, IGRAPH_UNLIMITED);
|
||||
|
||||
ud.i = 0;
|
||||
ud.list = &list;
|
||||
|
||||
igraph_cliques_callback(graph, 0, 0, &handler, (void *) &ud);
|
||||
|
||||
igraph_vector_int_list_destroy(&list);
|
||||
}
|
||||
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_vector_int_list_t result;
|
||||
igraph_es_t es;
|
||||
igraph_int_t omega;
|
||||
igraph_int_t i, j, n;
|
||||
const int params[] = {4, -1, 2, 2, 0, 0, -1, -1};
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_set_warning_handler(igraph_warning_handler_ignore);
|
||||
|
||||
igraph_vector_int_list_init(&result, 0);
|
||||
igraph_full(&g, 6, 0, 0);
|
||||
igraph_es_pairs_small(&es, 0, 0, 1, 0, 2, 3, 5, -1);
|
||||
igraph_delete_edges(&g, es);
|
||||
igraph_es_destroy(&es);
|
||||
|
||||
for (j = 0; j < sizeof(params) / (2 * sizeof(params[0])); j++) {
|
||||
if (params[2 * j + 1] != 0) {
|
||||
igraph_cliques(&g, &result, params[2 * j], params[2 * j + 1], IGRAPH_UNLIMITED);
|
||||
} else {
|
||||
igraph_largest_cliques(&g, &result);
|
||||
}
|
||||
n = igraph_vector_int_list_size(&result);
|
||||
printf("%" IGRAPH_PRId " cliques found\n", n);
|
||||
canonicalize_list(&result);
|
||||
for (i = 0; i < n; i++) {
|
||||
igraph_vector_int_t* v = igraph_vector_int_list_get_ptr(&result, i);
|
||||
igraph_vector_int_print(v);
|
||||
}
|
||||
}
|
||||
|
||||
igraph_clique_number(&g, &omega);
|
||||
printf("omega=%" IGRAPH_PRId "\n", omega);
|
||||
|
||||
test_callback(&g);
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
igraph_kary_tree(&g, 5, 2, IGRAPH_TREE_OUT);
|
||||
igraph_cliques(&g, &result, 5, 5, IGRAPH_UNLIMITED);
|
||||
if (igraph_vector_int_list_size(&result) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
igraph_destroy(&g);
|
||||
igraph_vector_int_list_destroy(&result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
2 cliques found
|
||||
1 2 3 4
|
||||
1 2 4 5
|
||||
12 cliques found
|
||||
0 3
|
||||
0 4
|
||||
0 5
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
1 5
|
||||
2 3
|
||||
2 4
|
||||
2 5
|
||||
3 4
|
||||
4 5
|
||||
2 cliques found
|
||||
1 2 3 4
|
||||
1 2 4 5
|
||||
29 cliques found
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
0 3
|
||||
0 4
|
||||
0 5
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
1 5
|
||||
2 3
|
||||
2 4
|
||||
2 5
|
||||
3 4
|
||||
4 5
|
||||
0 3 4
|
||||
0 4 5
|
||||
1 2 3
|
||||
1 2 4
|
||||
1 2 5
|
||||
1 3 4
|
||||
1 4 5
|
||||
2 3 4
|
||||
2 4 5
|
||||
1 2 3 4
|
||||
1 2 4 5
|
||||
omega=4
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2020 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_matrix_t matrix;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Create a small test graph. */
|
||||
igraph_small(&graph, 0, IGRAPH_DIRECTED,
|
||||
0, 1, 2, 1, 2, 0, 3, 0,
|
||||
-1);
|
||||
|
||||
/* As usual with igraph functions, the data structure in which the result
|
||||
will be returned must be initialized in advance. */
|
||||
igraph_matrix_init(&matrix, 0, 0);
|
||||
igraph_bibcoupling(&graph, &matrix, igraph_vss_all());
|
||||
printf("Bibliographic coupling matrix:\n");
|
||||
igraph_matrix_print(&matrix);
|
||||
|
||||
igraph_cocitation(&graph, &matrix, igraph_vss_all());
|
||||
printf("\nCocitation matrix:\n");
|
||||
igraph_matrix_print(&matrix);
|
||||
|
||||
/* Destroy data structures when we are done with them. */
|
||||
igraph_matrix_destroy(&matrix);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
Bibliographic coupling matrix:
|
||||
0 0 1 0
|
||||
0 0 0 0
|
||||
1 0 0 1
|
||||
0 0 1 0
|
||||
|
||||
Cocitation matrix:
|
||||
0 1 0 0
|
||||
1 0 0 0
|
||||
0 0 0 0
|
||||
0 0 0 0
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t edges;
|
||||
igraph_vector_t eb, weights;
|
||||
igraph_matrix_int_t merges;
|
||||
igraph_vector_int_t bridges;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_small(&graph, 5, IGRAPH_UNDIRECTED,
|
||||
0, 1, 1, 2, 0, 2, 0, 3, 1, 3, 1, 4,
|
||||
-1);
|
||||
igraph_vector_init_range(&weights, 1, igraph_ecount(&graph)+1);
|
||||
igraph_vector_init(&eb, 0);
|
||||
igraph_vector_int_init(&edges, 0);
|
||||
igraph_matrix_int_init(&merges, 0, 0);
|
||||
igraph_vector_int_init(&bridges, 0);
|
||||
igraph_community_edge_betweenness(&graph, &edges, &eb, &merges,
|
||||
&bridges, /*modularity*/ NULL,
|
||||
/*membership*/ NULL,
|
||||
IGRAPH_UNDIRECTED,
|
||||
&weights,
|
||||
NULL);
|
||||
printf("edges:\n");
|
||||
igraph_vector_int_print(&edges);
|
||||
printf("edge betweenness:\n");
|
||||
igraph_vector_print(&eb);
|
||||
printf("merges:\n");
|
||||
igraph_matrix_int_print(&merges);
|
||||
printf("bridges:\n");
|
||||
igraph_vector_int_print(&bridges);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
igraph_vector_int_destroy(&edges);
|
||||
igraph_vector_destroy(&eb);
|
||||
igraph_vector_destroy(&weights);
|
||||
igraph_matrix_int_destroy(&merges);
|
||||
igraph_vector_int_destroy(&bridges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
edges:
|
||||
0 1 3 4 2 5
|
||||
edge betweenness:
|
||||
2 3.5 6 2 1 1
|
||||
merges:
|
||||
1 4
|
||||
0 2
|
||||
5 3
|
||||
6 7
|
||||
bridges:
|
||||
5 4 3 2
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2022 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_t weights;
|
||||
igraph_matrix_int_t merges;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_matrix_int_init(&merges, 0, 0);
|
||||
igraph_vector_init_int(&weights, 8, 10, 10, 1, 1, 1, 1, 1, 1);
|
||||
|
||||
igraph_small(&graph, 6, IGRAPH_UNDIRECTED,
|
||||
0,1, 1,2, 2,3, 2,4, 2,5, 3,4, 3,5, 4,5, -1);
|
||||
igraph_community_fastgreedy(&graph, &weights, &merges,
|
||||
/*modularity*/ NULL,
|
||||
/*membership=*/ NULL);
|
||||
igraph_matrix_int_print(&merges);
|
||||
igraph_destroy(&graph);
|
||||
igraph_vector_destroy(&weights);
|
||||
igraph_matrix_int_destroy(&merges);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
1 0
|
||||
2 6
|
||||
3 4
|
||||
8 5
|
||||
9 7
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2024 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t membership;
|
||||
igraph_real_t modularity;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_famous(&graph, "Zachary"); /* We use Zachary's karate club network. */
|
||||
|
||||
/* Label propagation is a stochastic method; the result will depend on the random seed. */
|
||||
igraph_rng_seed(igraph_rng_default(), 123);
|
||||
|
||||
/* All igraph functions that returns their result in an igraph_vector_t must be given
|
||||
an already initialized vector. */
|
||||
igraph_vector_int_init(&membership, 0);
|
||||
igraph_community_label_propagation(
|
||||
&graph, &membership, /* mode = */ IGRAPH_ALL,
|
||||
/* weights= */ NULL, /* initial= */ NULL, /* fixed= */ NULL,
|
||||
IGRAPH_LPA_DOMINANCE);
|
||||
|
||||
/* Also calculate the modularity of the partition */
|
||||
igraph_modularity(
|
||||
&graph, &membership, /* weights= */ NULL, /* resolution = */ 1,
|
||||
/* directed= */ false, &modularity);
|
||||
|
||||
printf("%" IGRAPH_PRId " communities found; modularity score is %g.\n",
|
||||
igraph_vector_int_max(&membership) + 1, modularity);
|
||||
|
||||
printf("Communities membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
|
||||
/* Destroy data structures at the end. */
|
||||
igraph_vector_int_destroy(&membership);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
3 communities found; modularity score is 0.394395.
|
||||
Communities membership: 0 0 0 0 1 1 1 0 0 0 1 0 0 0 2 2 1 0 2 0 2 0 2 2 2 2 2 2 2 2 0 2 2 2
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2024 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g;
|
||||
igraph_matrix_int_t merges;
|
||||
igraph_vector_int_t membership;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Zachary Karate club */
|
||||
igraph_small(&g, 0, IGRAPH_UNDIRECTED,
|
||||
0, 1, 0, 2, 0, 3, 0, 4, 0, 5,
|
||||
0, 6, 0, 7, 0, 8, 0, 10, 0, 11,
|
||||
0, 12, 0, 13, 0, 17, 0, 19, 0, 21,
|
||||
0, 31, 1, 2, 1, 3, 1, 7, 1, 13,
|
||||
1, 17, 1, 19, 1, 21, 1, 30, 2, 3,
|
||||
2, 7, 2, 8, 2, 9, 2, 13, 2, 27,
|
||||
2, 28, 2, 32, 3, 7, 3, 12, 3, 13,
|
||||
4, 6, 4, 10, 5, 6, 5, 10, 5, 16,
|
||||
6, 16, 8, 30, 8, 32, 8, 33, 9, 33,
|
||||
13, 33, 14, 32, 14, 33, 15, 32, 15, 33,
|
||||
18, 32, 18, 33, 19, 33, 20, 32, 20, 33,
|
||||
22, 32, 22, 33, 23, 25, 23, 27, 23, 29,
|
||||
23, 32, 23, 33, 24, 25, 24, 27, 24, 31,
|
||||
25, 31, 26, 29, 26, 33, 27, 33, 28, 31,
|
||||
28, 33, 29, 32, 29, 33, 30, 32, 30, 33,
|
||||
31, 32, 31, 33, 32, 33,
|
||||
-1);
|
||||
|
||||
igraph_matrix_int_init(&merges, 0, 0);
|
||||
igraph_vector_int_init(&membership, 0);
|
||||
|
||||
igraph_community_leading_eigenvector(&g, /*weights=*/ NULL,
|
||||
&merges, &membership,
|
||||
/*steps=*/ 1,
|
||||
/*options=*/ NULL,
|
||||
/*modularity=*/ NULL,
|
||||
/*start=*/ NULL,
|
||||
/*eigenvalues=*/ NULL,
|
||||
/*eigenvectors=*/ NULL,
|
||||
/*history=*/ NULL,
|
||||
/*callback=*/ NULL,
|
||||
/*callback_extra=*/ NULL);
|
||||
|
||||
igraph_matrix_int_print(&merges);
|
||||
igraph_vector_int_print(&membership);
|
||||
|
||||
printf("\n");
|
||||
|
||||
/* Make all the steps */
|
||||
igraph_community_leading_eigenvector(&g, /*weights=*/ NULL,
|
||||
&merges, &membership,
|
||||
/*steps=*/ igraph_vcount(&g),
|
||||
/*options=*/ NULL,
|
||||
/*modularity=*/ NULL,
|
||||
/*start=*/ NULL,
|
||||
/*eigenvalues=*/ NULL,
|
||||
/*eigenvectors=*/ NULL,
|
||||
/*history=*/ NULL,
|
||||
/*callback=*/ NULL,
|
||||
/*callback_extra=*/ NULL);
|
||||
|
||||
igraph_matrix_int_print(&merges);
|
||||
igraph_vector_int_print(&membership);
|
||||
|
||||
igraph_vector_int_destroy(&membership);
|
||||
igraph_matrix_int_destroy(&merges);
|
||||
igraph_destroy(&g);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
0 1
|
||||
0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1
|
||||
|
||||
1 3
|
||||
0 2
|
||||
5 4
|
||||
0 2 2 2 0 0 0 2 1 1 0 0 2 2 1 1 0 2 1 2 1 2 1 3 3 3 1 3 3 1 1 3 1 1
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2007-2024 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t membership;
|
||||
igraph_vector_t vertex_weights;
|
||||
igraph_vector_t vertex_out_weights, vertex_in_weights;
|
||||
igraph_int_t nb_clusters;
|
||||
igraph_real_t quality;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* Set default seed to get reproducible results */
|
||||
igraph_rng_seed(igraph_rng_default(), 0);
|
||||
|
||||
/* UNDIRECTED EXAMPLE */
|
||||
|
||||
/* Simple unweighted undirected graph */
|
||||
igraph_small(&graph, 10, IGRAPH_UNDIRECTED,
|
||||
0, 1, 0, 2, 0, 3, 0, 4, 1, 2, 1, 3, 1, 4, 2, 3, 2, 4, 3, 4,
|
||||
5, 6, 5, 7, 5, 8, 5, 9, 6, 7, 6, 8, 6, 9, 7, 8, 7, 9, 8, 9,
|
||||
0, 5, -1);
|
||||
|
||||
/* Perform Leiden algorithm using CPM for 1 iteration */
|
||||
igraph_vector_int_init(&membership, igraph_vcount(&graph));
|
||||
igraph_community_leiden(&graph, NULL, NULL, NULL,
|
||||
/* resolution */ 0.05,
|
||||
/* beta */ 0.01,
|
||||
/* start */ false,
|
||||
/* iterations */ 1,
|
||||
&membership, &nb_clusters, &quality);
|
||||
|
||||
printf("Leiden found %" IGRAPH_PRId " clusters using CPM (resolution parameter 0.05), quality is %.4f.\n", nb_clusters, quality);
|
||||
printf("Membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
printf("\n");
|
||||
|
||||
/* Start from existing membership for 10 iterations to improve it further */
|
||||
igraph_community_leiden(&graph, NULL, NULL, NULL,
|
||||
/* resolution */ 0.05,
|
||||
/* beta */ 0.01,
|
||||
/* start */ true,
|
||||
/* iterations */ 10,
|
||||
&membership, &nb_clusters, &quality);
|
||||
|
||||
printf("Iterated Leiden, using CPM (resolution parameter 0.05), quality is %.4f.\n", quality);
|
||||
printf("Membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
printf("\n");
|
||||
|
||||
/* Use degrees as vertex weights for optimizing modularity */
|
||||
igraph_vector_init(&vertex_weights, igraph_vcount(&graph));
|
||||
igraph_strength(&graph, &vertex_weights, igraph_vss_all(), IGRAPH_ALL, IGRAPH_LOOPS, NULL);
|
||||
|
||||
/* Perform Leiden algorithm using modularity until stable iteration */
|
||||
igraph_community_leiden(&graph, NULL, &vertex_weights, NULL,
|
||||
/* resolution */ 1.0 / (2 * igraph_ecount(&graph)),
|
||||
/* beta */ 0.01,
|
||||
/* start */ false,
|
||||
/* iterations */ -1,
|
||||
&membership, &nb_clusters, &quality);
|
||||
|
||||
printf("Leiden found %" IGRAPH_PRId " clusters using modularity, quality is %.4f.\n", nb_clusters, quality);
|
||||
printf("Membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
printf("\n");
|
||||
|
||||
igraph_vector_destroy(&vertex_weights);
|
||||
igraph_vector_int_destroy(&membership);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
/* DIRECTED EXAMPLE */
|
||||
|
||||
/* Simple unweighted directed graph */
|
||||
igraph_small(&graph, 6, IGRAPH_DIRECTED,
|
||||
0, 1, 0, 3, 0, 5, 1, 3, 1, 4, 2, 3, 4, 1, 5, 2, 5, 4,
|
||||
-1);
|
||||
|
||||
igraph_vector_int_init(&membership, igraph_vcount(&graph));
|
||||
igraph_vector_init(&vertex_out_weights, igraph_vcount(&graph));
|
||||
igraph_vector_init(&vertex_in_weights, igraph_vcount(&graph));
|
||||
igraph_strength(&graph, &vertex_out_weights, igraph_vss_all(), IGRAPH_OUT, IGRAPH_LOOPS, NULL);
|
||||
igraph_strength(&graph, &vertex_in_weights, igraph_vss_all(), IGRAPH_IN, IGRAPH_LOOPS, NULL);
|
||||
|
||||
/* Perform Leiden algorithm using modularity for two iterations,
|
||||
* which are usually sufficient to achieve stability.
|
||||
* Note that in the directed case, we divide by the edge count m, not 2*m. */
|
||||
igraph_community_leiden(&graph, NULL, &vertex_out_weights, &vertex_in_weights,
|
||||
/* resolution */ 1.0 / igraph_ecount(&graph),
|
||||
/* beta */ 0.01,
|
||||
/* start */ false,
|
||||
/* iterations */ 2,
|
||||
&membership, &nb_clusters, &quality);
|
||||
|
||||
printf("Leiden found %" IGRAPH_PRId " clusters using modularity, quality is %.4f.\n", nb_clusters, quality);
|
||||
printf("Membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
printf("\n");
|
||||
|
||||
igraph_vector_destroy(&vertex_in_weights);
|
||||
igraph_vector_destroy(&vertex_out_weights);
|
||||
igraph_vector_int_destroy(&membership);
|
||||
igraph_destroy(&graph);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
Leiden found 2 clusters using CPM (resolution parameter 0.05), quality is 0.8929.
|
||||
Membership: 0 0 0 0 0 1 1 1 1 1
|
||||
|
||||
Iterated Leiden, using CPM (resolution parameter 0.05), quality is 0.8929.
|
||||
Membership: 0 0 0 0 0 1 1 1 1 1
|
||||
|
||||
Leiden found 2 clusters using modularity, quality is 0.4524.
|
||||
Membership: 0 0 0 0 0 1 1 1 1 1
|
||||
|
||||
Leiden found 3 clusters using modularity, quality is 0.1852.
|
||||
Membership: 0 1 2 2 1 0
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/* vim:set ts=4 sts=4 sw=4 et: */
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
void show_results(igraph_t *g, igraph_vector_int_t *membership, igraph_matrix_int_t *memberships, igraph_vector_t *modularity, FILE* f) {
|
||||
igraph_int_t i, j, no_of_nodes = igraph_vcount(g);
|
||||
|
||||
j = igraph_vector_which_max(modularity);
|
||||
for (i = 0; i < igraph_vector_int_size(membership); i++) {
|
||||
if (VECTOR(*membership)[i] != MATRIX(*memberships, j, i)) {
|
||||
fprintf(f, "WARNING: best membership vector element %" IGRAPH_PRId " does not match the best one in the membership matrix\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(f, "Modularities:\n");
|
||||
igraph_vector_print(modularity);
|
||||
|
||||
for (i = 0; i < igraph_matrix_int_nrow(memberships); i++) {
|
||||
for (j = 0; j < no_of_nodes; j++) {
|
||||
fprintf(f, "%" IGRAPH_PRId " ", MATRIX(*memberships, i, j));
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
igraph_setup();
|
||||
igraph_t g;
|
||||
igraph_vector_t modularity;
|
||||
igraph_vector_int_t edges;
|
||||
igraph_vector_int_t membership;
|
||||
igraph_matrix_int_t memberships;
|
||||
igraph_int_t i, j, k;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_init(&modularity, 0);
|
||||
igraph_vector_int_init(&membership, 0);
|
||||
igraph_matrix_int_init(&memberships, 0, 0);
|
||||
|
||||
igraph_rng_seed(igraph_rng_default(), 42);
|
||||
|
||||
/* Unweighted test graph from the paper of Blondel et al */
|
||||
igraph_small(&g, 16, IGRAPH_UNDIRECTED,
|
||||
0, 2, 0, 3, 0, 4, 0, 5,
|
||||
1, 2, 1, 4, 1, 7,
|
||||
2, 4, 2, 5, 2, 6,
|
||||
3, 7,
|
||||
4, 10,
|
||||
5, 7, 5, 11,
|
||||
6, 7, 6, 11,
|
||||
8, 9, 8, 10, 8, 11, 8, 14, 8, 15,
|
||||
9, 12, 9, 14,
|
||||
10, 11, 10, 12, 10, 13, 10, 14,
|
||||
11, 13,
|
||||
-1);
|
||||
igraph_community_multilevel(&g, 0, 1, &membership, &memberships, &modularity);
|
||||
show_results(&g, &membership, &memberships, &modularity, stdout);
|
||||
|
||||
/* Higher resolution */
|
||||
igraph_community_multilevel(&g, 0, 1.5, &membership, &memberships, &modularity);
|
||||
show_results(&g, &membership, &memberships, &modularity, stdout);
|
||||
|
||||
igraph_destroy(&g);
|
||||
|
||||
/* Ring of 30 cliques */
|
||||
igraph_vector_int_init(&edges, 0);
|
||||
for (i = 0; i < 30; i++) {
|
||||
for (j = 0; j < 5; j++) {
|
||||
for (k = j + 1; k < 5; k++) {
|
||||
igraph_vector_int_push_back(&edges, i * 5 + j);
|
||||
igraph_vector_int_push_back(&edges, i * 5 + k);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < 30; i++) {
|
||||
igraph_vector_int_push_back(&edges, i * 5 % 150);
|
||||
igraph_vector_int_push_back(&edges, (i * 5 + 6) % 150);
|
||||
}
|
||||
igraph_create(&g, &edges, 150, 0);
|
||||
igraph_community_multilevel(&g, 0, 1, &membership, &memberships, &modularity);
|
||||
show_results(&g, &membership, &memberships, &modularity, stdout);
|
||||
igraph_destroy(&g);
|
||||
|
||||
igraph_vector_destroy(&modularity);
|
||||
igraph_vector_int_destroy(&membership);
|
||||
igraph_vector_int_destroy(&edges);
|
||||
igraph_matrix_int_destroy(&memberships);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
Modularities:
|
||||
0.346301 0.392219
|
||||
0 0 0 1 0 0 1 1 2 2 2 3 2 3 2 2
|
||||
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
|
||||
|
||||
Modularities:
|
||||
0.195472
|
||||
0 1 1 0 1 0 1 0 2 2 3 3 2 3 2 2
|
||||
|
||||
Modularities:
|
||||
0.875758 0.887879
|
||||
0 0 0 0 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 13 13 13 13 13 14 14 14 14 14 15 15 15 15 15 16 16 16 16 16 17 17 17 17 17 18 18 18 18 18 19 19 19 19 19 20 20 20 20 20 21 21 21 21 21 22 22 22 22 22 23 23 23 23 23 24 24 24 24 24 25 25 25 25 25 26 26 26 26 26 27 27 27 27 27 28 28 28 28 28 29 29 29 29 29
|
||||
0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 0 0 0 0 0
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/* igraph library.
|
||||
Copyright (C) 2010-2024 The igraph development team <igraph@igraph.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
igraph_t graph;
|
||||
igraph_vector_int_t membership;
|
||||
igraph_real_t modularity;
|
||||
igraph_error_handler_t *handler;
|
||||
igraph_error_t errcode;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_small(&graph, 9, IGRAPH_UNDIRECTED,
|
||||
0, 3, 0, 4, 0, 1, 0, 2, 0, 5, 0, 6, 1, 3, 3, 5, 4, 7, 7, 8, 2, 4, 1, 2, 6, 8,
|
||||
-1);
|
||||
|
||||
igraph_vector_int_init(&membership, 0);
|
||||
|
||||
/* Temporarily ignore errors so we can check if the functionality is available. */
|
||||
handler = igraph_set_error_handler(&igraph_error_handler_printignore);
|
||||
|
||||
errcode = igraph_community_optimal_modularity(&graph, NULL, 1, &modularity, &membership);
|
||||
if (errcode == IGRAPH_UNIMPLEMENTED) {
|
||||
/* igraph was not build with GLPK; functionality unavailable, so we quit */
|
||||
return 77;
|
||||
}
|
||||
|
||||
/* Restore the previous error handler. */
|
||||
igraph_set_error_handler(handler);
|
||||
|
||||
printf("Highest possible modularity: %g\n", modularity);
|
||||
printf("Membership: ");
|
||||
igraph_vector_int_print(&membership);
|
||||
|
||||
igraph_destroy(&graph);
|
||||
|
||||
igraph_vector_int_destroy(&membership);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Highest possible modularity: 0.221893
|
||||
Membership: 0 0 0 0 1 0 1 1 1
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g1, g2;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
/* complementer of the empty graph */
|
||||
igraph_empty(&g1, 5, IGRAPH_DIRECTED);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* the same without loops */
|
||||
igraph_empty(&g1, 5, IGRAPH_DIRECTED);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_NO_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* complementer of the full graph */
|
||||
igraph_full(&g1, 5, IGRAPH_DIRECTED, IGRAPH_LOOPS);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
if (igraph_ecount(&g2) != 0) {
|
||||
return 1;
|
||||
}
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* complementer of the full graph, results loops only */
|
||||
igraph_full(&g1, 5, IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/**************
|
||||
* undirected *
|
||||
*************/
|
||||
|
||||
/* complementer of the empty graph */
|
||||
igraph_empty(&g1, 5, IGRAPH_UNDIRECTED);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* the same without loops */
|
||||
igraph_empty(&g1, 5, IGRAPH_UNDIRECTED);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_NO_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* complementer of the full graph */
|
||||
igraph_full(&g1, 5, IGRAPH_UNDIRECTED, IGRAPH_LOOPS);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
if (igraph_ecount(&g2) != 0) {
|
||||
return 1;
|
||||
}
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
printf("---\n");
|
||||
|
||||
/* complementer of the full graph, results loops only */
|
||||
igraph_full(&g1, 5, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||||
igraph_complementer(&g2, &g1, IGRAPH_LOOPS);
|
||||
igraph_write_graph_edgelist(&g2, stdout);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
0 0
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
1 0
|
||||
1 1
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
2 0
|
||||
2 1
|
||||
2 2
|
||||
2 3
|
||||
2 4
|
||||
3 0
|
||||
3 1
|
||||
3 2
|
||||
3 3
|
||||
3 4
|
||||
4 0
|
||||
4 1
|
||||
4 2
|
||||
4 3
|
||||
4 4
|
||||
---
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
1 0
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
2 0
|
||||
2 1
|
||||
2 3
|
||||
2 4
|
||||
3 0
|
||||
3 1
|
||||
3 2
|
||||
3 4
|
||||
4 0
|
||||
4 1
|
||||
4 2
|
||||
4 3
|
||||
---
|
||||
---
|
||||
0 0
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
---
|
||||
0 0
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
1 1
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
2 2
|
||||
2 3
|
||||
2 4
|
||||
3 3
|
||||
3 4
|
||||
4 4
|
||||
---
|
||||
0 1
|
||||
0 2
|
||||
0 3
|
||||
0 4
|
||||
1 2
|
||||
1 3
|
||||
1 4
|
||||
2 3
|
||||
2 4
|
||||
3 4
|
||||
---
|
||||
---
|
||||
0 0
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
igraph library.
|
||||
Copyright (C) 2006-2012 Gabor Csardi <csardi.gabor@gmail.com>
|
||||
334 Harvard street, Cambridge, MA 02139 USA
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
*/
|
||||
|
||||
#include <igraph.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
igraph_t g1, g2, res;
|
||||
igraph_vector_int_t v;
|
||||
igraph_vector_int_t map1, map2;
|
||||
|
||||
/* Initialize the library. */
|
||||
igraph_setup();
|
||||
|
||||
igraph_vector_int_init(&map1, 0);
|
||||
igraph_vector_int_init(&map2, 0);
|
||||
|
||||
/* composition with the empty graph */
|
||||
igraph_empty(&g1, 5, IGRAPH_DIRECTED);
|
||||
igraph_full(&g2, 5, IGRAPH_DIRECTED, IGRAPH_NO_LOOPS);
|
||||
igraph_compose(&res, &g1, &g2, &map1, &map2);
|
||||
if (igraph_ecount(&res) != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (igraph_vector_int_size(&map1) != 0 || igraph_vector_int_size(&map2) != 0) {
|
||||
return 11;
|
||||
}
|
||||
igraph_destroy(&res);
|
||||
igraph_compose(&res, &g2, &g1, &map1, &map2);
|
||||
if (igraph_ecount(&res) != 0) {
|
||||
return 2;
|
||||
}
|
||||
if (igraph_vector_int_size(&map1) != 0 || igraph_vector_int_size(&map2) != 0) {
|
||||
return 12;
|
||||
}
|
||||
igraph_destroy(&res);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
/* same but undirected */
|
||||
igraph_empty(&g1, 5, IGRAPH_UNDIRECTED);
|
||||
igraph_full(&g2, 5, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
|
||||
igraph_compose(&res, &g1, &g2, &map1, &map2);
|
||||
if (igraph_ecount(&res) != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (igraph_vector_int_size(&map1) != 0 || igraph_vector_int_size(&map2) != 0) {
|
||||
return 11;
|
||||
}
|
||||
igraph_destroy(&res);
|
||||
igraph_compose(&res, &g2, &g1, &map1, &map2);
|
||||
if (igraph_ecount(&res) != 0) {
|
||||
return 2;
|
||||
}
|
||||
if (igraph_vector_int_size(&map1) != 0 || igraph_vector_int_size(&map2) != 0) {
|
||||
return 12;
|
||||
}
|
||||
igraph_destroy(&res);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
/* proper directed graph */
|
||||
igraph_vector_int_init_int_end(&v, -1, 0, 1, 1, 2, 5, 6, -1);
|
||||
igraph_create(&g1, &v, 0, IGRAPH_DIRECTED);
|
||||
igraph_vector_int_destroy(&v);
|
||||
|
||||
igraph_vector_int_init_int_end(&v, -1, 0, 1, 2, 4, 5, 6, -1);
|
||||
igraph_create(&g2, &v, 0, IGRAPH_DIRECTED);
|
||||
igraph_vector_int_destroy(&v);
|
||||
|
||||
igraph_compose(&res, &g1, &g2, &map1, &map2);
|
||||
igraph_write_graph_edgelist(&res, stdout);
|
||||
igraph_vector_int_print(&map1);
|
||||
igraph_vector_int_print(&map2);
|
||||
igraph_destroy(&res);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
/* undirected graph */
|
||||
igraph_vector_int_init_int_end(&v, -1, 0, 1, 1, 2, 5, 6, -1);
|
||||
igraph_create(&g1, &v, 0, IGRAPH_UNDIRECTED);
|
||||
igraph_vector_int_destroy(&v);
|
||||
|
||||
igraph_vector_int_init_int_end(&v, -1, 0, 1, 0, 4, 5, 6, -1);
|
||||
igraph_create(&g2, &v, 0, IGRAPH_UNDIRECTED);
|
||||
igraph_vector_int_destroy(&v);
|
||||
|
||||
igraph_compose(&res, &g1, &g2, &map1, &map2);
|
||||
igraph_write_graph_edgelist(&res, stdout);
|
||||
igraph_vector_int_print(&map1);
|
||||
igraph_vector_int_print(&map2);
|
||||
igraph_destroy(&res);
|
||||
igraph_destroy(&g1);
|
||||
igraph_destroy(&g2);
|
||||
|
||||
igraph_vector_int_destroy(&map2);
|
||||
igraph_vector_int_destroy(&map1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
1 4
|
||||
1
|
||||
1
|
||||
0 0
|
||||
0 2
|
||||
1 1
|
||||
1 4
|
||||
5 5
|
||||
6 6
|
||||
0 0 0 1 2 2
|
||||
0 1 0 0 2 2
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user