//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;
    }
} 
Exemple #2
0
int check_simple() {

  igraph_t g;
  long int nodes=100;
  long int edges=1000;
  igraph_real_t p=3.0/nodes;
  long int runs=10;
  long int r, e, ecount;
  igraph_vector_t eids, pairs, path;

  srand(time(0));

  igraph_vector_init(&pairs, edges*2);
  igraph_vector_init(&path, 0);
  igraph_vector_init(&eids, 0);

  for (r=0; r<runs; r++) {
    igraph_erdos_renyi_game(&g, IGRAPH_ERDOS_RENYI_GNP, nodes, p, 
			    /*directed=*/ 0, /*loops=*/ 0);
    ecount=igraph_ecount(&g);
    for (e=0; e<edges; e++) {
      long int edge=RNG_INTEGER(0, ecount-1);
      VECTOR(pairs)[2*e] = IGRAPH_FROM(&g, edge);
      VECTOR(pairs)[2*e+1] = IGRAPH_TO(&g, edge);
    }
    igraph_get_eids(&g, &eids, &pairs, /*path=*/ 0, 0, /*error=*/ 1);
    for (e=0; e<edges; e++) {
      long int edge=VECTOR(eids)[e];
      long int from1=VECTOR(pairs)[2*e];
      long int to1=VECTOR(pairs)[2*e+1];
      long int from2=IGRAPH_FROM(&g, edge);
      long int to2=IGRAPH_TO(&g, edge);
      long int min1= from1 < to1 ? from1 : to1;
      long int max1= from1 < to1 ? to1 : from1;
      long int min2= from2 < to2 ? from2 : to2;
      long int max2= from2 < to2 ? to2 : from2;
      if (min1 != min2 || max1 != max2) {
	return 11;
      }
    }
    
    igraph_diameter(&g, /*res=*/ 0, /*from=*/ 0, /*to=*/ 0, &path,
		    IGRAPH_UNDIRECTED, /*unconn=*/ 1);
    igraph_get_eids(&g, &eids, /*pairs=*/ 0, &path, 0, /*error=*/ 1);
    for (e=0; e<igraph_vector_size(&path)-1; e++) {
      long int edge=VECTOR(eids)[e];
      long int from1=VECTOR(path)[e];
      long int to1=VECTOR(path)[e+1];
      long int from2=IGRAPH_FROM(&g, edge);
      long int to2=IGRAPH_TO(&g, edge);
      long int min1= from1 < to1 ? from1 : to1;
      long int max1= from1 < to1 ? to1 : from1;
      long int min2= from2 < to2 ? from2 : to2;
      long int max2= from2 < to2 ? to2 : from2;
      if (min1 != min2 || max1 != max2) {
	return 12;
      }
    }

    igraph_destroy(&g);
  }

  igraph_vector_destroy(&path);
  igraph_vector_destroy(&pairs);
  igraph_vector_destroy(&eids);

  return 0;
}