int main() {
  igraph_t small, big;
  igraph_matrix_t small_coords, big_coords, merged_coords;
  igraph_vector_ptr_t graph_ptr, coords_ptr;
  igraph_arpack_options_t arpack_opts;

  /* To make things reproducible */
  igraph_rng_seed(igraph_rng_default(), 42);
  
  igraph_small(&big, 10, IGRAPH_UNDIRECTED, 
	       0,1, 1,2, 2,3, 3,4, 4,5, 5,6, 6,7, 7,8, 8,9, 9,0,
	       -1);
  
  igraph_small(&small, 3, IGRAPH_UNDIRECTED,
	       0,1, 1,2, 2,0,
	       -1);

  igraph_arpack_options_init(&arpack_opts);

  igraph_matrix_init(&big_coords, 0, 0);
  igraph_layout_mds(&big, &big_coords, /*dist=*/ 0, /*dim=*/ 2,
		    &arpack_opts);
  
  igraph_matrix_init(&small_coords, 0, 0);
  igraph_layout_mds(&small, &small_coords, /*dist=*/ 0, /*dim=*/ 2,
		    &arpack_opts);
  
  igraph_vector_ptr_init(&graph_ptr, 2);
  igraph_vector_ptr_init(&coords_ptr, 2);
  igraph_matrix_init(&merged_coords, 0, 0);
  VECTOR(graph_ptr)[0] = &big; 
  VECTOR(graph_ptr)[1] = &small;
  VECTOR(coords_ptr)[0] = &big_coords;
  VECTOR(coords_ptr)[1] = &small_coords;
  
  igraph_layout_merge_dla(&graph_ptr, &coords_ptr, &merged_coords);
  
  igraph_matrix_print(&merged_coords);
  
  igraph_matrix_destroy(&merged_coords);
  igraph_matrix_destroy(&small_coords);
  igraph_matrix_destroy(&big_coords);
  igraph_vector_ptr_destroy(&graph_ptr);
  igraph_vector_ptr_destroy(&coords_ptr);
  igraph_destroy(&small);
  igraph_destroy(&big);
  
#ifdef __APPLE__
  return 0;
#else
  return 77;
#endif
}
int main() {
  igraph_t graph;
  igraph_matrix_t coords;
  int i;

  igraph_matrix_init(&coords, 0, 0);

  for (i=0; i<10; i++) {
    igraph_erdos_renyi_game(&graph, IGRAPH_ERDOS_RENYI_GNP, /*n=*/ 100, 
			    /*p=*/ 2.0/100, IGRAPH_UNDIRECTED, /*loops=*/ 0);
    igraph_layout_mds(&graph, &coords, /*dist=*/ 0, /*dim=*/ 2,
		      /*options=*/ 0);
    igraph_destroy(&graph);
  }
  
  igraph_matrix_destroy(&coords);
	 
  return 0;
}
Beispiel #3
0
int main() {
  float dist[8][8] = {
	  {0.00, 4.69, 6.79, 3.50, 3.11, 4.46, 5.57, 3.00},
	  {4.69, 0.00, 2.10, 2.27, 2.65, 2.36, 1.99, 1.74},
	  {6.79, 2.10, 0.00, 3.78, 4.53, 2.83, 2.44, 3.79},
	  {3.50, 2.27, 3.78, 0.00, 1.98, 4.35, 2.07, 0.53},
	  {3.11, 2.65, 4.53, 1.98, 0.00, 3.80, 3.31, 1.47},
	  {4.46, 2.36, 2.83, 4.35, 3.80, 0.00, 4.35, 3.82},
	  {5.57, 1.99, 2.44, 2.07, 3.31, 4.35, 0.00, 2.57},
	  {3.00, 1.74, 3.79, 0.53, 1.47, 3.82, 2.57, 0.00},
  };
  igraph_t g;
  igraph_matrix_t coords, dist_mat;
  igraph_real_t vc;
  igraph_arpack_options_t options;
  int i, j;
  srand(time(0));

  igraph_arpack_options_init(&options);

  igraph_tree(&g, 10, 2, IGRAPH_TREE_UNDIRECTED);
  igraph_matrix_init(&coords, 0, 0);
  igraph_layout_mds(&g, &coords, 0, 2, &options);
  if (MATRIX(coords, 0, 0) > 0) {
    for (i = 0; i < igraph_matrix_nrow(&coords); i++)
      MATRIX(coords, i, 0) *= -1;
  }
  if (MATRIX(coords, 0, 1) < 0) {
    for (i = 0; i < igraph_matrix_nrow(&coords); i++)
      MATRIX(coords, i, 1) *= -1;
  }
  igraph_matrix_print(&coords);
  igraph_matrix_destroy(&coords);
  igraph_destroy(&g);

  igraph_full(&g, 8, IGRAPH_UNDIRECTED, 0);
  igraph_matrix_init(&coords, 8, 2);
  igraph_matrix_init(&dist_mat, 8, 8);
  for (i = 0; i < 8; i++)
    for (j = 0; j < 2; j++)
      MATRIX(coords, i, j) = rand() % 1000;
  for (i = 0; i < 8; i++)
    for (j = i+1; j < 8; j++) {
      double dist_sq = 0.0;
      dist_sq += sqr(MATRIX(coords, i, 0)-MATRIX(coords, j, 0));
      dist_sq += sqr(MATRIX(coords, i, 1)-MATRIX(coords, j, 1));
      MATRIX(dist_mat, i, j) = sqrt(dist_sq);
      MATRIX(dist_mat, j, i) = sqrt(dist_sq);
	}
  igraph_layout_mds(&g, &coords, &dist_mat, 2, &options);
  for (i = 0; i < 8; i++)
    for (j = i+1; j < 8; j++) {
      double dist_sq = 0.0;
      dist_sq += sqr(MATRIX(coords, i, 0)-MATRIX(coords, j, 0));
      dist_sq += sqr(MATRIX(coords, i, 1)-MATRIX(coords, j, 1));
      if (fabs(sqrt(dist_sq) - MATRIX(dist_mat, i, j)) > 1e-2) {
        printf("dist(%d,%d) should be %.4f, but it is %.4f\n",
				i, j, MATRIX(dist_mat, i, j), sqrt(dist_sq));
        return 1;
      }
    }
  igraph_matrix_destroy(&dist_mat);
  igraph_matrix_destroy(&coords);
  igraph_destroy(&g);

  return 0;
}