int main() { igraph_t g, g2, cli; igraph_vector_t perm; igraph_vector_ptr_t cliques; igraph_integer_t no; int i; igraph_rng_seed(igraph_rng_default(), 42); /* Create a graph that has a random component, plus a number of relatively small cliques */ igraph_vector_init_seq(&perm, 0, NODES-1); igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNM, NODES, NODES, /*directed=*/ 0, /*loops=*/ 0, igraph_rng_default()); igraph_full(&cli, CLIQUE_SIZE, /*directed=*/ 0, /*loops=*/ 0); for (i=0; i<NO_CLIQUES; i++) { /* Permute vertices of g */ permutation(&perm); igraph_permute_vertices(&g, &g2, &perm); igraph_destroy(&g); g=g2; /* Add a clique */ igraph_union(&g2, &g, &cli, /*edge_map1=*/ 0, /*edge_map2=*/ 0); igraph_destroy(&g); g=g2; } igraph_simplify(&g, /*multiple=*/ 1, /*loop=*/ 0, /*edge_comb=*/ 0); igraph_vector_destroy(&perm); igraph_destroy(&cli); /* Find the maximal cliques */ igraph_vector_ptr_init(&cliques, 0); igraph_maximal_cliques(&g, &cliques, /*min_size=*/ 3, /*max_size=*/ 0 /*no limit*/); igraph_maximal_cliques_count(&g, &no, /*min_size=*/ 3, /*max_size=*/ 0 /*no limit*/); if (no != igraph_vector_ptr_size(&cliques)) { return 1; } /* Print and destroy them */ print_and_destroy_cliques(&cliques); /* Clean up */ igraph_vector_ptr_destroy(&cliques); igraph_destroy(&g); /* Build a triangle with a loop (thanks to Emmanuel Navarro) */ igraph_small(&g, 3, IGRAPH_UNDIRECTED, 0, 1, 1, 2, 2, 0, 0, 0, -1); /* Find the maximal cliques */ igraph_vector_ptr_init(&cliques, 0); igraph_maximal_cliques(&g, &cliques, /*min_size=*/ 3, /*max_size=*/ 0 /*no limit*/); igraph_maximal_cliques_count(&g, &no, /*min_size=*/ 3, /*max_size=*/ 0 /*no limit*/); if (no != igraph_vector_ptr_size(&cliques)) { return 2; } /* Print and destroy them */ print_and_destroy_cliques(&cliques); /* Clean up */ igraph_vector_ptr_destroy(&cliques); igraph_destroy(&g); return 0; }
void test_bliss() { igraph_t ring1, ring2, directed_ring; igraph_vector_t perm; igraph_bool_t iso; igraph_bliss_info_t info; igraph_vector_int_t color; igraph_vector_ptr_t generators; igraph_ring(&ring1, 100, /*directed=*/ 0, /*mutual=*/ 0, /*circular=*/1); igraph_vector_init_seq(&perm, 0, igraph_vcount(&ring1)-1); random_permutation(&perm); igraph_permute_vertices(&ring1, &ring2, &perm); igraph_ring(&directed_ring, 100, /* directed= */ 1, /* mutual = */0, /* circular = */1); igraph_vector_ptr_init(&generators, 0); IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&generators, igraph_vector_destroy); igraph_isomorphic_bliss(&ring1, &ring2, NULL, NULL, &iso, NULL, NULL, IGRAPH_BLISS_F, NULL, NULL); if (! iso) printf("Bliss failed on ring isomorphism.\n"); igraph_automorphisms(&ring1, NULL, IGRAPH_BLISS_F, &info); if (strcmp(info.group_size, "200") != 0) printf("Biss automorphism count failed: ring1.\n"); igraph_free(info.group_size); igraph_automorphisms(&ring2, NULL, IGRAPH_BLISS_F, &info); if (strcmp(info.group_size, "200") != 0) printf("Biss automorphism count failed: ring2.\n"); igraph_free(info.group_size); igraph_automorphisms(&directed_ring, NULL, IGRAPH_BLISS_F, &info); if (strcmp(info.group_size, "100") != 0) printf("Biss automorphism count failed: directed_ring.\n"); igraph_free(info.group_size); // The follwing test is included so there is at least one call to igraph_automorphism_group // in the test suite. However, the generator set returned may depend on the splitting // heursitics as well as on the Bliss version. If the test fails, please verify manually // that the generating set is valid. For a undirected cycle graph like ring2, there should // be two generators: a cyclic permutation and a reversal of the vertex order. igraph_automorphism_group(&ring2, NULL, &generators, IGRAPH_BLISS_F, NULL); if (igraph_vector_ptr_size(&generators) != 2) printf("Bliss automorphism generators may have failed with ring2. " "Please verify the generators manually. " "Note that the generator set is not guaranteed to be minimal.\n"); igraph_vector_ptr_free_all(&generators); // For a directed ring, the only generator should be a cyclic permutation. igraph_automorphism_group(&directed_ring, NULL, &generators, IGRAPH_BLISS_F, NULL); if (igraph_vector_ptr_size(&generators) != 1) printf("Bliss automorphism generators may have failed with directed_ring. " "Please verify the generators manually. " "Note that the generator set is not guaranteed to be minimal.\n"); igraph_vector_ptr_free_all(&generators); igraph_vector_int_init_seq(&color, 0, igraph_vcount(&ring1)-1); igraph_automorphisms(&ring1, &color, IGRAPH_BLISS_F, &info); if (strcmp(info.group_size, "1") != 0) printf("Biss automorphism count with color failed: ring1.\n"); igraph_free(info.group_size); // There's only one automorphism for this coloured graph, so the generating set is empty. igraph_automorphism_group(&ring1, &color, &generators, IGRAPH_BLISS_F, NULL); if (igraph_vector_ptr_size(&generators) != 0) printf("Bliss automorphism generators failed with colored graph.\n"); igraph_vector_ptr_destroy_all(&generators); igraph_vector_int_destroy(&color); igraph_vector_destroy(&perm); igraph_destroy(&ring1); igraph_destroy(&ring2); igraph_destroy(&directed_ring); }