int main(void) { igraph_real_t avg_path; igraph_t graph; igraph_vector_t dimvector; igraph_vector_t edges; int i; igraph_vector_init(&dimvector, 2); VECTOR(dimvector)[0]=30; VECTOR(dimvector)[1]=30; igraph_lattice(&graph, &dimvector, 0, IGRAPH_UNDIRECTED, 0, 1); igraph_rng_seed(igraph_rng_default(), 42); igraph_vector_init(&edges, 20); for (i=0; i<igraph_vector_size(&edges); i++) { VECTOR(edges)[i] = rand() % (int)igraph_vcount(&graph); } igraph_average_path_length(&graph, &avg_path, IGRAPH_UNDIRECTED, 1); printf("Average path length (lattice): %f\n", (double) avg_path); igraph_add_edges(&graph, &edges, 0); igraph_average_path_length(&graph, &avg_path, IGRAPH_UNDIRECTED, 1); printf("Average path length (randomized lattice): %f\n", (double) avg_path); igraph_vector_destroy(&dimvector); igraph_vector_destroy(&edges); igraph_destroy(&graph); return 0; }
int check_lattice(const lat_test_t *test) { igraph_t graph, othergraph; igraph_vector_t otheredges; igraph_vector_t dimvector; igraph_bool_t iso; int ret; /* Create lattice */ igraph_vector_view(&dimvector, test->dimedges, test->dim); igraph_lattice(&graph, &dimvector, test->nei, test->directed, test->mutual, test->circular); /* Check its properties */ if ((ret=check_lattice_properties(&graph, &dimvector, test->directed, test->mutual, test->circular))) { igraph_destroy(&graph); printf("Lattice properties are not satisfied\n"); return ret; } /* Check that it is isomorphic to the stored graph */ igraph_vector_view(&otheredges, test->dimedges+test->dim, test->m * 2); igraph_create(&othergraph, &otheredges, igraph_vector_prod(&dimvector), test->directed); igraph_isomorphic(&graph, &othergraph, &iso); if (!iso) { printf("--\n"); igraph_write_graph_edgelist(&graph, stdout); printf("--\n"); igraph_write_graph_edgelist(&othergraph, stdout); igraph_destroy(&graph); igraph_destroy(&othergraph); return 50; } igraph_destroy(&graph); igraph_destroy(&othergraph); return 0; }