예제 #1
0
int main() {

  igraph_t graph;
  FILE *ifile = fopen("cattr_bool_bug.graphml", "r");

  if (!ifile) {
    printf("Cannot open input file");
    return 1;
  }

  igraph_i_set_attribute_table(&igraph_cattribute_table);

  igraph_read_graph_graphml(&graph, ifile, 0);
  fclose(ifile);

  check_attr(&graph, 10);

  igraph_to_directed(&graph, IGRAPH_TO_DIRECTED_ARBITRARY);

  check_attr(&graph, 20);

  if (GAB(&graph, "loops")) { return 2; }

  igraph_destroy(&graph);

  return 0;
}
예제 #2
0
int TMIgraph::readTopology(char *file_name) {
    int ret;
    Bitvector *lid;
    Bitvector *ilid;
    ifstream infile;
    string str;
    size_t found, first, second;
    FILE *instream;
    infile.open(file_name, ifstream::in);
    /*first the Global graph attributes - c igraph does not do it!!*/
    while (infile.good()) {
        getline(infile, str);
        found = str.find("<data key=\"FID_LEN\">");
        if (found != string::npos) {
            first = str.find(">");
            second = str.find("<", first);
            sscanf(str.substr(first + 1, second - first - 1).c_str(), "%d", &fid_len);
        }
        found = str.find("<data key=\"TM\">");
        if (found != string::npos) {
            first = str.find(">");
            second = str.find("<", first);
            nodeID = str.substr(first + 1, second - first - 1);
        }

        found = str.find("<data key=\"TM_MODE\">");
        if (found != string::npos) {
            first = str.find(">");
            second = str.find("<", first);
            mode = str.substr(first + 1, second - first - 1);
        }
    }
    infile.close();
    instream = fopen(file_name, "r");
    ret = igraph_read_graph_graphml(&graph, instream, 0);
    fclose(instream);
    if (ret < 0) {
        return ret;
    }
    cout << "TM: " << igraph_vcount(&graph) << " nodes" << endl;
    cout << "TM: " << igraph_ecount(&graph) << " edges" << endl;
    for (int i = 0; i < igraph_vcount(&graph); i++) {
        string nID = string(igraph_cattribute_VAS(&graph, "NODEID", i));
        string iLID = string(igraph_cattribute_VAS(&graph, "iLID", i));
        reverse_node_index.insert(pair<string, int>(nID, i));
        ilid = new Bitvector(iLID);
        nodeID_iLID.insert(pair<string, Bitvector *>(nID, ilid));
        vertex_iLID.insert(pair<int, Bitvector *>(i, ilid));
        //cout << "node " << i << " has NODEID " << nID << endl;
        //cout << "node " << i << " has ILID " << ilid->to_string() << endl;
    }
    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));
        lid = new Bitvector(LID);
        edge_LID.insert(pair<int, Bitvector *>(i, lid));
        //cout << "edge " << i << " has LID  " << lid->to_string() << endl;
    }
    return ret;
}
예제 #3
0
int main(int argc, char* argv[]) {
  if(argc != 2) {
	printf("USAGE: %s path/to/file.graphml.xml\n", argv[0]);
	return -1;
  }

  char* fileName = argv[1];

  igraph_attribute_table_t* oldHandler = igraph_i_set_attribute_table(&igraph_cattribute_table);
  FILE* graphFile = fopen(fileName, "r");
  if(!graphFile) {
	printf("error opening graph file at %s\n", fileName);
	return -2;
  }

  igraph_t graph;
  time_t start = time(NULL);
  int r = igraph_read_graph_graphml(&graph, graphFile, 0);
  time_t end = time(NULL);
  fclose(graphFile);

  if(r != IGRAPH_SUCCESS) {
	printf("error loading graph file at %s\n", fileName);
	r = -3;
  } else {
	printf("successfully loaded graph file at %s in %li seconds\n", fileName, (long int)(end-start));
	r = 0;
  }

  printf("graph has %li vertices and %li edges\n", (long int)igraph_vcount(&graph), (long int)igraph_ecount(&graph));

  igraph_integer_t largestCliqueSize = 0;
  start = time(NULL);
  r = igraph_clique_number(&graph, &largestCliqueSize);
  end = time(NULL);

  if(r != IGRAPH_SUCCESS) {
	printf("error computing igraph_clique_number\n");
	r = -4;
  } else {
	printf("igraph_clique_number = %i in %li seconds\n", (int) largestCliqueSize, (long int)(end-start));
	r = 0;
  }

  start = time(NULL);
  igraph_destroy(&graph);
  end = time(NULL);
  printf("igraph_destroy finished in %li seconds\n", (long int)end-start);

  return r;
}
예제 #4
0
static igraph_t* _tgengraph_loadNewGraph(const gchar* path) {
    /* get the file */
    FILE* graphFile = fopen(path, "r");
    if(!graphFile) {
        tgen_critical("fopen returned NULL, problem opening graph file path '%s'", path);
        return FALSE;
    }

    tgen_info("reading graphml action graph at '%s'...", path);

    igraph_t* graph = g_new0(igraph_t, 1);
    gint result = igraph_read_graph_graphml(graph, graphFile, 0);
    fclose(graphFile);

    if(result != IGRAPH_SUCCESS) {
        tgen_critical("igraph_read_graph_graphml return non-success code %i", result);
        g_free(graph);
        return NULL;
    }

    tgen_info("successfully read graphml action graph at '%s'", path);

    return graph;
}
예제 #5
0
int TEgraphMF::readTopology(const char *file_name) {
  int ret = 0;
  Bitvector* lid;
  Bitvector* ilid;
  ifstream infile;
  string str;
  size_t found, first, second;
  FILE *instream;
  infile.open(file_name, ifstream::in);
  /*first the Global graph attributes - c igraph does not do it!!*/
  while (infile.good()) {
    getline(infile, str);
    found = str.find("<data key=\"FID_LEN\">");
    if (found != string::npos) {
      first = str.find(">");
      second = str.find("<", first);
      sscanf(str.substr(first + 1, second - first - 1).c_str(), "%d", &fid_len);
    }
    found = str.find("<data key=\"TM\">");
    if (found != string::npos) {
      first = str.find(">");
      second = str.find("<", first);
      nodeID = str.substr(first + 1, second - first - 1);
    }
    found = str.find("<data key=\"RV\">");
    if (found != string::npos) {
      first = str.find(">");
      second = str.find("<", first);
      RVnodeID = str.substr(first + 1, second - first - 1);
    }
    found = str.find("<data key=\"TM_MODE\">");
    if (found != string::npos) {
      first = str.find(">");
      second = str.find("<", first);
      mode = str.substr(first + 1, second - first - 1);
    }
  }
  infile.close();
  instream = fopen(file_name, "r");
  if (instream == NULL) {
    return -1;
  }
  //EF_ALLOW_MALLOC_0=1;
  ret = igraph_read_graph_graphml(&graph, instream, 0);
  //EF_ALLOW_MALLOC_0=0;

  fclose(instream);
  if (ret < 0) {
    return ret;
  }
  //cout << "TM: " << igraph_vcount(&graph) << " nodes" << endl;
  //cout << "TM: " << igraph_ecount(&graph) << " edges" << endl;
  for (int i = 0; i < igraph_vcount(&graph); i++) {
    string nID = string(igraph_cattribute_VAS(&graph, "NODEID", i));
    string iLID = string(igraph_cattribute_VAS(&graph, "iLID", i));
    reverse_node_index.insert(pair<string, int>(nID, i));
    ilid = new Bitvector(iLID);
    nodeID_iLID.insert(pair<string, Bitvector* >(nID, ilid));
    vertex_iLID.insert(pair<int, Bitvector* >(i, ilid));
    cout<<"node "<<i<<" has NODEID"<<nID<<endl;
    cout<<"node "<<i<<" has ILID"<<ilid->to_string()<<endl;
  }
  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));
    lid = new Bitvector(LID);
    edge_LID.insert(pair<int, Bitvector* >(i, lid));

    igraph_integer_t head;
    igraph_integer_t tail;
    igraph_edge(&graph, i,&head,&tail);
    cout << "edge " << i 
	 <<" "<<head<<"->"<<tail<<" has LID  " 
	 << lid->to_string() << endl;
  }

  std::vector<int> edgepairs;
  std::vector<double> capacities;
  igraph_eit_t ieit;
  igraph_eit_create(&graph,igraph_ess_all(IGRAPH_EDGEORDER_ID),&ieit);
  while(!IGRAPH_EIT_END(ieit)) {
    igraph_integer_t edgeid = IGRAPH_EIT_GET(ieit);
    igraph_integer_t head;
    igraph_integer_t tail;
    // WARNING all edge capacities are give the same value
    // this needs to come from deployment script
    capacities.push_back(defaultBW);
    igraph_edge(&graph, edgeid,&head,&tail);
    cout<<"edge"<<head<<"->"<<tail<<endl;
    edgepairs.push_back(head);
    edgepairs.push_back(tail);
    IGRAPH_EIT_NEXT(ieit);
  }
  igraph_eit_destroy(&ieit);

  // create an initial dmand matrix assuming equal traffic
  // between all node pairs - unlikely to be correct but
  // as booststrap we do not know any better
  // THIS WILL NEED TO BE DYNAMICALLY UPDATED LATER
  for (int i = 0; i < igraph_vcount(&graph); i++) {
    for (int j = 0; j < igraph_vcount(&graph); j++) {
      if( i == j) continue;
      mf_demand demand;
      demand.source = i;
      demand.sink = j;
      // WARNING HARDCODED VALUE, ok for initial boostrap
      // as it is all relative. It should be obtained from
      // the deployment script as an initial demand.
      demand.demand = 1.0;
      demandMapMeasured.insert(pair<intpair,mf_demand>(intpair(i,j),
						       demand));
			       
					  
    }
  }

  graphMF = Graph_mf((int)igraph_vcount(&graph),edgepairs,capacities);

  // now demands are set to half the maximum flow when 
  // using shortest paths assuming equal flow between
  // all pairs - enough for boostrapping
  // initial demand matrix done!
  //update_paths();


     
  preCalculateFids();
  return ret;
}
예제 #6
0
int main(int argc, char* argv[])
{
  igraph_i_set_attribute_table(&igraph_cattribute_table);
  char * in_graph_fn;
  char * out_graph_fn;

  if (argc < 3) {
    printf("[ERROR] usage: mm-writer in_graph_fn out_graph_fn\n");
    exit(-1);
  }
  else {
    in_graph_fn = &argv[1][0];
    out_graph_fn = &argv[2][0];
  }
  
  igraph_t g;
  
  FILE *ifile, *ofile;

  ifile = fopen(in_graph_fn, "r");
  if (ifile == 0) {
    return 10;
  }
  
  igraph_read_graph_graphml(&g, ifile, 0);
  fclose(ifile);
  igraph_to_directed(&g, IGRAPH_TO_DIRECTED_ARBITRARY);

  printf("The graph stats:\n");
  printf("Vertices: %li\n", (long int) igraph_vcount(&g));
  printf("Edges: %li\n", (long int) igraph_ecount(&g));
  printf("Directed: %i\n", (int) igraph_is_directed(&g));
  
  ofile = fopen(out_graph_fn, "w");
  if (ofile == 0) {
    return 10;
  }
  
  // Write MM format
  fprintf(ofile, "%li %li %li\n", (long int) igraph_vcount(&g),
      (long int) igraph_vcount(&g), (long int) igraph_ecount(&g));

  igraph_integer_t to;
  igraph_integer_t from;
  igraph_integer_t eid;
  igraph_real_t weight;

  for (eid = 0; eid < (long int) igraph_ecount(&g); eid++) {
    igraph_edge(&g, eid, &from, &to);
    weight = igraph_cattribute_EAN(&g, "weight",eid); // TODO: time
    fprintf(ofile, "%i %i %f\n", from, to, weight);

    //printf("Edge %i => %i --> %i\n", eid, from, to);
    //printf("Edge %i has weight %f\n", eid, igraph_cattribute_EAN(&g, "weight",eid)); // TODO: time
  }

  // For all. TODO: time
#if 0
  igraph_es_t eids;
  igraph_es_all(&eids, IGRAPH_EDGEORDER_ID); // Order edges 

  igraph_vector_t result;
  igraph_vector_init(&result, (int long) igraph_ecount(&g));
  igraph_cattribute_EANV(&g, "weight", eids, &result);
  
  igraph_integer_t i;
  for (i = 0; i < (int long) igraph_ecount(&g); i++)
     printf("Edge %i value: %f\n", i, VECTOR(result)[i]);

  // Free memory
  igraph_es_destroy(&eids);
  igraph_vector_destroy(&result);
#endif
  igraph_destroy(&g);

  fclose(ofile);
  return 0;
}
예제 #7
0
int main(int argc, char **argv) {
  igraph_t g;
  igraph_error_handler_t* oldhandler;
  igraph_warning_handler_t* oldwarnhandler;
  int result;
  FILE *ifile, *ofile;

  igraph_i_set_attribute_table(&igraph_cattribute_table);

  /* GraphML */
  ifile=fopen("test.gxl", "r");
  if (ifile==0) {
    return 10;
  }
  
  oldhandler=igraph_set_error_handler(igraph_error_handler_ignore);
  oldwarnhandler=igraph_set_warning_handler(custom_warning_handler);
  if ((result=igraph_read_graph_graphml(&g, ifile, 0))) {
    /* maybe it is simply disabled at compile-time */
    if (result == IGRAPH_UNIMPLEMENTED) return 77;
    return 1;
  }
  igraph_set_error_handler(oldhandler);

  fclose(ifile);

  /* Write it back */
  ofile=fopen("test2.gxl", "w");
  /* If we can't create the test file, just skip the test */
  if (ofile) {
    if ((result=igraph_write_graph_graphml(&g, ofile, /*prefixattr=*/ 1))) {
      return 1;
    }
    fclose(ofile);
    unlink("test2.gxl");
  }
  dump_graph("The directed graph:\n", &g);
  igraph_destroy(&g);
 
  /* The same with undirected graph */
  ifile=fopen("test.gxl", "r");
  if ((result=igraph_read_graph_graphml(&g, ifile, 0))) {
    return 1;
  }
  fclose(ifile);
  dump_graph("The undirected graph:\n", &g);
  igraph_destroy(&g);

  /* Test a GraphML file with default attributes */
  ifile=fopen("graphml-default-attrs.xml", "r");
  if ((result=igraph_read_graph_graphml(&g, ifile, 0))) {
    return 1;
  }
  fclose(ifile);
  dump_graph("The directed graph:\n", &g);
  dump_vertex_attribute_bool("type", &g);
  dump_vertex_attribute_string("gender", &g);
  dump_vertex_attribute_numeric("age", &g);
  dump_vertex_attribute_bool("retired", &g);
  igraph_destroy(&g);

  /* Test a GraphML file with namespaces */
  ifile=fopen("graphml-namespace.xml", "r");
  if ((result=igraph_read_graph_graphml(&g, ifile, 0))) {
    return 1;
  }
  fclose(ifile);
  dump_graph("The undirected graph:\n", &g);
  igraph_destroy(&g);

  /* Restore the old warning handler */
  igraph_set_warning_handler(oldwarnhandler);

  /* There were sometimes problems with this file */
  /* Only if called from R though, and only on random occasions, once in every 
     ten reads. Do testing here doesn't make much sense, but if we have the file 
     then let's do it anyway. */
  ifile=fopen("graphml-hsa05010.xml", "r");  
  igraph_read_graph_graphml(&g, ifile, 0);
  fclose(ifile);
  igraph_destroy(&g);
  
  return 0;
}