Bitvector GraphRepresentation::calculateFID(string &source, string &destination) { int vertex_id; Bitvector result(dm->fid_len * 8); igraph_vs_t vs; igraph_vector_ptr_t res; igraph_vector_t to_vector; igraph_vector_t *temp_v; igraph_integer_t eid; /*find the vertex id in the reverse index*/ int from = (*reverse_node_index.find(source)).second; igraph_vector_init(&to_vector, 1); VECTOR(to_vector)[0] = (*reverse_node_index.find(destination)).second; /*initialize the sequence*/ igraph_vs_vector(&vs, &to_vector); /*initialize the vector that contains pointers*/ igraph_vector_ptr_init(&res, 1); temp_v = (igraph_vector_t *) VECTOR(res)[0]; temp_v = (igraph_vector_t *) malloc(sizeof (igraph_vector_t)); VECTOR(res)[0] = temp_v; igraph_vector_init(temp_v, 1); /*run the shortest path algorithm from "from"*/ igraph_get_shortest_paths(&igraph, &res, from, vs, IGRAPH_OUT); /*check the shortest path to each destination*/ temp_v = (igraph_vector_t *) VECTOR(res)[0]; //click_chatter("Shortest path from %s to %s", igraph_cattribute_VAS(&graph, "NODEID", from), igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[igraph_vector_size(temp_v) - 1])); /*now let's "or" the FIDs for each link in the shortest path*/ for (int j = 0; j < igraph_vector_size(temp_v) - 1; j++) { igraph_get_eid(&igraph, &eid, VECTOR(*temp_v)[j], VECTOR(*temp_v)[j + 1], true); //click_chatter("node %s -> node %s", igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[j]), igraph_cattribute_VAS(&graph, "NODEID", VECTOR(*temp_v)[j + 1])); //click_chatter("link: %s", igraph_cattribute_EAS(&graph, "LID", eid)); string LID(igraph_cattribute_EAS(&igraph, "LID", eid), dm->fid_len * 8); for (int k = 0; k < dm->fid_len * 8; k++) { if (LID[k] == '1') { (result)[ dm->fid_len * 8 - k - 1].operator |=(true); } } //click_chatter("FID of the shortest path: %s", result.to_string().c_str()); } /*now for all destinations "or" the internal linkID*/ vertex_id = (*reverse_node_index.find(destination)).second; string iLID(igraph_cattribute_VAS(&igraph, "iLID", vertex_id)); //click_chatter("internal link for node %s: %s", igraph_cattribute_VAS(&graph, "NODEID", vertex_id), iLID.c_str()); for (int k = 0; k < dm->fid_len * 8; k++) { if (iLID[k] == '1') { (result)[ dm->fid_len * 8 - k - 1].operator |=(true); } } igraph_vector_destroy((igraph_vector_t *) VECTOR(res)[0]); igraph_vector_destroy(&to_vector); igraph_vector_ptr_destroy_all(&res); igraph_vs_destroy(&vs); return result; }
int print_and_destroy(igraph_vector_ptr_t *cliques) { int i, n=igraph_vector_ptr_size(cliques); sort_cliques(cliques); for (i=0; i<n; i++) { igraph_vector_t *v=VECTOR(*cliques)[i]; igraph_vector_print(v); igraph_vector_destroy(v); } igraph_vector_ptr_destroy_all(cliques); return 0; }
void test_callback(const igraph_t *graph) { igraph_vector_ptr_t list; struct userdata ud; igraph_vector_ptr_init(&list, 0); igraph_cliques(graph, &list, 0, 0); ud.i = 0; ud.list = &list; igraph_cliques_callback(graph, 0, 0, &handler, (void *) &ud); IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&list, igraph_vector_destroy); igraph_vector_ptr_destroy_all(&list); }
void TMIgraph::calculateFID(string &source, string &destination, Bitvector &resultFID, unsigned int &numberOfHops) { int vertex_id; igraph_vs_t vs; igraph_vector_ptr_t res; igraph_vector_t to_vector; igraph_vector_t *temp_v; igraph_integer_t eid; /*find the vertex id in the reverse index*/ int from = (*reverse_node_index.find(source)).second; igraph_vector_init(&to_vector, 1); VECTOR(to_vector)[0] = (*reverse_node_index.find(destination)).second; /*initialize the sequence*/ igraph_vs_vector(&vs, &to_vector); /*initialize the vector that contains pointers*/ igraph_vector_ptr_init(&res, 1); temp_v = (igraph_vector_t *) VECTOR(res)[0]; temp_v = (igraph_vector_t *) malloc(sizeof (igraph_vector_t)); VECTOR(res)[0] = temp_v; igraph_vector_init(temp_v, 1); /*run the shortest path algorithm from "from"*/ igraph_get_shortest_paths(&graph, &res, from, vs, IGRAPH_OUT); /*check the shortest path to each destination*/ temp_v = (igraph_vector_t *) VECTOR(res)[0]; /*now let's "or" the FIDs for each link in the shortest path*/ for (int j = 0; j < igraph_vector_size(temp_v) - 1; j++) { igraph_get_eid(&graph, &eid, VECTOR(*temp_v)[j], VECTOR(*temp_v)[j + 1], true); Bitvector *lid = (*edge_LID.find(eid)).second; (resultFID) = (resultFID) | (*lid); } numberOfHops = igraph_vector_size(temp_v); /*now for the destination "or" the internal linkID*/ Bitvector *ilid = (*nodeID_iLID.find(destination)).second; (resultFID) = (resultFID) | (*ilid); //cout << "FID of the shortest path: " << resultFID.to_string() << endl; igraph_vector_destroy((igraph_vector_t *) VECTOR(res)[0]); igraph_vector_destroy(&to_vector); igraph_vector_ptr_destroy_all(&res); igraph_vs_destroy(&vs); }
void test4() { int i, j; igraph_vector_ptr_t graphs4; // Verify that no two 4-vertex graphs of distinct isoclasses are considered isomorphic by Bliss or VF2. igraph_vector_ptr_init(&graphs4, 0); IGRAPH_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&graphs4, igraph_destroy); for (i=0; i < 218; i++) { igraph_t *g; g = (igraph_t *) malloc(sizeof(igraph_t)); igraph_vector_ptr_push_back(&graphs4, g); igraph_isoclass_create(g, 4, i, /* directed = */ 1); } for (i=0; i < 218; i++) for (j=i+1; j < 218; j++) { igraph_bool_t iso; igraph_isomorphic_bliss( (igraph_t *) VECTOR(graphs4)[i], (igraph_t *) VECTOR(graphs4)[j], NULL, NULL, &iso, NULL, NULL, IGRAPH_BLISS_F, NULL, NULL); if (iso) printf("Bliss failure, 4 vertex directed graphs of isoclass %d and %d are not isomorphic. Bliss reports otherwise.\n", i, j); } for (i=0; i < 218; i++) for (j=i+1; j < 218; j++) { igraph_bool_t iso; igraph_isomorphic_vf2( (igraph_t *) VECTOR(graphs4)[i], (igraph_t *) VECTOR(graphs4)[j], NULL, NULL, NULL, NULL, &iso, NULL, NULL, NULL, NULL, NULL); if (iso) printf("VF2 failure, 4 vertex directed graphs of isoclass %d and %d are not isomorphic. VF2 reports otherwise.\n", i, j); } igraph_vector_ptr_destroy_all(&graphs4); }
int main() { igraph_vector_ptr_t v1, v2; igraph_vector_ptr_t v3=IGRAPH_VECTOR_PTR_NULL; int i; void ** ptr; int d1=1, d2=2, d3=3, d4=4, d5=5; char *block1=0, *block2=0; /* igraph_vector_ptr_init, igraph_vector_ptr_destroy */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_destroy(&v1); igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_free_all, igraph_vector_ptr_destroy_all */ igraph_vector_ptr_init(&v1, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_free_all(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { VECTOR(v1)[i]=(void*)malloc(i*10); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_reserve */ igraph_vector_ptr_init(&v1, 0); igraph_vector_ptr_reserve(&v1, 5); igraph_vector_ptr_reserve(&v1, 15); igraph_vector_ptr_reserve(&v1, 1); igraph_vector_ptr_reserve(&v1, 0); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_empty, igraph_vector_ptr_clear */ igraph_vector_ptr_init(&v1, 10); if (igraph_vector_ptr_empty(&v1)) { return 1; } igraph_vector_ptr_clear(&v1); if (!igraph_vector_ptr_empty(&v1)) { return 2; } /* igraph_vector_ptr_size */ if (igraph_vector_ptr_size(&v1) != 0) { return 3; } igraph_vector_ptr_resize(&v1, 10); if (igraph_vector_ptr_size(&v1) != 10) { return 4; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_push_back */ igraph_vector_ptr_init(&v1, 0); for (i=0; i<10; i++) { igraph_vector_ptr_push_back(&v1, (void*)malloc(i*10)); } igraph_vector_ptr_destroy_all(&v1); /* igraph_vector_ptr_e */ igraph_vector_ptr_init(&v1, 5); VECTOR(v1)[0]=&d1; VECTOR(v1)[1]=&d2; VECTOR(v1)[2]=&d3; VECTOR(v1)[3]=&d4; VECTOR(v1)[4]=&d5; if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_set */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 5; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 6; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 7; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 8; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 9; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_null */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_null(&v1); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if (VECTOR(v1)[i] != 0) { return 10; } } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_resize */ igraph_vector_ptr_init(&v1, 10); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_resize(&v1, 10); igraph_vector_ptr_resize(&v1, 15); igraph_vector_ptr_resize(&v1, 5); if (igraph_vector_ptr_size(&v1) != 5) { return 11; } if (igraph_vector_ptr_e(&v1, 0) != &d1) { return 12; } if (igraph_vector_ptr_e(&v1, 1) != &d2) { return 13; } if (igraph_vector_ptr_e(&v1, 2) != &d3) { return 14; } if (igraph_vector_ptr_e(&v1, 3) != &d4) { return 15; } if (igraph_vector_ptr_e(&v1, 4) != &d5) { return 16; } igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_view */ ptr=(void**) malloc(5 * sizeof(void*)); igraph_vector_ptr_view(&v3, ptr, 5); ptr[0]=&d1; ptr[1]=&d2; ptr[2]=&d3; ptr[3]=&d4; ptr[4]=&d5; for (i=0; i<igraph_vector_ptr_size(&v3); i++) { if ( *((int*)VECTOR(v3)[i]) != i+1) { return 17; } } /* igraph_vector_ptr_init_copy */ igraph_vector_ptr_init_copy(&v1, ptr, 5); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)VECTOR(v1)[i]) != i+1) { return 18; } } /* igraph_vector_ptr_copy_to */ igraph_vector_ptr_copy_to(&v1, ptr); for (i=0; i<igraph_vector_ptr_size(&v1); i++) { if ( *((int*)ptr[i]) != i+1) { return 19; } } free(ptr); igraph_vector_ptr_destroy(&v1); /* igraph_vector_ptr_copy */ igraph_vector_ptr_init(&v1, 5); igraph_vector_ptr_set(&v1, 0, &d1); igraph_vector_ptr_set(&v1, 1, &d2); igraph_vector_ptr_set(&v1, 2, &d3); igraph_vector_ptr_set(&v1, 3, &d4); igraph_vector_ptr_set(&v1, 4, &d5); igraph_vector_ptr_copy(&v2, &v1); igraph_vector_ptr_destroy(&v1); for (i=0; i<igraph_vector_ptr_size(&v2); i++) { if ( *((int*)VECTOR(v2)[i]) != i+1) { return 20; } } /* igraph_vector_ptr_remove */ igraph_vector_ptr_remove(&v2, 0); igraph_vector_ptr_remove(&v2, 3); if ( *((int*)VECTOR(v2)[0]) != 2) { return 21; } if ( *((int*)VECTOR(v2)[1]) != 3) { return 22; } if ( *((int*)VECTOR(v2)[2]) != 4) { return 23; } igraph_vector_ptr_destroy(&v2); /* Testing destructor */ igraph_vector_ptr_init(&custom_destructor_stack, 0); igraph_vector_ptr_init(&v1, 2); block1 = igraph_Calloc(32, char); block2 = igraph_Calloc(64, char); VECTOR(v1)[0] = block1; VECTOR(v1)[1] = block2; if (igraph_vector_ptr_get_item_destructor(&v1) != 0) { return 24; } if (igraph_vector_ptr_set_item_destructor(&v1, &custom_destructor) != 0) { return 25; } /* Okay, let's clear the vector. This should push the blocks in the * custom destructor stack */ igraph_vector_ptr_clear(&v1); /* Put the blocks back and destroy the vector */ igraph_vector_ptr_push_back(&v1, block1); igraph_vector_ptr_push_back(&v1, block2); igraph_vector_ptr_destroy_all(&v1); if (VECTOR(custom_destructor_stack)[0] != block1 || VECTOR(custom_destructor_stack)[1] != block2 || VECTOR(custom_destructor_stack)[2] != block1 || VECTOR(custom_destructor_stack)[3] != block2 ) return 26; igraph_vector_ptr_destroy(&custom_destructor_stack); if (IGRAPH_FINALLY_STACK_SIZE() != 0) return 27; 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); }