예제 #1
0
int GraphRepresentation::buildIGraphTopology() {
    int source_vertex_id, destination_vertex_id;
    igraph_i_set_attribute_table(&igraph_cattribute_table);
    igraph_empty(&igraph, 0, true);
    //cout << "iGraph: number of nodes: " << dm->number_of_nodes << endl;
    //cout << "iGraph: number number_of_connections nodes: " << dm->number_of_connections << endl;
    for (int i = 0; i < dm->network_nodes.size(); i++) {
        NetworkNode *nn = dm->network_nodes[i];
        for (int j = 0; j < nn->connections.size(); j++) {
            NetworkConnection *nc = nn->connections[j];
            map <string, int>::iterator index_it;
            /*find that node - if exists*/
            index_it = reverse_node_index.find(nc->src_label);
            /*check if the source node exists in the reverse index*/
            if (index_it == reverse_node_index.end()) {
                /*it does not exist...add it*/
                source_vertex_id = igraph_vcount(&igraph);
                igraph_add_vertices(&igraph, 1, 0);
                reverse_node_index.insert(pair<string, int>(nc->src_label, source_vertex_id));
                igraph_cattribute_VAS_set(&igraph, "NODEID", source_vertex_id, nc->src_label.c_str());
                //cout << "added node " << nc->src_label << " in the igraph" << endl;
            } else {
                source_vertex_id = (*index_it).second;
            }
            index_it = reverse_node_index.find(nc->dst_label);
            /*check if the destination node exists in the reverse index*/
            if (index_it == reverse_node_index.end()) {
                /*it does not exist...add it*/
                destination_vertex_id = igraph_vcount(&igraph);
                igraph_add_vertices(&igraph, 1, 0);
                reverse_node_index.insert(pair<string, int>(nc->dst_label, destination_vertex_id));
                igraph_cattribute_VAS_set(&igraph, "NODEID", destination_vertex_id, nc->dst_label.c_str());
                //cout << "added node " << nc->dst_label << " in the igraph" << endl;
            } else {
                destination_vertex_id = (*index_it).second;
            }
            /*add an edge in the graph*/
            igraph_add_edge(&igraph, source_vertex_id, destination_vertex_id);
            igraph_cattribute_EAS_set(&igraph, "LID", igraph_ecount(&igraph) - 1, nc->LID.to_string().c_str());
            reverse_edge_index.insert(pair<string, int>(nc->LID.to_string(), igraph_ecount(&igraph) - 1));
        }
    }
    for (int i = 0; i < dm->network_nodes.size(); i++) {
        NetworkNode *nn = dm->network_nodes[i];
        igraph_cattribute_VAS_set(&igraph, "iLID", i, nn->iLid.to_string().c_str());
    }
}
예제 #2
0
//resiliency function for use later when supporting resiliency inside TE 
void TEgraphMF::updateGraph(string &source, string &destination, string &net, bool update_op){
  igraph_vector_t v;
  igraph_es_t es;
  igraph_vector_t eids;
  int src_v = (*reverse_node_index.find(source)).second;
  int dst_v = (*reverse_node_index.find(destination)).second;
  string pairs[2];
  pairs[0]=source + "/" + destination;
  pairs[1]=destination + "/" + source;
     if(net != "e"){
      igraph_vector_init(&v, 2);
      igraph_vector_init(&eids,1);
      VECTOR(v)[0]=src_v;
      VECTOR(v)[1]=dst_v;
    } else {
      igraph_vector_init(&v, 4);
      igraph_vector_init(&eids,2);
      VECTOR(v)[0]=src_v;
      VECTOR(v)[1]=dst_v;
      VECTOR(v)[2]=dst_v;
      VECTOR(v)[3]=src_v;
    }
    if(update_op){
      if(rmv_edge_lid.find(pairs[0]) != rmv_edge_lid.end()){
	igraph_add_edge(&graph, src_v, dst_v);
	Bitvector *lid=new Bitvector();
	lid = (*rmv_edge_lid.find(pairs[0])).second;
	igraph_cattribute_EAS_set(&graph, "LID", igraph_ecount(&graph) - 1, lid->to_string().c_str());
	rmv_edge_lid.erase(pairs[0]);
	if((net=="e")&&(rmv_edge_lid.find(pairs[1]) != rmv_edge_lid.end())){
	  igraph_add_edge(&graph,dst_v , src_v);
	  Bitvector *lid=new Bitvector();
	  lid = (*rmv_edge_lid.find(pairs[1])).second;
	  igraph_cattribute_EAS_set(&graph, "LID", igraph_ecount(&graph) - 1, lid->to_string().c_str());
	  rmv_edge_lid.erase(pairs[1]);
	}
	cout<<"TM: Link Recovery: " << source << " - " << destination <<endl;
      }
    }else {
      if(net =="e"){
      if ((rmv_edge_lid.find(pairs[0]) != rmv_edge_lid.end()) || (rmv_edge_lid.find(pairs[1]) != rmv_edge_lid.end())){
	cout << "TM: Reported Edges are alreday disconnected" << endl;
      } else {
	igraph_es_pairs(&es, &v, true);
#if IGRAPH_V >= IGRAPH_V_0_6
	igraph_get_eids(&graph, &eids, &v, NULL, true, false);
# else 
	igraph_get_eids(&graph, &eids, &v, true);
#endif
	for (int j = 0; j <= igraph_vector_size(&eids) - 1; j++) {
	  Bitvector *lid = (*edge_LID.find(VECTOR(eids)[j])).second;
	  rmv_edge_lid.insert(pair<string, Bitvector *>(pairs[j],lid));
	}
	igraph_delete_edges(&graph, es);
      }
      } else if (net=="o"){
	if(rmv_edge_lid.find(pairs[0]) != rmv_edge_lid.end()){
	  cout << "TM: Reproted Edge is already disconnected" << endl;
	} else {
	    igraph_es_pairs(&es, &v, true);
#if IGRAPH_V >= IGRAPH_V_0_6
	    igraph_get_eids(&graph, &eids, &v,NULL, true, false);
# else 
	    igraph_get_eids(&graph, &eids, &v, true);
#endif
	    for (int j = 0; j <= igraph_vector_size(&eids) - 1; j++) {
	      Bitvector *lid = (*edge_LID.find(VECTOR(eids)[j])).second;
	      rmv_edge_lid.insert(pair<string, Bitvector *>(pairs[j],lid));
	    }
	    igraph_delete_edges(&graph, es);
	  }
	}
      }
    //mjreed MEMORY LEAK HERE
    reverse_edge_index.clear();
    edge_LID.clear();
    for (int i = 0; i < igraph_ecount(&graph); i++) {
      string LID = string(igraph_cattribute_EAS(&graph, "LID", i));
      reverse_edge_index.insert(pair<string, int>(LID, i));
      Bitvector* lid = new Bitvector(LID);
      edge_LID.insert(pair<int, Bitvector *>(i, lid));
      //cout << "edge " << i << " has LID  " << lid->to_string() << endl;
    }
}