int main() { igraph_t g; igraph_vector_ptr_t vecs; long int i; igraph_vs_t vs; igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 1); igraph_vector_ptr_init(&vecs, 5); for (i=0; i<igraph_vector_ptr_size(&vecs); i++) { VECTOR(vecs)[i] = calloc(1, sizeof(igraph_vector_t)); igraph_vector_init(VECTOR(vecs)[i], 0); } igraph_vs_vector_small(&vs, 1, 3, 5, 2, 1, -1); igraph_get_shortest_paths(&g, &vecs, 0, vs, IGRAPH_OUT); for (i=0; i<igraph_vector_ptr_size(&vecs); i++) { print_vector(VECTOR(vecs)[i]); igraph_vector_destroy(VECTOR(vecs)[i]); free(VECTOR(vecs)[i]); } igraph_vector_ptr_destroy(&vecs); igraph_vs_destroy(&vs); igraph_destroy(&g); return 0; }
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; }
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); }