Add graph references

This commit is contained in:
Abdelrahman Said
2026-06-28 13:49:01 +01:00
parent 0a9807e448
commit a11edf0c53
2578 changed files with 868045 additions and 0 deletions
@@ -0,0 +1,43 @@
/*
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 "../unit/test_utilities.h"
int main(void) {
igraph_t graph;
igraph_vector_int_list_t separators;
igraph_small(&graph, 0, /*directed=*/ 0,
0, 1, 0, 2, 1, 3, 1, 4, 2, 3, 2, 5, 3, 4, 3, 5, 4, 6, 5, 6, -1);
igraph_vector_int_list_init(&separators, 0);
igraph_all_minimal_st_separators(&graph, &separators);
print_vector_int_list(&separators);
igraph_vector_int_list_destroy(&separators);
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,11 @@
{
0: ( 1 2 )
1: ( 0 3 4 )
2: ( 0 3 5 )
3: ( 4 5 )
4: ( 1 3 6 )
5: ( 2 3 6 )
6: ( 2 3 4 )
7: ( 1 3 5 )
8: ( 0 3 6 )
}
@@ -0,0 +1,47 @@
/*
igraph library.
Copyright (C) 2013 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 "../unit/test_utilities.h"
int main(void) {
igraph_t graph;
igraph_vector_t mod;
igraph_empty(&graph, 25, IGRAPH_UNDIRECTED);
igraph_vector_init(&mod, 0);
igraph_community_multilevel(&graph, /*weights=*/ 0, /*resolution=*/ 1,
/*membership=*/ 0, /*memberships=*/ 0, &mod);
if (igraph_vector_size(&mod) != 1 ||
!isnan(VECTOR(mod)[0])) {
return 1;
}
igraph_vector_destroy(&mod);
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,159 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
/* Regression test for https://github.com/igraph/igraph/issues/1760 */
int test_unweighted(const igraph_t* g, igraph_int_t from, const igraph_vs_t* to) {
igraph_vector_int_list_t vpath, epath;
igraph_int_t num_paths;
igraph_vector_int_t parents;
igraph_vector_int_t inbound_edges;
printf("Unweighted case\n");
printf("---------------\n\n");
IGRAPH_CHECK(igraph_vs_size(g, to, &num_paths));
IGRAPH_CHECK(igraph_vector_int_list_init(&vpath, 0));
IGRAPH_CHECK(igraph_vector_int_list_init(&epath, 0));
IGRAPH_CHECK(igraph_vector_int_init(&parents, 0));
IGRAPH_CHECK(igraph_vector_int_init(&inbound_edges, 0));
IGRAPH_CHECK(igraph_get_shortest_paths(
g, NULL, &vpath, &epath, from, *to, IGRAPH_IN,
&parents, &inbound_edges
));
printf("Vertices:\n");
print_vector_int_list(&vpath);
printf("\n");
printf("Edges:\n");
print_vector_int_list(&epath);
printf("\n");
printf("Parents:\n");
print_vector_int(&parents);
printf("\n");
printf("Inbound edges:\n");
print_vector_int(&inbound_edges);
printf("\n");
igraph_vector_int_destroy(&inbound_edges);
igraph_vector_int_destroy(&parents);
igraph_vector_int_list_destroy(&epath);
igraph_vector_int_list_destroy(&vpath);
return IGRAPH_SUCCESS;
}
int test_weighted(
const igraph_t* g, const igraph_vector_t* weights, igraph_int_t from,
const igraph_vs_t* to, igraph_bool_t use_bellman_ford
) {
igraph_vector_int_list_t vpath, epath;
igraph_int_t num_paths;
igraph_vector_int_t parents;
igraph_vector_int_t inbound_edges;
printf("Weighted case\n");
printf("-------------\n\n");
printf("Algorithm: %s\n\n", use_bellman_ford ? "Bellman-Ford" : "Dijkstra");
IGRAPH_CHECK(igraph_vs_size(g, to, &num_paths));
IGRAPH_CHECK(igraph_vector_int_list_init(&vpath, 0));
IGRAPH_CHECK(igraph_vector_int_list_init(&epath, 0));
IGRAPH_CHECK(igraph_vector_int_init(&parents, 0));
IGRAPH_CHECK(igraph_vector_int_init(&inbound_edges, 0));
if (use_bellman_ford) {
IGRAPH_CHECK(igraph_get_shortest_paths_bellman_ford(
g, &vpath, &epath, from, *to, weights, IGRAPH_IN,
&parents, &inbound_edges
));
} else {
IGRAPH_CHECK(igraph_get_shortest_paths_dijkstra(
g, &vpath, &epath, from, *to, weights, IGRAPH_IN,
&parents, &inbound_edges
));
}
printf("Vertices:\n");
print_vector_int_list(&vpath);
printf("\n");
printf("Edges:\n");
print_vector_int_list(&epath);
printf("\n");
printf("Parents:\n");
print_vector_int(&parents);
printf("\n");
printf("Inbound edges:\n");
print_vector_int(&inbound_edges);
printf("\n");
igraph_vector_int_destroy(&inbound_edges);
igraph_vector_int_destroy(&parents);
igraph_vector_int_list_destroy(&epath);
igraph_vector_int_list_destroy(&vpath);
return IGRAPH_SUCCESS;
}
int main(void) {
igraph_t g;
igraph_vector_t weights;
igraph_vs_t to;
igraph_set_warning_handler(igraph_warning_handler_ignore);
igraph_small(&g, 4, /* directed = */ 1, 0, 1, 1, 2, 1, 3, -1);
igraph_vs_vector_small(&to, 0, 3, -1);
igraph_vector_init(&weights, 3);
VECTOR(weights)[0] = 1;
VECTOR(weights)[1] = 2;
VECTOR(weights)[2] = 2;
/* Test unweighted case */
if (test_unweighted(&g, 2, &to)) {
return 1;
}
/* Test weighted case */
if (test_weighted(&g, &weights, 2, &to, /* use_bellman_ford = */ 0)) {
return 2;
}
if (test_weighted(&g, &weights, 2, &to, /* use_bellman_ford = */ 1)) {
return 3;
}
igraph_vector_destroy(&weights);
igraph_vs_destroy(&to);
igraph_destroy(&g);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,67 @@
Unweighted case
---------------
Vertices:
{
0: ( 2 1 0 )
1: ( )
}
Edges:
{
0: ( 1 0 )
1: ( )
}
Parents:
( 1 2 -1 -2 )
Inbound edges:
( 0 1 -1 -1 )
Weighted case
-------------
Algorithm: Dijkstra
Vertices:
{
0: ( 2 1 0 )
1: ( )
}
Edges:
{
0: ( 1 0 )
1: ( )
}
Parents:
( 1 2 -1 -2 )
Inbound edges:
( 0 1 -1 -1 )
Weighted case
-------------
Algorithm: Bellman-Ford
Vertices:
{
0: ( 2 1 0 )
1: ( )
}
Edges:
{
0: ( 1 0 )
1: ( )
}
Parents:
( 1 2 -1 -2 )
Inbound edges:
( 0 1 -1 -1 )
@@ -0,0 +1,75 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
/* Regression test for https://github.com/igraph/igraph/issues/1814 */
void test_igraph_to_undirected(igraph_to_undirected_t mode) {
igraph_t g;
igraph_attribute_combination_t comb;
igraph_small(&g, 4, IGRAPH_DIRECTED,
0,1, 0,1, 1,0,
1,1, 1,1,
-1);
SETEAN(&g, "weight", 0, 1);
SETEAN(&g, "weight", 1, 2);
SETEAN(&g, "weight", 2, 3);
SETEAN(&g, "weight", 3, 4);
SETEAN(&g, "weight", 4, 2);
igraph_attribute_combination(
&comb, "weight", IGRAPH_ATTRIBUTE_COMBINE_SUM,
IGRAPH_NO_MORE_ATTRIBUTES
);
igraph_to_undirected(&g, mode, &comb);
igraph_attribute_combination_destroy(&comb);
igraph_write_graph_gml(&g, stdout, IGRAPH_WRITE_GML_DEFAULT_SW, 0, "");
igraph_destroy(&g);
VERIFY_FINALLY_STACK();
}
int main(void) {
igraph_set_attribute_table(&igraph_cattribute_table);
printf("to_undirected(COLLAPSE)\n");
printf("=======================\n\n");
test_igraph_to_undirected(IGRAPH_TO_UNDIRECTED_COLLAPSE);
printf("\n");
printf("to_undirected(MUTUAL)\n");
printf("=====================\n\n");
test_igraph_to_undirected(IGRAPH_TO_UNDIRECTED_MUTUAL);
printf("\n");
printf("to_undirected(EACH)\n");
printf("===================\n\n");
test_igraph_to_undirected(IGRAPH_TO_UNDIRECTED_EACH);
printf("\n");
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,135 @@
to_undirected(COLLAPSE)
=======================
Version 1
graph
[
directed 0
node
[
id 0
]
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
edge
[
source 1
target 0
weight 6
]
edge
[
source 1
target 1
weight 6
]
]
to_undirected(MUTUAL)
=====================
Version 1
graph
[
directed 0
node
[
id 0
]
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
edge
[
source 1
target 0
weight 5
]
edge
[
source 1
target 1
weight 2
]
edge
[
source 1
target 1
weight 4
]
]
to_undirected(EACH)
===================
Version 1
graph
[
directed 0
node
[
id 0
]
node
[
id 1
]
node
[
id 2
]
node
[
id 3
]
edge
[
source 1
target 0
weight 1
]
edge
[
source 1
target 0
weight 2
]
edge
[
source 1
target 0
weight 3
]
edge
[
source 1
target 1
weight 4
]
edge
[
source 1
target 1
weight 2
]
]
@@ -0,0 +1,44 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
int main(void) {
FILE *file;
igraph_t graph;
igraph_error_t err;
igraph_set_attribute_table(&igraph_cattribute_table);
igraph_set_error_handler(igraph_error_handler_printignore);
file = fopen("bug_1970.graphml", "r");
IGRAPH_ASSERT(file != NULL);
err = igraph_read_graph_graphml(&graph, file, 0);
fclose(file);
IGRAPH_ASSERT(err != IGRAPH_SUCCESS);
/* graph creation should have failed, no need to destroy 'graph' */
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1 @@
<graphml><key id="one" for="edge" attr.type="double"/><key id="one" for="edge" attr.type="string"></key><graph></graph></graphml>
@@ -0,0 +1,46 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
/* Regression test for https://github.com/igraph/igraph/issues/2150 */
int main(void) {
igraph_t graph;
igraph_vector_t w;
igraph_vector_int_list_t res;
igraph_full(&graph, 3, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
igraph_vector_init_int(&w, 3, 1, 2, 3);
igraph_vector_int_list_init(&res, 0);
igraph_weighted_cliques(&graph, &w, &res, false, 1, 3, IGRAPH_UNLIMITED);
igraph_vector_int_list_destroy(&res);
igraph_vector_destroy(&w);
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,48 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
int main(void) {
FILE *file;
igraph_t graph;
igraph_set_attribute_table(&igraph_cattribute_table);
igraph_set_error_handler(igraph_error_handler_ignore);
igraph_set_warning_handler(igraph_warning_handler_ignore);
file = fopen("bug_2497.gml", "r");
IGRAPH_ASSERT(file != NULL);
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
IGRAPH_ASSERT(igraph_read_graph_gml(&graph, file) == IGRAPH_SUCCESS);
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
fclose(file);
igraph_write_graph_gml(&graph, stdout, IGRAPH_WRITE_GML_DEFAULT_SW, NULL, "");
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,4 @@
graph [
node [ id 2 ]
node [ ]
]
@@ -0,0 +1,13 @@
Version 1
graph
[
directed 0
node
[
id 0
]
node
[
id 1
]
]
@@ -0,0 +1,68 @@
/*
igraph library.
Copyright (C) 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>
#include "../unit/test_utilities.h"
int main(void) {
igraph_t g;
igraph_error_t result;
FILE *ifile;
igraph_set_error_handler(igraph_error_handler_ignore);
igraph_set_attribute_table(&igraph_cattribute_table);
ifile = fopen("bug_2506_1.graphml", "r");
IGRAPH_ASSERT(ifile != NULL);
result = igraph_read_graph_graphml(&g, ifile, 0);
fclose(ifile);
if (result == IGRAPH_UNIMPLEMENTED) {
/* maybe it is simply disabled at compile-time */
return 77;
}
IGRAPH_ASSERT(result == IGRAPH_PARSEERROR);
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
ifile = fopen("bug_2506_2.graphml", "r");
IGRAPH_ASSERT(ifile != NULL);
result = igraph_read_graph_graphml(&g, ifile, 0);
fclose(ifile);
IGRAPH_ASSERT(result == IGRAPH_PARSEERROR);
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
ifile = fopen("bug_2506_3.graphml", "r");
IGRAPH_ASSERT(ifile != NULL);
result = igraph_read_graph_graphml(&g, ifile, 0);
fclose(ifile);
IGRAPH_ASSERT(result == IGRAPH_PARSEERROR);
IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,4 @@
<graphml>
<key id="d3" for="" attr.type="s"></key><key id="d3" for="" attr.type=""></key>
<graph></graph>
</graphml>
@@ -0,0 +1 @@
<graphml><key id="" for="graph" attr.type="string"/><key id="" for="graph" attr.type="double"/><graph></graph></graphml>
@@ -0,0 +1 @@
<graphml><key id="e" for="graph" attr.name="" attr.type="string"/><key id="g" for="graph" attr.name="" attr.type="double"/><graph></graph></graphml>
@@ -0,0 +1,44 @@
/*
igraph library.
Copyright (C) 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 "../unit/test_utilities.h"
int main(void) {
igraph_t g;
igraph_vector_int_list_t result;
igraph_vector_int_list_init(&result, 0);
igraph_small(&g, 2, IGRAPH_UNDIRECTED, 0, 1, -1);
igraph_all_minimal_st_separators(&g, &result);
print_vector_int_list(&result);
igraph_destroy(&g);
igraph_small(&g, 3, IGRAPH_UNDIRECTED, 0, 1, -1);
igraph_all_minimal_st_separators(&g, &result);
print_vector_int_list(&result);
igraph_destroy(&g);
igraph_vector_int_list_destroy(&result);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,4 @@
{
}
{
}
@@ -0,0 +1,49 @@
/*
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 "../unit/test_utilities.h"
int main(void) {
igraph_t g;
igraph_vector_int_t membership;
/* label propagation is a stochastic method */
igraph_rng_seed(igraph_rng_default(), 765);
igraph_small(&g, 0, /* directed = */ 1,
0, 1, 0, 2, 1, 0, 1, 0, 1, 1, 2, 0, 2, 1, 2, 1, 2, 1, -1);
igraph_vector_int_init(&membership, 0);
igraph_community_label_propagation(&g, &membership, IGRAPH_OUT, NULL, NULL, NULL, IGRAPH_LPA_FAST);
print_vector_int(&membership);
igraph_vector_int_destroy(&membership);
igraph_destroy(&g);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,73 @@
/*
igraph library.
Copyright (C) 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>
#include "../unit/test_utilities.h"
void check_attr(igraph_t *graph) {
IGRAPH_ASSERT(igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_GRAPH, "name"));
IGRAPH_ASSERT(igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_GRAPH, "type"));
IGRAPH_ASSERT(igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_GRAPH, "p"));
IGRAPH_ASSERT(igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_VERTEX, "name"));
IGRAPH_ASSERT(igraph_cattribute_has_attr(graph, IGRAPH_ATTRIBUTE_EDGE, "weight"));
}
int main(void) {
igraph_t graph;
igraph_error_handler_t* oldhandler;
int result;
FILE *ifile = fopen("cattr_bool_bug.graphml", "r");
if (!ifile) {
printf("Cannot open input file\n");
return 1;
}
igraph_set_attribute_table(&igraph_cattribute_table);
oldhandler = igraph_set_error_handler(igraph_error_handler_ignore);
if ((result = igraph_read_graph_graphml(&graph, ifile, 0))) {
/* Maybe it is simply disabled at compile-time. If so, skip test. */
if (result == IGRAPH_UNIMPLEMENTED) {
return 77;
}
printf("Failed to read GraphML file\n");
return 1;
}
igraph_set_error_handler(oldhandler);
fclose(ifile);
printf("Checkng attributes of original graph\n");
check_attr(&graph);
printf("Checkng attributes of directed version\n");
igraph_to_directed(&graph, IGRAPH_TO_DIRECTED_ARBITRARY);
check_attr(&graph);
IGRAPH_ASSERT(! GAB(&graph, "loops"));
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,76 @@
<?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_type" for="graph" attr.name="type" attr.type="string"/>
<key id="g_loops" for="graph" attr.name="loops" attr.type="boolean"/>
<key id="g_p" for="graph" attr.name="p" attr.type="double"/>
<key id="v_id" for="node" attr.name="name" attr.type="string"/>
<key id="e_weight" for="edge" attr.name="weight" attr.type="double"/>
<graph id="G" edgedefault="undirected">
<data key="g_name">Erdos renyi (gnp) graph</data>
<data key="g_type">gnp</data>
<data key="g_loops">false</data>
<data key="g_p">0.2</data>
<node id="n0">
<data key="v_id">n0</data>
</node>
<node id="n1">
<data key="v_id">n1</data>
</node>
<node id="n2">
<data key="v_id">n2</data>
</node>
<node id="n3">
<data key="v_id">n3</data>
</node>
<node id="n4">
<data key="v_id">n4</data>
</node>
<node id="n5">
<data key="v_id">n5</data>
</node>
<node id="n6">
<data key="v_id">n6</data>
</node>
<node id="n7">
<data key="v_id">n7</data>
</node>
<node id="n8">
<data key="v_id">n8</data>
</node>
<node id="n9">
<data key="v_id">n9</data>
</node>
<edge source="n0" target="n1">
<data key="e_weight">10</data>
</edge>
<edge source="n0" target="n3">
<data key="e_weight">11</data>
</edge>
<edge source="n4" target="n5">
<data key="e_weight">12</data>
</edge>
<edge source="n0" target="n6">
<data key="e_weight">13</data>
</edge>
<edge source="n5" target="n6">
<data key="e_weight">14</data>
</edge>
<edge source="n4" target="n7">
<data key="e_weight">15</data>
</edge>
<edge source="n5" target="n7">
<data key="e_weight">16</data>
</edge>
<edge source="n5" target="n9">
<data key="e_weight">17</data>
</edge>
<edge source="n7" target="n9">
<data key="e_weight">18</data>
</edge>
</graph>
</graphml>
@@ -0,0 +1,63 @@
/*
igraph library.
Copyright (C) 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>
#include "../unit/test_utilities.h"
#define FILENAME "mybool.graphml.xml"
int main(void) {
igraph_t graph;
igraph_error_handler_t* oldhandler;
int result;
FILE* ifile = fopen("cattr_bool_bug2.graphml", "r");
if (!ifile) {
printf("Cannot open input file\n");
return 1;
}
igraph_set_attribute_table(&igraph_cattribute_table);
oldhandler = igraph_set_error_handler(igraph_error_handler_ignore);
if ((result = igraph_read_graph_graphml(&graph, ifile, 0))) {
/* maybe it is simply disabled at compile-time */
if (result == IGRAPH_UNIMPLEMENTED) {
return 77;
}
printf("Failed to read GraphML file\n");
return 1;
}
igraph_set_error_handler(oldhandler);
fclose(ifile);
IGRAPH_ASSERT(igraph_cattribute_has_attr(&graph, IGRAPH_ATTRIBUTE_GRAPH, "mybool"));
/* Boolean attribute value is expected to be true */
IGRAPH_ASSERT(igraph_cattribute_GAB(&graph, "mybool"));
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,7 @@
<?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">
<key attr.name="mybool" attr.type="boolean" for="graph" id="d0" />
<graph edgedefault="undirected">
<data key="d0">True</data>
</graph>
</graphml>
@@ -0,0 +1,66 @@
/*
igraph library.
Copyright (C) 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>
#include "../unit/test_utilities.h"
void snap_to_zero(igraph_real_t* value) {
if (fabs(*value) < 1e-5) {
*value = 0.0;
}
}
int main(void) {
igraph_t graph;
igraph_matrix_t layout;
igraph_int_t i;
if (igraph_empty(&graph, 2, 0)) {
return 1;
}
if (igraph_add_edge(&graph, 0, 1)) {
return 2;
}
if (igraph_matrix_init(&layout, 0, 0)) {
return 3;
}
if (igraph_layout_kamada_kawai_3d(&graph, &layout, 0, 200, 0, 2, 0, 0, 0, 0, 0, 0, 0)) {
return 4;
}
/* Snap numbers close to zero in the layout; there are false failures on
* MinGW if we don't do so */
for (i = 0; i < 2; i++) {
snap_to_zero(&MATRIX(layout, i, 0));
snap_to_zero(&MATRIX(layout, i, 1));
snap_to_zero(&MATRIX(layout, i, 2));
}
print_matrix_format(&layout, stdout, "%.2f");
igraph_matrix_destroy(&layout);
igraph_destroy(&graph);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,2 @@
[ 0.00 0.00 -0.91
0.00 0.00 0.51 ]
@@ -0,0 +1,55 @@
/*
igraph library.
Copyright (C) 2006-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>
#include "../unit/test_utilities.h"
int main(void) {
igraph_t g;
FILE *f;
igraph_matrix_t coords;
igraph_vector_int_t roots;
igraph_int_t i, n;
f = fopen("igraph_layout_reingold_tilford_bug_879.in", "r");
IGRAPH_ASSERT(f != NULL);
igraph_read_graph_edgelist(&g, f, 0, IGRAPH_UNDIRECTED);
igraph_matrix_init(&coords, 0, 0);
igraph_vector_int_init(&roots, 0);
igraph_vector_int_push_back(&roots, 0);
igraph_layout_reingold_tilford(&g, &coords, IGRAPH_OUT, &roots, 0);
n = igraph_vcount(&g);
for (i = 0; i < n; i++) {
printf("%6.3f %6.3f\n", MATRIX(coords, i, 0), MATRIX(coords, i, 1));
}
igraph_matrix_destroy(&coords);
igraph_vector_int_destroy(&roots);
igraph_destroy(&g);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,15 @@
0 1
0 2
0 3
1 4
2 5
2 6
3 7
4 8
4 9
4 10
4 11
4 12
7 13
7 14
7 15
@@ -0,0 +1,16 @@
0.000 0.000
-1.833 1.000
-0.333 1.000
2.167 1.000
-1.833 2.000
-0.833 2.000
0.167 2.000
2.167 2.000
-3.833 3.000
-2.833 3.000
-1.833 3.000
-0.833 3.000
0.167 3.000
1.167 3.000
2.167 3.000
3.167 3.000
@@ -0,0 +1,74 @@
/*
igraph library.
Copyright (C) 2021-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 "../unit/test_utilities.h"
int test_file(const char* fname) {
FILE *ifile;
igraph_t g;
int retval;
ifile = fopen(fname, "r");
if (ifile == 0) {
return 1;
}
retval = igraph_read_graph_gml(&g, ifile);
if (!retval) {
/* input was accepted, this is a bug; attempt to clean up after
* ourselves nevertheless */
igraph_destroy(&g);
fclose(ifile);
return 2;
}
fclose(ifile);
return 0;
}
#undef RUN_TEST
#define RUN_TEST(fname) { \
index++; \
if (test_file(fname)) { \
return index; \
} \
VERIFY_FINALLY_STACK(); \
}
int main(void) {
int index = 0;
/* We do not care about errors; all we care about is that the library
* should not segfault and should not accept invalid input either */
igraph_set_error_handler(igraph_error_handler_ignore);
RUN_TEST("invalid1.gml");
RUN_TEST("invalid2.gml");
/* invalid3.gml was removed, parser now supports it */
RUN_TEST("invalid4.gml");
RUN_TEST("invalid5.gml");
RUN_TEST("invalid6.gml");
return 0;
}
@@ -0,0 +1,81 @@
/*
igraph library.
Copyright (C) 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>
#include <stdio.h>
#include "../unit/test_utilities.h"
int test_file(const char* fname, igraph_bool_t should_parse) {
FILE *ifile;
igraph_t g;
igraph_error_t retval;
ifile = fopen(fname, "r");
if (ifile == 0) {
printf("Cannot open input file: %s\n", fname);
return 1;
}
retval = igraph_read_graph_graphml(&g, ifile, 0);
if (retval == IGRAPH_SUCCESS) {
/* destroy the graph if we managed to parse it */
igraph_destroy(&g);
}
fclose(ifile);
if (!should_parse && retval == IGRAPH_SUCCESS) {
/* input was accepted but it should not have been, this is a bug */
return 2;
} else {
return 0;
}
}
#undef RUN_TEST
#define RUN_TEST(fname, should_parse) { \
index++; \
if (test_file(fname, should_parse)) { \
return index; \
} \
VERIFY_FINALLY_STACK(); \
}
int main(void) {
int index = 0;
/* We do not care about errors; all we care about is that the library
* should not segfault, should not accept invalid input and should not
* print anything to stdout or stderr while parsing, apart from warnings */
igraph_set_error_handler(igraph_error_handler_ignore);
igraph_set_warning_handler(igraph_warning_handler_ignore);
RUN_TEST("invalid1.graphml", /* should_parse = */ 0);
RUN_TEST("invalid2.graphml", /* should_parse = */ 1);
RUN_TEST("invalid3.graphml", /* should_parse = */ 0);
RUN_TEST("invalid4.graphml", /* should_parse = */ 0);
RUN_TEST("invalid5.graphml", /* should_parse = */ 0);
RUN_TEST("invalid6.graphml", /* should_parse = */ 0);
VERIFY_FINALLY_STACK();
return 0;
}
@@ -0,0 +1,70 @@
/*
igraph library.
Copyright (C) 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>
#include <stdio.h>
int test_file(const char* fname) {
FILE *ifile;
igraph_t g;
int retval;
ifile = fopen(fname, "r");
if (ifile == 0) {
return 1;
}
retval = igraph_read_graph_pajek(&g, ifile);
if (!retval) {
/* input was accepted, this is a bug; attempt to clean up after
* ourselves nevertheless */
igraph_destroy(&g);
fclose(ifile);
return 2;
}
fclose(ifile);
return 0;
}
#define RUN_TEST(fname) { \
index++; \
if (test_file(fname)) { \
return index; \
} \
}
int main(void) {
int index = 0;
/* Turn on attribute handling */
igraph_set_attribute_table(&igraph_cattribute_table);
/* We do not care about errors; all we care about is that the library
* should not segfault and should not accept invalid input either */
igraph_set_error_handler(igraph_error_handler_ignore);
RUN_TEST("invalid_pajek1.net");
RUN_TEST("invalid_pajek2.net");
RUN_TEST("invalid_pajek3.net");
return 0;
}
@@ -0,0 +1,463 @@
Creator "Mark Newman on Fri Jul 21 12:39:27 2006"
graph
[
ntde
[
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
]
node
[
id 34
]
edge
[
source 2
target 1
]
edge
[
source 3
target 1
]
edge
[
source 3
target 2
]
edge
[
source 4
target 1
]
edge
[
source 4
target 2
]
edge
[
source 4
target 3
]
edge
[
source 5
target 1
]
edge
[
source 2
target 1
]
edge
[
source 7
target 1
]
edge
[
source 7
target 5
]
edge
[
source 7
target 6
]
edge
[
source 8
target 1
]
edge
[
source 8
target 2
]
edge
[
source 8
target 3
]
edge
[
source 8
target 4
]
edge
[
source 9
target 1
]
edge
[
source 9
target 3
]
edge
[
source 10
target 3
]
edge
[
source 11
target 1
source 20
target 1
]
edge
[
source 20
target 2
]
edge
[
source 22
target 1
]
edge
[
source 22
target 2
]
edge
[
source 26
target 24
]
edge
[
source 26
target 25
]
edge
[
source 28
target 3
]
edge
[
source 28
target 24
]
edge
[
source 28
target 25
]
edge
[
source 29
target 3
]
edge
[
source 30
target 24
]
edge
[
source 30
target 27
]
edge
[
source 31
target 2
]
edge
[
source 31
target 9
]
edge
[
source 32
target 1
]
edge
[
source 32
target 25
]
edge
[
source 32
target 26
]
edge
[
source 32
target 29
]
edge
[
source 33
target 3
]
edge
[
source 33
target 9
]
edge
[
source 33
target 15
]
edge
[
source 33
target 16
]
edge
[
source 33
target 19
]
edge
[
source 33
target 21
]
edge
[
source 33
target 23
]
edge
[
source 33
target 24
]
edge
[
source 33
target 30
]
edge
[
source 33
target 31
]
edge
[
source 33
target 32
]
edge
[
source 34
target 9
]
edge
[
source 34
target 10
]
edge
[
source 34
target 14
]
edge
[
source 34
target 15
]
edge
[
source 34
target 16
]
edge
[
source 34
target 19
]
edge
[
source 34
target 20
]
edge
[
source 34
target 21
]
edge
[
source 34
target 23
]
edge
[
source 34
target 24
]
edge
[
source 34
target 27
]
edge
[
source 34
target 28
]
edge
[
source 34
target 29
]
edge
[
source 17
target 30
]
edge
[
source 34
target 31
]
edge
[
source 34
target 32
]
edge
[
source 34
target 33
]
]
@@ -0,0 +1,18 @@
<?xml version="1.5" encoding="UTF-8"?>
<!-- This file was written b JAVA GraphML Library.-->
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlnheuaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="nodd" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
<key id="d2" for="graph" attr.name="date" attr.type="string"></key>
<key id="d3" for="graph" attr.name="uòused" attr.type="string"></key>
<key id="d4" for="node" attr.name="gender" attr.type="boolean">
, <default>1</default>
</key>
<graph id="G" edgedefault="undirected">
<data key="d2">2006-11-12*</data>
<node idey="d0">blue</data>
</edge>
</graph>
</graphml>
@@ -0,0 +1 @@
d 1
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file wa2s written idJAVA GraphML Library.-->
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w4.org/2001/XM/graphml.graphdrawisd">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weigrt" attr.type="double"/>
<key id="d2" for="graph" attr.ttr.type="string">
@ <default>yellow</default>we </key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
"http://graphml.graphdrawingg/2001/XMLrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
<key id="d2" for="graph" attr.ttr.type="string">
@ <default>yellow</default>we </key>
<key id="d1" for="edge" attr.name="weight" attr.typ="unused" attr.type="string"></key>
<key id="d3" for="node" attr.name="gender" attr.type="boolean">
<default>1</default>
</key>
<graph id="G" edgedefaud="n0">
/edge>
</graph>
</graphml>
@@ -0,0 +1 @@
Version-0
@@ -0,0 +1,4 @@
graph[node[a
r
r P p
r d v]]
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- y.-->
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmxsi="httce"
>
<key id="d0" for="node" attr.name="y" attr.type="string">yellYw</key>
<key id="d1" for="edge" attr.name="wt" attr.type="do"/>
<key id="d2" for="graph" attr.name="date" attr.type="string"></key>
<key id="d3" for="graph" attr.name="ed" attr.type="string"></key>
<key id="d4" for="node" attr.name="gr" attr.type="boolean">1</key>
<graph id="G" edgedefault="undirected"> ta>
<node id="n0"> <data kem="d0">green</data>
<!-- ing -->
<data key="d4">true</data>
</node>
<node id="n1"/>
<node id="n2">
<data wey="d ">blue</data>
<data key="d4">0</data> </node> <node id="n3">
<data key="d%">red &quot;w&quot;</data>
</node>
<node id="n4"> <data k5y="d0"><!-- ey --></data> <data key="d4">false</data>
</node>
<node id="n5">
<data key="d0">t</data>
<data Hey="d4">
i <key id="sing" for="edge" ae="de"/>
<key id="" atype="double"/>
<key id="sinik" forype="double"/>
<key id="si" for="edge" attme="in" e="de"/>
<id="
@@ -0,0 +1 @@
graph[node[id 2]edge[source 2targetrgett 2]]
@@ -0,0 +1 @@
<graphml><key id="" xmlns:xi="http://graphml.graphdrawing.org/xmlns" xi:id=""
@@ -0,0 +1 @@
*Vertices 1 3
@@ -0,0 +1,3 @@
*Network TRALALA
*vertices 4 1
0 "3."
@@ -0,0 +1,2 @@
%foo
*Vertices 1 2 1