예제 #1
0
int main() {
  
  igraph_t g;
  igraph_integer_t result;
  igraph_integer_t from, to;
  igraph_vector_t path;
  igraph_rng_t rng;
  igraph_rng_init(&rng, &igraph_rngtype_mt19937);
  
  igraph_barabasi_game(&g, 30, /*power=*/ 1, 30, 0, 0, /*A=*/ 1, 
		       IGRAPH_DIRECTED, IGRAPH_BARABASI_BAG, 
		       /*start_from=*/ 0, &rng);
  igraph_diameter(&g, &result, 0, 0, 0, IGRAPH_UNDIRECTED, 1);
  
/*   printf("Diameter: %li\n", (long int) result); */
  
  igraph_destroy(&g);

  igraph_ring(&g, 10, IGRAPH_DIRECTED, 0, 0);
  igraph_vector_init(&path, 0);
  igraph_diameter(&g, &result, &from, &to, &path, IGRAPH_DIRECTED, 1);
  printf("diameter: %li, from %li to %li\n", (long int) result,
	 (long int) from, (long int) to);
  print_vector(&path);
  
  igraph_vector_destroy(&path);
  igraph_destroy(&g);
  igraph_rng_destroy(&rng);

  return 0;
}
예제 #2
0
int main(void)
{
	igraph_integer_t diameter;
	igraph_t graph;
	igraph_rng_seed(igraph_rng_default(), 42);
	igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNP, 1000, 5.0/1000, IGRAPH_UNDIRECTED, IGRAPH_NO_LOOPS);
	igraph_diameter(&graph, &diameter, 0, 0, 0, IGRAPH_UNDIRECTED, 1);
	printf("Diameter of a random graph with average degree 5: %d\n", (int) diameter);

	igraph_destroy(&graph);
	return 0;
}
예제 #3
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;
}