Пример #1
0
int main() {

  igraph_t g;
  int ret;

  igraph_atlas(&g, 45);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_atlas(&g, 0);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_atlas(&g, 1252);
  igraph_write_graph_edgelist(&g, stdout);
  printf("\n");
  igraph_destroy(&g);

  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_atlas(&g, -1);
  if (ret != IGRAPH_EINVAL) {
    return 1;
  }

  ret=igraph_atlas(&g, 1253);
  if (ret != IGRAPH_EINVAL) {
    return 2;
  }

  return 0;
}
Пример #2
0
char * ggen_vname(char *s, igraph_t *g, unsigned long id)
{
	/* WARNING: this should be changed if igraph-0.6 gets
	 * stable.
	 * We need to ignore some igraph_cattribute errors
	 * because we try to retrieve special attributes (ggen specifics).
	 * igraph version 0.6 include a cattribute_has_attr that should be
	 * used instead of ignoring errors.
	 */
	char * r = NULL;
	igraph_error_handler_t *error_handler;
	error_handler = igraph_set_error_handler(igraph_error_handler_ignore);
	r = vid2vname_unsafe(s,g,id);
	igraph_set_error_handler(error_handler);
	return r;
}
Пример #3
0
int main() {

  igraph_t g;
  igraph_vector_t v;
  int ret;
  igraph_es_t es;

  igraph_vector_init(&v, 8);
  VECTOR(v)[0]=0; VECTOR(v)[1]=1;
  VECTOR(v)[2]=1; VECTOR(v)[3]=2;
  VECTOR(v)[4]=2; VECTOR(v)[5]=3;
  VECTOR(v)[6]=2; VECTOR(v)[7]=2;
  igraph_create(&g, &v, 0, 0);
  
  igraph_es_pairs_small(&es, IGRAPH_DIRECTED, 3,2, -1);
  igraph_delete_edges(&g, es);
  if (igraph_ecount(&g) != 3) {
    return 1;
  }

  /* error test, no such edge to delete */
  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_delete_edges(&g, es);
  if (ret != IGRAPH_EINVAL) {
    printf("Error code: %i\n", ret);
    return 2;
  } 
  if (igraph_ecount(&g) != 3) {
    return 3;
  }

  /* error test, invalid vertex id */
  igraph_es_destroy(&es);
  igraph_es_pairs_small(&es, IGRAPH_DIRECTED, 10,2, -1);
  ret=igraph_delete_edges(&g, es);
  if (ret != IGRAPH_EINVVID) {
    return 4;
  } 
  if (igraph_ecount(&g) != 3) {
    return 5;
  }
  
  /* error test, invalid (odd) length */
  igraph_es_destroy(&es);
  igraph_es_pairs_small(&es, IGRAPH_DIRECTED, 0,1,2, -1);
  ret=igraph_delete_edges(&g, es);
  if (ret != IGRAPH_EINVAL) {
    return 6;
  } 
  if (igraph_ecount(&g) != 3) {
    return 7;
  }  

  igraph_es_destroy(&es);
  igraph_vector_destroy(&v);
  igraph_destroy(&g);
  
  return 0;
}
Пример #4
0
int main() {
  
  igraph_t g;
  igraph_vector_t v1, v2;
  int ret;
  
  /* simple use */
  igraph_vector_init(&v1, 8);
  VECTOR(v1)[0]=0; VECTOR(v1)[1]=1;
  VECTOR(v1)[2]=1; VECTOR(v1)[3]=2;
  VECTOR(v1)[4]=2; VECTOR(v1)[5]=3;
  VECTOR(v1)[6]=2; VECTOR(v1)[7]=2;
  igraph_create(&g, &v1, 0, 0);
  if (igraph_vcount(&g) != 4) {
    return 1;
  }
  igraph_vector_init(&v2, 0);
  igraph_get_edgelist(&g, &v2, 0);
  igraph_vector_sort(&v1);
  igraph_vector_sort(&v2);
  if (!igraph_vector_all_e(&v1, &v2)) {
    return 2;
  }
  igraph_destroy(&g);
  
  /* higher number of vertices */
  igraph_create(&g, &v1, 10, 0);
  if (igraph_vcount(&g) != 10) {
    return 1;
  }
  igraph_get_edgelist(&g, &v2, 0);
  igraph_vector_sort(&v1);
  igraph_vector_sort(&v2);
  if (!igraph_vector_all_e(&v1, &v2)) {
    return 3;
  }
  igraph_destroy(&g);

  /* error: IGRAPH_EINVEVECTOR */
  igraph_set_error_handler(igraph_error_handler_ignore);
  igraph_vector_resize(&v1, 9);
  VECTOR(v1)[8]=0;
  ret=igraph_create(&g, &v1, 0, 0);
  if (ret != IGRAPH_EINVEVECTOR) {
    return 4;
  }
  
  /* error: IGRAPH_EINVVID */
  igraph_vector_resize(&v1, 8);
  VECTOR(v1)[7]=-1;
  ret=igraph_create(&g, &v1, 10, 1);
  if (ret != IGRAPH_EINVVID) {
    return 5;
  }
  igraph_vector_destroy(&v1);
  igraph_vector_destroy(&v2);

  return 0;
}
Пример #5
0
int main() {
  
  igraph_t g;
  int ret;

  /* empty directed graph, zero vertices */
  igraph_empty(&g, 0, 1);
  if (igraph_vcount(&g) != 0) {
    return 1;
  }
  if (igraph_ecount(&g) != 0) {
    return 2;
  }
  igraph_destroy(&g);
  
  /* empty undirected graph, zero vertices */
  igraph_empty(&g, 0, 0);
  if (igraph_vcount(&g) != 0) {
    return 3;
  }
  if (igraph_ecount(&g) != 0) {
    return 4;
  }
  igraph_destroy(&g);

  /* empty directed graph, 20 vertices */
  igraph_empty(&g, 20, 1);
  if (igraph_vcount(&g) != 20) {
    return 5;
  }
  if (igraph_ecount(&g) != 0) {
    return 6;
  }
  igraph_destroy(&g);
  
  /* empty undirected graph, 30 vertices */
  igraph_empty(&g, 30, 0);
  if (igraph_vcount(&g) != 30) {
    return 7;
  }
  if (igraph_ecount(&g) != 0) {
    return 8;
  }
  igraph_destroy(&g);

  /* error: negative number of vertices */
  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_empty(&g, -1, 0);
  if (ret != IGRAPH_EINVAL) {
    return 9;
  }

  return 0;
}
int main() {

  igraph_t g;
  igraph_vector_t v;
  int ret;

  /* without edges */
  igraph_empty(&g, 5, IGRAPH_DIRECTED);
  igraph_add_vertices(&g, 2, 0);
  igraph_add_vertices(&g, 3, 0);
  igraph_add_vertices(&g, 1, 0);
  igraph_add_vertices(&g, 4, 0);
  if (igraph_vcount(&g) != 15)  {
    return 1;
  }
  igraph_delete_vertices(&g, igraph_vss_1(2));
  if (igraph_vcount(&g) != 14)  {
    return 2;
  }
  igraph_destroy(&g);
   
  igraph_vector_init(&v, 8);
  VECTOR(v)[0]=0; VECTOR(v)[1]=1;
  VECTOR(v)[2]=1; VECTOR(v)[3]=2;
  VECTOR(v)[4]=2; VECTOR(v)[5]=3;
  VECTOR(v)[6]=2; VECTOR(v)[7]=2;
  igraph_create(&g, &v, 0, 0);
  igraph_vector_destroy(&v);

  /* resize vector */
  igraph_delete_vertices(&g, igraph_vss_1(2));
  if (igraph_vcount(&g) != 3) {
    return 3;
  }
  if (igraph_ecount(&g) != 1) {
    return 4;
  }

  /* error test */
  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_delete_vertices(&g, igraph_vss_1(3));
  if (ret != IGRAPH_EINVVID) {
    return 5;
  }
  
  igraph_destroy(&g);

  return 0;
}
Пример #7
0
int main() {

  igraph_t g;
  igraph_vector_t v, res, reset, weights;
  igraph_arpack_options_t arpack_options;
  igraph_real_t value;
  int ret;
  igraph_pagerank_power_options_t power_options;

  /* Test graphs taken from http://www.iprcom.com/papers/pagerank/ */
  igraph_vector_init(&v, 10);
  VECTOR(v)[0]=0; VECTOR(v)[1]=1;
  VECTOR(v)[2]=1; VECTOR(v)[3]=2;
  VECTOR(v)[4]=2; VECTOR(v)[5]=0;
  VECTOR(v)[6]=3; VECTOR(v)[7]=2;
  VECTOR(v)[8]=0; VECTOR(v)[9]=2;
  igraph_create(&g, &v, 0, 1);

  igraph_vector_init(&res, 0);
  oldwarn=igraph_set_warning_handler(warning_handler_stdout);
  igraph_pagerank_old(&g, &res, igraph_vss_all(), 1, 1000, 0.001, 0.85, 0);
  print_vector(&res, stdout);
  igraph_vector_destroy(&res);
  igraph_vector_destroy(&v);
  
  igraph_destroy(&g);

  igraph_vector_init(&v, 28);
  VECTOR(v)[ 0]=0; VECTOR(v)[ 1]=1;
  VECTOR(v)[ 2]=0; VECTOR(v)[ 3]=2;
  VECTOR(v)[ 4]=0; VECTOR(v)[ 5]=3;
  VECTOR(v)[ 6]=1; VECTOR(v)[ 7]=0;
  VECTOR(v)[ 8]=2; VECTOR(v)[ 9]=0;
  VECTOR(v)[10]=3; VECTOR(v)[11]=0;
  VECTOR(v)[12]=3; VECTOR(v)[13]=4;
  VECTOR(v)[14]=3; VECTOR(v)[15]=5;
  VECTOR(v)[16]=3; VECTOR(v)[17]=6;
  VECTOR(v)[18]=3; VECTOR(v)[19]=7;
  VECTOR(v)[20]=4; VECTOR(v)[21]=0;
  VECTOR(v)[22]=5; VECTOR(v)[23]=0;
  VECTOR(v)[24]=6; VECTOR(v)[25]=0;
  VECTOR(v)[26]=7; VECTOR(v)[27]=0;
  igraph_create(&g, &v, 0, 1);

  igraph_vector_init(&res, 0);
  igraph_pagerank_old(&g, &res, igraph_vss_all(), 1, 10000, 0.0001, 0.85, 0);
  print_vector(&res, stdout);
  igraph_vector_destroy(&res);
  igraph_vector_destroy(&v);
  igraph_destroy(&g);

  igraph_set_warning_handler(oldwarn);

  /* New PageRank */
  igraph_star(&g, 11, IGRAPH_STAR_UNDIRECTED, 0);
  igraph_vector_init(&res, 0);
  igraph_arpack_options_init(&arpack_options);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, &arpack_options);
  print_vector(&res, stdout);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, 0);
  print_vector(&res, stdout);
  /* Check twice more for consistency */
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, &arpack_options);
  print_vector(&res, stdout);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, 0);
  print_vector(&res, stdout);

  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, &arpack_options);
  print_vector(&res, stdout);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
		  igraph_vss_all(), 0, 0.85, 0, 0);
  print_vector(&res, stdout);

  /* Check personalized PageRank */
  igraph_personalized_pagerank_vs(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
				  igraph_vss_all(), 0, 0.5,
				  igraph_vss_1(1), 0, &arpack_options);
  print_vector(&res, stdout);
  igraph_personalized_pagerank_vs(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
				  igraph_vss_all(), 0, 0.5,
				  igraph_vss_1(1), 0, 0);
  print_vector(&res, stdout);

  /* Errors */
  power_options.niter = -1; power_options.eps=0.0001;
  igraph_set_error_handler(igraph_error_handler_ignore);
  igraph_set_warning_handler(igraph_warning_handler_ignore);
  ret=igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
		      /*value=*/ 0, igraph_vss_all(), 1, 0.85,
		      /*weights=*/ 0, &power_options);
  if (ret != IGRAPH_EINVAL) {
    return 1;
  }
  
  power_options.niter=10000; power_options.eps=-1;
  ret=igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
		      /*value=*/ 0, igraph_vss_all(), 1, 0.85,
		      /*weights=*/ 0, &power_options);
  if (ret != IGRAPH_EINVAL) {
    return 2;
  }

  power_options.niter=10000; power_options.eps=0.0001;
  ret=igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_POWER, &res,
		      /*value=*/ 0, igraph_vss_all(), 1, 1.2,
		      /*weights=*/ 0, &power_options);
  if (ret != IGRAPH_EINVAL) {
    return 3;
  }

  igraph_vector_init(&reset, 2);
  ret=igraph_personalized_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
				   igraph_vss_all(), 0, 0.85, &reset, 0,
				   &arpack_options);
  if (ret != IGRAPH_EINVAL) {
    return 4;
  }
  ret=igraph_personalized_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
				   igraph_vss_all(), 0, 0.85, &reset, 0, 0);
  if (ret != IGRAPH_EINVAL) {
    return 4;
  }
  igraph_vector_resize(&reset, 10);
  igraph_vector_fill(&reset, 0);
  ret=igraph_personalized_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK,
				   &res, 0, igraph_vss_all(), 0, 0.85,
				   &reset, 0, &arpack_options);
  if (ret != IGRAPH_EINVAL) {
    return 5;
  }
  ret=igraph_personalized_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK,
				   &res, 0, igraph_vss_all(), 0, 0.85,
				   &reset, 0, 0);
  if (ret != IGRAPH_EINVAL) {
    return 5;
  }
  igraph_vector_destroy(&reset);
  igraph_destroy(&g);
  igraph_set_error_handler(igraph_error_handler_abort);

  /* Special cases: check for empty graph */
  igraph_empty(&g, 10, 0);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, &value,
		  igraph_vss_all(), 1, 0.85, 0, &arpack_options);
  if (value != 1.0) {
    return 6;
  }
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, &value,
		  igraph_vss_all(), 1, 0.85, 0, 0);
  if (value != 1.0) {
    return 6;
  }
  print_vector(&res, stdout);
  igraph_destroy(&g);

  /* Special cases: check for full graph, zero weights */
  igraph_full(&g, 10, 0, 0);
  igraph_vector_init(&v, 45);
  igraph_vector_fill(&v, 0);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, &value,
		  igraph_vss_all(), 1, 0.85, &v, &arpack_options);
  if (value != 1.0) {
    return 7;
  }
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, &value,
		  igraph_vss_all(), 1, 0.85, &v, 0);
  if (value != 1.0) {
    return 7;
  }
  igraph_vector_destroy(&v);
  print_vector(&res, stdout);
  igraph_destroy(&g);

  /* Another test case for PageRank (bug #792352) */
  igraph_small(&g, 9, 1, 0, 5, 1, 5, 2, 0, 3, 1, 5, 4, 5, 7, 6, 0, 8, 0, 8, 1, -1);
  igraph_vector_init(&weights, 9);
  VECTOR(weights)[0] = 4; VECTOR(weights)[1] = 5; VECTOR(weights)[2] = 5;
  VECTOR(weights)[3] = 4; VECTOR(weights)[4] = 4; VECTOR(weights)[5] = 4;
  VECTOR(weights)[6] = 3; VECTOR(weights)[7] = 4; VECTOR(weights)[8] = 4;
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_ARPACK, &res, 0,
		  igraph_vss_all(), 1, 0.85, &weights, &arpack_options);
  print_vector(&res, stdout);
  igraph_pagerank(&g, IGRAPH_PAGERANK_ALGO_PRPACK, &res, 0,
		  igraph_vss_all(), 1, 0.85, &weights, 0);
  print_vector(&res, stdout);
  igraph_vector_destroy(&weights);
  igraph_destroy(&g);

  igraph_vector_destroy(&res);
  return 0;
}
Пример #8
0
int ggen_write_graph(igraph_t *g, FILE *output)
{
	Agraph_t *cg;
	Agnode_t *f,*t;
	Agedge_t *edge;
	igraph_vector_ptr_t vertices;
	igraph_eit_t eit;
	int err;
	unsigned long i,j;
	unsigned long vcount = igraph_vcount(g);
	igraph_integer_t from,to;
	char name[GGEN_DEFAULT_NAME_SIZE];
	char *str = NULL;
	igraph_strvector_t gnames,vnames,enames;
	igraph_vector_t gtypes,vtypes,etypes;
	Agsym_t *attr;
	/* see warning below */
	igraph_error_handler_t *error_handler;

	err = igraph_vector_ptr_init(&vertices,vcount);
	if(err) return 1;

	/* WARNING: this should be changed if igraph-0.6 gets
	 * stable.
	 * We need to ignore some igraph_cattribute errors
	 * because we try to retrieve special attributes (ggen specifics).
	 * igraph version 0.6 include a cattribute_has_attr that should be
	 * used instead of ignoring errors.
	 */
	error_handler = igraph_set_error_handler(igraph_error_handler_ignore);

	/* open graph
	 * its name is saved in __ggen_graph_name if it exists
	 */
	str =(char *) GAS(g,GGEN_GRAPH_NAME_ATTR);
	if(!str)
		cg = agopen(GGEN_DEFAULT_GRAPH_NAME,Agdirected,NULL);
	else
		cg = agopen(str,Agdirected,NULL);

	if(!cg)
	{
		err = 1;
		goto d_v;
	}

	/* save a pointer to each vertex */
	for(i = 0; i < vcount; i++)
	{
		/* find a vertex name */
		str = vid2vname_unsafe(name,g,i);
		if(!str)
			f = agnode(cg,name,1);
		else
			f = agnode(cg,str,1);
		VECTOR(vertices)[i] = (void *)f;
	}

	/* We have finished with dangerous attributes accesses */
	igraph_set_error_handler(error_handler);

	/* now loop through edges in the igraph */
	err = igraph_eit_create(g,igraph_ess_all(IGRAPH_EDGEORDER_ID),&eit);
	if(err) goto c_ag;

	for(IGRAPH_EIT_RESET(eit); !IGRAPH_EIT_END(eit); IGRAPH_EIT_NEXT(eit))
	{
		err = igraph_edge(g,IGRAPH_EIT_GET(eit),&from,&to);
		if(err) goto d_eit;

		f = (Agnode_t *) VECTOR(vertices)[(unsigned long)from];
		t = (Agnode_t *) VECTOR(vertices)[(unsigned long)to];
		agedge(cg,f,t,NULL,1);
	}

	/* find all properties */
	igraph_strvector_init(&gnames,1);
	igraph_strvector_init(&vnames,vcount);
	igraph_strvector_init(&enames,igraph_ecount(g));
	igraph_vector_init(&gtypes,1);
	igraph_vector_init(&vtypes,vcount);
	igraph_vector_init(&etypes,igraph_ecount(g));

	err = igraph_cattribute_list(g,&gnames,&gtypes,&vnames,&vtypes,&enames,&etypes);
	if(err) goto d_eit;

	/* add graph properties */
	for(i = 0; i < igraph_strvector_size(&gnames); i++)
	{
		if(strcmp(GGEN_GRAPH_NAME_ATTR,STR(gnames,i)))
		{
			if(VECTOR(gtypes)[i]==IGRAPH_ATTRIBUTE_NUMERIC) {
				snprintf(name,GGEN_DEFAULT_NAME_SIZE,"%f",
						(double)GAN(g,STR(gnames,i)));
				agattr(cg,AGRAPH,(char *)STR(gnames,i),name);
			}
			else
				agattr(cg,AGRAPH,(char *)STR(gnames,i),
						(char *)GAS(g,STR(gnames,i)));
		}
	}

	/* add vertex properties */
	for(i = 0; i < igraph_strvector_size(&vnames); i++)
	{
		if(strcmp(GGEN_VERTEX_NAME_ATTR,STR(vnames,i)))
		{
			/* creates the attribute but we still need to set it for each vertex */
			attr = agattr(cg,AGNODE,(char *)STR(vnames,i),GGEN_CGRAPH_DEFAULT_VALUE);
			for(j = 0; j < vcount; j++)
			{
				f = (Agnode_t *) VECTOR(vertices)[j];
				if(VECTOR(vtypes)[i]==IGRAPH_ATTRIBUTE_NUMERIC) {
					snprintf(name,GGEN_DEFAULT_NAME_SIZE,"%f",
							(double)VAN(g,STR(vnames,i),j));
					agxset(f,attr,name);
				}
				else
					agxset(f,attr,(char *)VAS(g,STR(vnames,i),j));
			}
		}
	}

	/* add edges properties */
	for(i = 0; i < igraph_strvector_size(&enames); i++)
	{
		/* creates the attribute but we still need to set it for each edge */
		attr = agattr(cg,AGEDGE,(char *)STR(enames,i),GGEN_CGRAPH_DEFAULT_VALUE);
		for(j = 0; j < igraph_ecount(g); j++)
		{
			igraph_edge(g,j,&from,&to);
			f = (Agnode_t *) VECTOR(vertices)[(unsigned long)from];
			t = (Agnode_t *) VECTOR(vertices)[(unsigned long)to];
			edge = agedge(cg,f,t,NULL,0);
			if(VECTOR(etypes)[i]==IGRAPH_ATTRIBUTE_NUMERIC) {
				snprintf(name,GGEN_DEFAULT_NAME_SIZE,"%f",
						(double)EAN(g,STR(enames,i),j));
				agxset(edge,attr,name);
			}
			else
				agxset(edge,attr,(char *)EAS(g,STR(enames,i),j));
		}
	}

	/* write the graph */
	err = agwrite(cg,(void *)output);
d_eit:
	igraph_eit_destroy(&eit);
c_ag:
	agclose(cg);
d_v:
	igraph_vector_ptr_destroy(&vertices);
	return err;
}
/**
 * \ingroup interface
 * \function igraph_add_edges
 * \brief Adds edges to a graph object. 
 * 
 * </para><para>
 * The edges are given in a vector, the
 * first two elements define the first edge (the order is
 * <code>from</code>, <code>to</code> for directed
 * graphs). The vector 
 * should contain even number of integer numbers between zero and the
 * number of vertices in the graph minus one (inclusive). If you also
 * want to add new vertices, call igraph_add_vertices() first.
 * \param graph The graph to which the edges will be added.
 * \param edges The edges themselves.
 * \param attr The attributes of the new edges, only used by high level
 *        interfaces currently, you can supply 0 here.
 * \return Error code:
 *    \c IGRAPH_EINVEVECTOR: invalid (odd)
 *    edges vector length, \c IGRAPH_EINVVID:
 *    invalid vertex id in edges vector. 
 *
 * This function invalidates all iterators.
 *
 * </para><para>
 * Time complexity: O(|V|+|E|) where
 * |V| is the number of vertices and
 * |E| is the number of
 * edges in the \em new, extended graph.
 */
int igraph_add_edges(igraph_t *graph, const igraph_vector_t *edges,
		     void *attr) {
  long int no_of_edges=igraph_vector_size(&graph->from);
  long int edges_to_add=igraph_vector_size(edges)/2;
  long int i=0;
  igraph_error_handler_t *oldhandler;
  int ret1, ret2;
  igraph_vector_t newoi, newii;
  igraph_bool_t directed=igraph_is_directed(graph);

  if (igraph_vector_size(edges) % 2 != 0) {
    IGRAPH_ERROR("invalid (odd) length of edges vector", IGRAPH_EINVEVECTOR);
  }
  if (!igraph_vector_isininterval(edges, 0, igraph_vcount(graph)-1)) {
    IGRAPH_ERROR("cannot add edges", IGRAPH_EINVVID);
  }

  /* from & to */
  IGRAPH_CHECK(igraph_vector_reserve(&graph->from, no_of_edges+edges_to_add));
  IGRAPH_CHECK(igraph_vector_reserve(&graph->to  , no_of_edges+edges_to_add));

  while (i<edges_to_add*2) {
    if (directed || VECTOR(*edges)[i] > VECTOR(*edges)[i+1]) {
      igraph_vector_push_back(&graph->from, VECTOR(*edges)[i++]); /* reserved */
      igraph_vector_push_back(&graph->to,   VECTOR(*edges)[i++]); /* reserved */
    } else {
      igraph_vector_push_back(&graph->to,   VECTOR(*edges)[i++]); /* reserved */
      igraph_vector_push_back(&graph->from, VECTOR(*edges)[i++]); /* reserved */
    }      
  }

  /* disable the error handler temporarily */
  oldhandler=igraph_set_error_handler(igraph_error_handler_ignore);
    
  /* oi & ii */
  ret1=igraph_vector_init(&newoi, no_of_edges);
  ret2=igraph_vector_init(&newii, no_of_edges);
  if (ret1 != 0 || ret2 != 0) {
    igraph_vector_resize(&graph->from, no_of_edges); /* gets smaller */
    igraph_vector_resize(&graph->to, no_of_edges);   /* gets smaller */
    igraph_set_error_handler(oldhandler);
    IGRAPH_ERROR("cannot add edges", IGRAPH_ERROR_SELECT_2(ret1, ret2));
  }  
  ret1=igraph_vector_order(&graph->from, &graph->to, &newoi, graph->n);
  ret2=igraph_vector_order(&graph->to  , &graph->from, &newii, graph->n);
  if (ret1 != 0 || ret2 != 0) {
    igraph_vector_resize(&graph->from, no_of_edges);
    igraph_vector_resize(&graph->to, no_of_edges);
    igraph_vector_destroy(&newoi);
    igraph_vector_destroy(&newii);
    igraph_set_error_handler(oldhandler);
    IGRAPH_ERROR("cannot add edges", IGRAPH_ERROR_SELECT_2(ret1, ret2));
  }  

  /* Attributes */
  if (graph->attr) { 
    ret1=igraph_i_attribute_add_edges(graph, edges, attr);
    if (ret1 != 0) {
      igraph_vector_resize(&graph->from, no_of_edges);
      igraph_vector_resize(&graph->to, no_of_edges);
      igraph_vector_destroy(&newoi);
      igraph_vector_destroy(&newii);
      igraph_set_error_handler(oldhandler);
      IGRAPH_ERROR("cannot add edges", ret1);
    }  
  }
  
  /* os & is, its length does not change, error safe */
  igraph_i_create_start(&graph->os, &graph->from, &newoi, graph->n);
  igraph_i_create_start(&graph->is, &graph->to  , &newii, graph->n);

  /* everything went fine  */
  igraph_vector_destroy(&graph->oi);
  igraph_vector_destroy(&graph->ii);
  graph->oi=newoi;
  graph->ii=newii;
  igraph_set_error_handler(oldhandler);
  
  return 0;
}
int main() {
  igraph_t g;
  igraph_vector_t weights, result;
  igraph_bool_t dag;
  int retval;

  igraph_vector_init(&result, 0);

  igraph_set_error_handler(&igraph_error_handler_printignore);

  /***********************************************************************/
  /* Exact solution with integer programming                             */
  /***********************************************************************/

  /* Simple unweighted graph */
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,1, 1,2, 2,0, 2,3, 2,4, 0,4, 4,3, 5,0, 6,5, -1);
  retval = igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_EXACT_IP);
  if (retval == IGRAPH_UNIMPLEMENTED)
    return 77;
  igraph_vector_print(&result);
  igraph_delete_edges(&g, igraph_ess_vector(&result));
  igraph_is_dag(&g, &dag);
  if (!dag)
    return 1;
  igraph_destroy(&g);

  /* Simple weighted graph */
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,1, 1,2, 2,0, 2,3, 2,4, 0,4, 4,3, 5,0, 6,5, -1);
  igraph_vector_init_int_end(&weights, -1, 1, 1, 3, 1, 1, 1, 1, 1, 1, -1);
  igraph_feedback_arc_set(&g, &result, &weights, IGRAPH_FAS_EXACT_IP);
  igraph_vector_print(&result);
  igraph_delete_edges(&g, igraph_ess_vector(&result));
  igraph_is_dag(&g, &dag);
  if (!dag)
    return 2;
  igraph_vector_destroy(&weights);
  igraph_destroy(&g);

  /* Simple unweighted graph with loops */
  igraph_small(&g, 0, IGRAPH_DIRECTED, 0,1, 1,2, 2,0, 2,3, 2,4, 0,4, 4,3, 5,0, 6,5, 1,1, 4,4, -1);
  igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_EXACT_IP);
  igraph_vector_print(&result);
  igraph_delete_edges(&g, igraph_ess_vector(&result));
  igraph_is_dag(&g, &dag);
  if (!dag)
    return 3;
  igraph_destroy(&g);

  /* Disjoint union of two almost identical graphs */
  igraph_small(&g, 0, IGRAPH_DIRECTED,
      0,1, 1,2, 2,0, 2,3,  2,4,  0,4,  4,3,    5,0,  6,5, 1,1, 4,4,
      7,8, 8,9, 9,7, 9,10, 9,11, 7,11, 11,10, 12,7, 13,12,
      -1);
  igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_EXACT_IP);
  igraph_vector_print(&result);
  igraph_delete_edges(&g, igraph_ess_vector(&result));
  igraph_is_dag(&g, &dag);
  if (!dag)
    return 4;
  igraph_destroy(&g);

  /* Graph with lots of isolated vertices */
  igraph_small(&g, 10000, IGRAPH_DIRECTED, 0,1, -1);
  igraph_feedback_arc_set(&g, &result, 0, IGRAPH_FAS_EXACT_IP);
  igraph_vector_print(&result);
  igraph_delete_edges(&g, igraph_ess_vector(&result));
  igraph_is_dag(&g, &dag);
  if (!dag)
    return 5;
  igraph_destroy(&g);

  igraph_vector_destroy(&result);

  return 0;
}
Пример #11
0
int main() {
  
  igraph_t g;
  igraph_vector_t weights;
  igraph_real_t weights_data_0[] = { 0,2,1, 0,5,2, 1,1,0, 2,2,8, 1,1,3, 1,1,4, 2,1 };
  igraph_real_t weights_data_1[] = { 6,7,8,-4,-2,-3,9,2,7 };
  igraph_real_t weights_data_2[] = { 6,7,2,-4,-2,-3,9,2,7 };
  igraph_matrix_t res;
  
  /* Graph with only positive weights */
  igraph_small(&g, 10, IGRAPH_DIRECTED, 
	       0,1, 0,2, 0,3,    1,2, 1,4, 1,5,
	       2,3, 2,6,         3,2, 3,6,
	       4,5, 4,7,         5,6, 5,8, 5,9,
	       7,5, 7,8,         8,9,
	       5,2,
	       2,1,
	       -1);
  
  igraph_vector_view(&weights, weights_data_0, 
		     sizeof(weights_data_0)/sizeof(igraph_real_t));
  
  igraph_matrix_init(&res, 0, 0);
  igraph_shortest_paths_bellman_ford(&g, &res, igraph_vss_all(), igraph_vss_all(),
				     &weights, IGRAPH_OUT);
  print_matrix(&res);
  
  igraph_matrix_destroy(&res);
  igraph_destroy(&g);

  printf("\n");

  /***************************************/

  /* Graph with negative weights */
  igraph_small(&g, 5, IGRAPH_DIRECTED, 
	       0,1, 0,3, 1,3, 1,4, 2,1, 3,2, 3,4, 4,0, 4,2, -1);
  
  igraph_vector_view(&weights, weights_data_1, 
		     sizeof(weights_data_1)/sizeof(igraph_real_t));
  
  igraph_matrix_init(&res, 0, 0);
  igraph_shortest_paths_bellman_ford(&g, &res, igraph_vss_all(), 
				     igraph_vss_all(), &weights, IGRAPH_OUT);
  print_matrix(&res);
  
  /***************************************/

  /* Same graph with negative loop */
  igraph_set_error_handler(igraph_error_handler_ignore);
  igraph_vector_view(&weights, weights_data_2, 
		     sizeof(weights_data_2)/sizeof(igraph_real_t));
  if (igraph_shortest_paths_bellman_ford(&g, &res, igraph_vss_all(),
					 igraph_vss_all(),
                                         &weights, IGRAPH_OUT) != IGRAPH_ENEGLOOP)
    return 1;
  
  igraph_matrix_destroy(&res);
  igraph_destroy(&g);

  if (!IGRAPH_FINALLY_STACK_EMPTY) return 1;

  return 0;
}
Пример #12
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;
}
Пример #13
0
int main() {
  igraph_t g;
  igraph_vector_t deg;
  igraph_bool_t is_simple;

  igraph_set_error_handler(&igraph_error_handler_ignore);

  igraph_vector_init(&deg, 0);

  /* k-regular undirected graph, even degrees, no multiple edges */
  igraph_k_regular_game(&g, 10, 4, 0, 0);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_ALL, 1);
  igraph_vector_print(&deg);
  igraph_is_simple(&g, &is_simple);
  if (!is_simple)
	  return 1;
  if (igraph_is_directed(&g))
	  return 1;
  igraph_destroy(&g);

  /* k-regular undirected graph, odd degrees, even number of vertices, no multiple edges */
  igraph_k_regular_game(&g, 10, 3, 0, 0);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_ALL, 1);
  igraph_vector_print(&deg);
  igraph_is_simple(&g, &is_simple);
  if (!is_simple)
	  return 2;
  if (igraph_is_directed(&g))
	  return 2;
  igraph_destroy(&g);

  /* k-regular undirected graph, odd degrees, odd number of vertices, no multiple edges */
  if (!igraph_k_regular_game(&g, 9, 3, 0, 0))
	  return 3;

  /* k-regular undirected graph, even degrees, multiple edges */
  igraph_k_regular_game(&g, 10, 4, 0, 1);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_ALL, 1);
  igraph_vector_print(&deg);
  if (igraph_is_directed(&g))
	  return 14;
  igraph_destroy(&g);

  /* k-regular undirected graph, odd degrees, even number of vertices, multiple edges */
  igraph_k_regular_game(&g, 10, 3, 0, 1);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_ALL, 1);
  igraph_vector_print(&deg);
  if (igraph_is_directed(&g))
	  return 15;
  igraph_destroy(&g);

  /* k-regular undirected graph, odd degrees, odd number of vertices, multiple edges */
  if (!igraph_k_regular_game(&g, 9, 3, 0, 1))
	  return 4;

  /* k-regular directed graph, even degrees, no multiple edges */
  igraph_k_regular_game(&g, 10, 4, 1, 0);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  igraph_is_simple(&g, &is_simple);
  if (!is_simple)
	  return 5;
  if (!igraph_is_directed(&g))
	  return 5;
  igraph_destroy(&g);

  /* k-regular directed graph, odd degrees, even number of vertices, no multiple edges */
  igraph_k_regular_game(&g, 10, 3, 1, 0);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  igraph_is_simple(&g, &is_simple);
  if (!is_simple)
	  return 6;
  if (!igraph_is_directed(&g))
	  return 6;
  igraph_destroy(&g);

  /* k-regular directed graph, odd degrees, odd number of vertices, no multiple edges */
  igraph_k_regular_game(&g, 9, 3, 1, 0);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  igraph_is_simple(&g, &is_simple);
  if (!is_simple)
	  return 7;
  if (!igraph_is_directed(&g))
	  return 7;
  igraph_destroy(&g);

  /* k-regular directed graph, even degrees, multiple edges */
  igraph_k_regular_game(&g, 10, 4, 1, 1);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  if (!igraph_is_directed(&g))
	  return 16;
  igraph_destroy(&g);

  /* k-regular directed graph, odd degrees, even number of vertices, multiple edges */
  igraph_k_regular_game(&g, 10, 3, 1, 1);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  if (!igraph_is_directed(&g))
	  return 17;
  igraph_destroy(&g);

  /* k-regular directed graph, odd degrees, odd number of vertices, multiple edges */
  igraph_k_regular_game(&g, 9, 3, 1, 1);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_IN, 1);
  igraph_vector_print(&deg);
  igraph_degree(&g, &deg, igraph_vss_all(), IGRAPH_OUT, 1);
  igraph_vector_print(&deg);
  if (!igraph_is_directed(&g))
	  return 18;
  igraph_destroy(&g);

  /* k-regular undirected graph, too large degree, no multiple edges */
  if (!igraph_k_regular_game(&g, 10, 10, 0, 0))
	  return 8;

  /* k-regular directed graph, too large degree, no multiple edges */
  if (!igraph_k_regular_game(&g, 10, 10, 1, 0))
	  return 9;

  /* empty graph */
  if (igraph_k_regular_game(&g, 0, 0, 0, 0))
	  return 10;
  if (igraph_vcount(&g) != 0 || igraph_ecount(&g) != 0 || igraph_is_directed(&g))
	  return 11;
  igraph_destroy(&g);
  if (igraph_k_regular_game(&g, 0, 0, 1, 0))
	  return 12;
  if (igraph_vcount(&g) != 0 || igraph_ecount(&g) != 0 || !igraph_is_directed(&g))
	  return 13;
  igraph_destroy(&g);

  igraph_vector_destroy(&deg);

  return 0;
}
Пример #14
0
void Init_igraph(){

  //Modules
  VALUE cIGraph_generate;
  VALUE cIGraph_genrandom;
  VALUE cIGraph_connectivity;
  VALUE cIGraph_mincuts;
  VALUE cIGraph_layout;
  VALUE cIGraph_clique;
  VALUE cIGraph_indyver;
  VALUE cIGraph_isomor;
  VALUE cIGraph_motifs;
  VALUE cIGraph_sorting;
  VALUE cIGraph_filewrite;
  VALUE cIGraph_fileread;
  VALUE cIGraph_community;
  VALUE cIGraph_shortestpaths;
  VALUE cIGraph_neighborhoodm;
  VALUE cIGraph_components;
  VALUE cIGraph_closenessm;
  VALUE cIGraph_spanning;
  VALUE cIGraph_transitivitym;
  VALUE cIGraph_spectral;
  VALUE cIGraph_kcore;
  VALUE cIGraph_otherop;
  VALUE cIGraph_randomise;

  igraph_i_set_attribute_table(&cIGraph_attribute_table);
  igraph_set_error_handler(cIGraph_error_handler);
  igraph_set_warning_handler(cIGraph_warning_handler);  

  cIGraph      = rb_define_class("IGraph",      rb_cObject);
  cIGraphError = rb_define_class("IGraphError", rb_eRuntimeError);

  rb_define_alloc_func(cIGraph, cIGraph_alloc);
  rb_define_method(cIGraph, "initialize",      cIGraph_initialize, -1);
  rb_define_method(cIGraph, "initialize_copy", cIGraph_init_copy,   1);

  rb_include_module(cIGraph, rb_mEnumerable);

  
  /* Functions for deterministically generating graphs. */
  cIGraph_generate = rb_define_module_under(cIGraph, "Generate");
  rb_include_module(cIGraph, cIGraph_generate);       

  rb_define_singleton_method(cIGraph_generate, "adjacency", cIGraph_adjacency, 2); /* in cIGraph_generators_deterministic.c */
  rb_define_singleton_method(cIGraph_generate, "star", cIGraph_star, 3); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "lattice", cIGraph_lattice, 4); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "ring", cIGraph_ring, 4); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "tree", cIGraph_tree, 3); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "full", cIGraph_full, 3); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "atlas", cIGraph_atlas, 1); /* in cIGraph_generators_deterministic.c */ 
  rb_define_singleton_method(cIGraph_generate, "extended_chordal_ring", cIGraph_extended_chordal_ring, 2); /* in cIGraph_generators_deterministic.c */ 

  /* Functions for randomly generating graphs. */
  cIGraph_genrandom = rb_define_module_under(cIGraph, "GenerateRandom");
  rb_include_module(cIGraph, cIGraph_genrandom);       

  rb_define_singleton_method(cIGraph_genrandom, "grg_game", cIGraph_grg_game, 3); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "barabasi_game", cIGraph_barabasi_game, 4); /* in cIGraph_generators_random.c */ 
  rb_define_singleton_method(cIGraph_genrandom, "nonlinear_barabasi_game", cIGraph_nonlinear_barabasi_game, 6); /* in cIGraph_generators_random.c */ 
  rb_define_singleton_method(cIGraph_genrandom, "erdos_renyi_game", cIGraph_erdos_renyi_game, 5); /* in cIGraph_generators_random.c */ 
  rb_define_singleton_method(cIGraph_genrandom, "watts_strogatz_game", cIGraph_watts_strogatz_game, 4); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "degree_sequence_game", cIGraph_degree_sequence_game, 2); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "growing_random_game", cIGraph_growing_random_game, 4); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "callaway_traits_game", cIGraph_callaway_traits_game, 6); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "establishment_game", cIGraph_establishment_game, 6); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "preference_game", cIGraph_preference_game, 6); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "asymmetric_preference_game", cIGraph_asymmetric_preference_game, 5); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "recent_degree_game", cIGraph_recent_degree_game, 7); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "barabasi_aging_game", cIGraph_barabasi_aging_game, 11); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "recent_degree_aging_game", cIGraph_recent_degree_aging_game, 9); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "cited_type_game", cIGraph_cited_type_game, 5); /* in cIGraph_generators_random.c */
  rb_define_singleton_method(cIGraph_genrandom, "citing_cited_type_game", cIGraph_citing_cited_type_game, 5); /* in cIGraph_generators_random.c */

  rb_define_method(cIGraph, "[]",            cIGraph_get_edge_attr, 2); /* in cIGraph_attribute_handler.c */
  rb_define_method(cIGraph, "[]=",           cIGraph_set_edge_attr, 3); /* in cIGraph_attribute_handler.c */
  rb_define_alias (cIGraph, "get_edge_attr", "[]");
  rb_define_alias (cIGraph, "set_edge_attr", "[]=");

  rb_define_method(cIGraph, "attributes", cIGraph_graph_attributes, 0); /* in cIGraph_attribute_handler.c */

  rb_define_method(cIGraph, "each_vertex",   cIGraph_each_vertex,  0); /* in cIGraph_iterators.c */
  rb_define_method(cIGraph, "each_edge",     cIGraph_each_edge,    1); /* in cIGraph_iterators.c */
  rb_define_method(cIGraph, "each_edge_eid", cIGraph_each_edge_eid,1); /* in cIGraph_iterators.c */ 
  rb_define_alias (cIGraph, "each", "each_vertex");

  rb_define_method(cIGraph, "vertices",             cIGraph_all_v,    0); /* in cIGraph_selectors.c */
  rb_define_method(cIGraph, "adjacent_vertices",    cIGraph_adj_v,    2); /* in cIGraph_selectors.c */
  rb_define_method(cIGraph, "nonadjacent_vertices", cIGraph_nonadj_v, 2); /* in cIGraph_selectors.c */
  rb_define_alias (cIGraph, "all_vertices", "vertices");

  rb_define_method(cIGraph, "edges",                cIGraph_all_e,    1); /* in cIGraph_selectors.c */
  rb_define_method(cIGraph, "adjacent_edges",       cIGraph_adj_e,    2); /* in cIGraph_selectors.c */
  rb_define_alias (cIGraph, "all_edges", "edges");

  rb_define_method(cIGraph, "vcount",       cIGraph_vcount,      0); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "ecount",       cIGraph_ecount,      0); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "edge",         cIGraph_edge,        1); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "get_eid",      cIGraph_get_eid,     2); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "neighbours",   cIGraph_neighbors,   2); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "adjacent",     cIGraph_adjacent,    2); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "degree",       cIGraph_degree,      3); /* in cIGraph_basic_query.c */
  rb_define_method(cIGraph, "is_directed?", cIGraph_is_directed, 0); /* in cIGraph_basic_query.c */ 
  rb_define_alias (cIGraph, "is_directed",  "is_directed?");
  rb_define_alias (cIGraph, "neighbors",    "neighbours");

  rb_define_method(cIGraph, "add_edges",     cIGraph_add_edges,    -1); /* in cIGraph_add_delete.c */
  rb_define_method(cIGraph, "add_vertices",  cIGraph_add_vertices,  1); /* in cIGraph_add_delete.c */
  rb_define_method(cIGraph, "add_edge",      cIGraph_add_edge,     -1); /* in cIGraph_add_delete.c */
  rb_define_method(cIGraph, "add_vertex",    cIGraph_add_vertex,    1); /* in cIGraph_add_delete.c */
  rb_define_method(cIGraph, "delete_edge",   cIGraph_delete_edge,   2); /* in cIGraph_add_delete.c */
  rb_define_method(cIGraph, "delete_vertex", cIGraph_delete_vertex, 1); /* in cIGraph_add_delete.c */

  rb_define_method(cIGraph, "are_connected",  cIGraph_are_connected,2); /* in cIGraph_basic_properties.c */  
  rb_define_alias (cIGraph, "are_connected?", "are_connected");

  rb_define_method(cIGraph, "to_directed",   cIGraph_to_directed,   1); /* in cIGraph_direction.c */
  rb_define_method(cIGraph, "to_undirected", cIGraph_to_undirected, 1); /* in cIGraph_direction.c */  

  /* These methods randomise a graph by rewiring the edges. */
  cIGraph_randomise = rb_define_module_under(cIGraph, "Randomise");
  rb_include_module(cIGraph, cIGraph_randomise);       

  rb_define_method(cIGraph_randomise, "rewire_edges", cIGraph_rewire_edges, 1); /* in cIGraph_randomisation.c */
  rb_define_method(cIGraph_randomise, "rewire", cIGraph_rewire, 1); /* in cIGraph_randomisation.c */

  /* Functions for calculating the shortest path through a graph */
  cIGraph_shortestpaths = rb_define_module_under(cIGraph, "ShortestPaths");
  rb_include_module(cIGraph, cIGraph_shortestpaths);     

  rb_define_method(cIGraph_shortestpaths, "shortest_paths",         cIGraph_shortest_paths,         2); /* in cIGraph_shortest_paths.c */
  rb_define_method(cIGraph_shortestpaths, "get_shortest_paths",     cIGraph_get_shortest_paths,     3); /* in cIGraph_shortest_paths.c */
  rb_define_method(cIGraph_shortestpaths, "get_all_shortest_paths", cIGraph_get_all_shortest_paths, 3); /* in cIGraph_shortest_paths.c */  
  rb_define_method(cIGraph_shortestpaths, "average_path_length",    cIGraph_average_path_length,    2); /* in cIGraph_shortest_paths.c */  
  rb_define_method(cIGraph_shortestpaths, "diameter",               cIGraph_diameter,               2); /* in cIGraph_shortest_paths.c */
  rb_define_method(cIGraph_shortestpaths, "girth",                  cIGraph_girth,                  0); /* in cIGraph_shortest_paths.c */

  rb_define_method(cIGraph_shortestpaths, "dijkstra_shortest_paths", cIGraph_dijkstra_shortest_paths, 3); /* in cIGraph_dijkstra.c */

  /* Functions for querying the neighborhood of vertices */
  cIGraph_neighborhoodm = rb_define_module_under(cIGraph, "Neighborhood");
  rb_include_module(cIGraph, cIGraph_neighborhoodm);     

  rb_define_method(cIGraph_neighborhoodm, "neighbourhood_size",   cIGraph_neighborhood_size,   3); /* in cIGraph_vertex_neighbourhood.c */
  rb_define_method(cIGraph_neighborhoodm, "neighbourhood",        cIGraph_neighborhood,        3); /* in cIGraph_vertex_neighbourhood.c */
  rb_define_method(cIGraph_neighborhoodm, "neighbourhood_graphs", cIGraph_neighborhood_graphs, 3); /* in cIGraph_vertex_neighbourhood.c */
  rb_define_alias (cIGraph_neighborhoodm, "neighborhood_size", "neighbourhood_size");
  rb_define_alias (cIGraph_neighborhoodm, "neighborhood", "neighbourhood");
  rb_define_alias (cIGraph_neighborhoodm, "neighborhood_graphs", "neighbourhood_graphs");
  rb_define_method(cIGraph_neighborhoodm, "connect_neighborhood", cIGraph_connect_neighborhood, 2); /* in cIGraph_generators_deterministic.c */

  /* Functions for splitting the graph into components */
  cIGraph_components = rb_define_module_under(cIGraph, "Components");
  rb_include_module(cIGraph, cIGraph_components);     

  rb_define_method(cIGraph_components, "subcomponent", cIGraph_subcomponent, 2); /* in cIGraph_components.c */
  rb_define_method(cIGraph_components, "subgraph",     cIGraph_subgraph,     1); /* in cIGraph_components.c */
  rb_define_method(cIGraph_components, "clusters",     cIGraph_clusters,     1); /* in cIGraph_components.c */
  rb_define_method(cIGraph_components, "decompose",    cIGraph_decompose,   -1); /* in cIGraph_components.c */

  /* Graph centrality functions */
  cIGraph_closenessm = rb_define_module_under(cIGraph, "Closeness");
  rb_include_module(cIGraph, cIGraph_closenessm);     

  rb_define_method(cIGraph_closenessm, "closeness",        cIGraph_closeness,        2); /* in cIGraph_centrality.c */
  rb_define_method(cIGraph_closenessm, "betweenness",      cIGraph_betweenness,      2); /* in cIGraph_centrality.c */
  rb_define_method(cIGraph_closenessm, "edge_betweenness", cIGraph_edge_betweenness, 1); /* in cIGraph_centrality.c */
  rb_define_method(cIGraph_closenessm, "pagerank",         cIGraph_pagerank,         5); /* in cIGraph_centrality.c */  
  rb_define_method(cIGraph_closenessm, "constraint",       cIGraph_constraint,      -1); /* in cIGraph_centrality.c */  
  rb_define_method(cIGraph_closenessm, "maxdegree",        cIGraph_maxdegree,        3); /* in cIGraph_centrality.c */    

  /* Minimum spanning tree functions */
  cIGraph_spanning = rb_define_module_under(cIGraph, "Spanning");
  rb_include_module(cIGraph, cIGraph_spanning);     

  rb_define_method(cIGraph_spanning, "minimum_spanning_tree_unweighted", cIGraph_minimum_spanning_tree_unweighted, 0); /* in cIGraph_spanning.c */
  rb_define_method(cIGraph_spanning, "minimum_spanning_tree_prim",       cIGraph_minimum_spanning_tree_prim,       1); /* in cIGraph_spanning.c */
  
  /* Graph transitivity functions */
  cIGraph_transitivitym = rb_define_module_under(cIGraph, "Transitivity");
  rb_include_module(cIGraph, cIGraph_transitivitym);     

  rb_define_method(cIGraph_transitivitym, "transitivity",          cIGraph_transitivity,          0); /* in cIGraph_transitivity.c */
  rb_define_method(cIGraph_transitivitym, "transitivity_local",    cIGraph_transitivity_local,    1); /* in cIGraph_transitivity.c */
  rb_define_method(cIGraph_transitivitym, "transitivity_avglocal", cIGraph_transitivity_avglocal, 0); /* in cIGraph_transitivity.c */

  /* Functions for the Laplacian matrix. */
  cIGraph_spectral = rb_define_module_under(cIGraph, "Spectral");
  rb_include_module(cIGraph, cIGraph_spectral);     

  rb_define_method(cIGraph_spectral, "laplacian", cIGraph_laplacian, 1); /* in cIGraph_spectral.c */

  /* Functions for finding the coreness of a graph */
  cIGraph_kcore = rb_define_module_under(cIGraph, "KCores");
  rb_include_module(cIGraph, cIGraph_kcore);     

  rb_define_method(cIGraph_kcore, "coreness", cIGraph_coreness, 1); /* in cIGraph_kcores.c */

  /* Other general graph operations */
  cIGraph_otherop = rb_define_module_under(cIGraph, "OtherOperations");
  rb_include_module(cIGraph, cIGraph_otherop);   

  rb_define_method(cIGraph_otherop, "density",       cIGraph_density,       1); /* in cIGraph_other_ops.c */
  rb_define_method(cIGraph_otherop, "simplify",      cIGraph_simplify,      2); /* in cIGraph_other_ops.c */
  rb_define_method(cIGraph_otherop, "reciprocity",   cIGraph_reciprocity,   1); /* in cIGraph_other_ops.c */
  rb_define_method(cIGraph_otherop, "bibcoupling",   cIGraph_bibcoupling,   1); /* in cIGraph_other_ops.c */
  rb_define_method(cIGraph_otherop, "cocitation",    cIGraph_cocitation,    1); /* in cIGraph_other_ops.c */
  rb_define_method(cIGraph_otherop, "get_adjacency", cIGraph_get_adjacency, 1); /* in cIGraph_other_ops.c */
  
  /* Clique finding functions */
  cIGraph_clique = rb_define_module_under(cIGraph, "Cliques");
  rb_include_module(cIGraph, cIGraph_clique);   

  rb_define_method(cIGraph_clique, "cliques",         cIGraph_cliques,         2); /* in cIGraph_cliques.c */
  rb_define_method(cIGraph_clique, "largest_cliques", cIGraph_largest_cliques, 0); /* in cIGraph_cliques.c */ 
  rb_define_method(cIGraph_clique, "maximal_cliques", cIGraph_maximal_cliques, 0); /* in cIGraph_cliques.c */ 
  rb_define_method(cIGraph_clique, "clique_number",   cIGraph_clique_number,   0); /* in cIGraph_cliques.c */ 

  /* Independent vertex set finding functions */
  cIGraph_indyver = rb_define_module_under(cIGraph, "IndependentVertexSets");
  rb_include_module(cIGraph, cIGraph_indyver);  

  rb_define_method(cIGraph_indyver, "independent_vertex_sets", cIGraph_independent_vertex_sets, 2); /* in cIGraph_independent_vertex_sets.c */
  rb_define_method(cIGraph_indyver, "largest_independent_vertex_sets", cIGraph_largest_independent_vertex_sets, 0); /* in cIGraph_independent_vertex_sets.c */
  rb_define_method(cIGraph_indyver, "maximal_independent_vertex_sets", cIGraph_maximal_independent_vertex_sets, 0); /* in cIGraph_independent_vertex_sets.c */
  rb_define_method(cIGraph_indyver, "independence_number", cIGraph_independence_number, 0); /* in cIGraph_independent_vertex_sets.c */

  /* Functions for isomorphism and isoclasses */
  cIGraph_isomor = rb_define_module_under(cIGraph, "Isomorphism");
  rb_include_module(cIGraph, cIGraph_isomor);  

  rb_define_method(cIGraph_isomor, "isomorphic",     cIGraph_isomorphic,     1); /* in cIGraph_isomorphism.c */
  rb_define_method(cIGraph_isomor, "isomorphic_vf2", cIGraph_isomorphic_vf2, 1); /* in cIGraph_isomorphism.c */
  rb_define_method(cIGraph_isomor, "isoclass", cIGraph_isoclass, 0); /* in cIGraph_isomorphism.c */
  rb_define_method(cIGraph_isomor, "isoclass_subgraph", cIGraph_isoclass_subgraph, 1); /* in cIGraph_isomorphism.c */
  rb_define_singleton_method(cIGraph_generate, "isoclass_create", cIGraph_isoclass_create, 3); /* in cIGraph_isomorphism.c */

  /* Motif finding functions */
  cIGraph_motifs = rb_define_module_under(cIGraph, "Motifs");
  rb_include_module(cIGraph, cIGraph_motifs);  

  rb_define_method(cIGraph_motifs, "motifs_randesu",          cIGraph_motifs_randesu,          2); /* in cIGraph_motif.c */ 
  rb_define_method(cIGraph_motifs, "motifs_randesu_no",       cIGraph_motifs_randesu_no,       2); /* in cIGraph_motif.c */ 
  rb_define_method(cIGraph_motifs, "motifs_randesu_estimate", cIGraph_motifs_randesu_estimate, 4); /* in cIGraph_motif.c */ 

  /* Graph sorting functions. */
  cIGraph_sorting = rb_define_module_under(cIGraph, "Sorting");
  rb_include_module(cIGraph, cIGraph_sorting);  

  rb_define_method(cIGraph_sorting, "topological_sorting", cIGraph_topological_sorting, 1); /* in cIGraph_topological_sort.c */

  /* Functions for reading graphs from files */
  cIGraph_fileread = rb_define_module_under(cIGraph, "FileRead");
  rb_include_module(cIGraph, cIGraph_fileread);  

  #ifdef __APPLE__
  rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml",  cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol",     cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_lgl",      cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_dimacs",   cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb",  cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_gml",      cIGraph_unavailable_method, -1);
  rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek",    cIGraph_unavailable_method, -1);
  #else
  rb_define_singleton_method(cIGraph_fileread, "read_graph_edgelist", cIGraph_read_graph_edgelist, 2); /* in cIGraph_file.c */
  rb_define_singleton_method(cIGraph_fileread, "read_graph_graphml",  cIGraph_read_graph_graphml, 2);  /* in cIGraph_file.c */  
  rb_define_singleton_method(cIGraph_fileread, "read_graph_ncol",     cIGraph_read_graph_ncol, 5);     /* in cIGraph_file.c */ 
  rb_define_singleton_method(cIGraph_fileread, "read_graph_lgl",      cIGraph_read_graph_lgl,  3);     /* in cIGraph_file.c */ 
  rb_define_singleton_method(cIGraph_fileread, "read_graph_dimacs",   cIGraph_read_graph_dimacs, 2);     /* in cIGraph_file.c */ 
  rb_define_singleton_method(cIGraph_fileread, "read_graph_graphdb",  cIGraph_read_graph_graphdb, 2);     /* in cIGraph_file.c */ 
  rb_define_singleton_method(cIGraph_fileread, "read_graph_gml",      cIGraph_read_graph_gml,  1);     /* in cIGraph_file.c */ 
  rb_define_singleton_method(cIGraph_fileread, "read_graph_pajek",    cIGraph_read_graph_pajek, 2);    /* in cIGraph_file.c */
  #endif

  /* Functions for writing graphs to files */
  cIGraph_filewrite = rb_define_module_under(cIGraph, "FileWrite");
  rb_include_module(cIGraph, cIGraph_filewrite);

  #ifdef __APPLE__
  rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_unavailable_method, -1);
  rb_define_method(cIGraph_filewrite, "write_graph_graphml",  cIGraph_unavailable_method, -1);  
  rb_define_method(cIGraph_filewrite, "write_graph_gml",      cIGraph_unavailable_method, -1);  
  rb_define_method(cIGraph_filewrite, "write_graph_ncol",     cIGraph_unavailable_method, -1);    
  rb_define_method(cIGraph_filewrite, "write_graph_lgl",      cIGraph_unavailable_method, -1); 
  rb_define_method(cIGraph_filewrite, "write_graph_dimacs",   cIGraph_unavailable_method, -1); 
  rb_define_method(cIGraph_filewrite, "write_graph_pajek",    cIGraph_unavailable_method, -1);
  #else
  rb_define_method(cIGraph_filewrite, "write_graph_edgelist", cIGraph_write_graph_edgelist, 1);  /* in cIGraph_file.c */
  rb_define_method(cIGraph_filewrite, "write_graph_graphml",  cIGraph_write_graph_graphml,   1); /* in cIGraph_file.c */  
  rb_define_method(cIGraph_filewrite, "write_graph_gml",      cIGraph_write_graph_gml,    1); /* in cIGraph_file.c */  
  rb_define_method(cIGraph_filewrite, "write_graph_ncol",     cIGraph_write_graph_ncol,   3);    /* in cIGraph_file.c */    
  rb_define_method(cIGraph_filewrite, "write_graph_lgl",      cIGraph_write_graph_lgl,   4);    /* in cIGraph_file.c */ 
  rb_define_method(cIGraph_filewrite, "write_graph_dimacs",   cIGraph_write_graph_dimacs, 4);    /* in cIGraph_file.c */ 
  rb_define_method(cIGraph_filewrite, "write_graph_pajek",    cIGraph_write_graph_pajek, 1);     /* in cIGraph_file.c */
  #endif

  /* Graph layout functions */
  cIGraph_layout = rb_define_module_under(cIGraph, "Layout");
  rb_include_module(cIGraph, cIGraph_layout);

  rb_define_method(cIGraph_layout, "layout_random",                    cIGraph_layout_random,                        0); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_circle",                    cIGraph_layout_circle,                        0); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_fruchterman_reingold",      cIGraph_layout_fruchterman_reingold,          6); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_kamada_kawai",              cIGraph_layout_kamada_kawai,                  5); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_reingold_tilford",          cIGraph_layout_reingold_tilford,              1); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_reingold_tilford_circular", cIGraph_layout_reingold_tilford_circular, 1); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_grid_fruchterman_reingold", cIGraph_layout_grid_fruchterman_reingold,     7); /* in cIGraph_layout.c */
  rb_define_method(cIGraph_layout, "layout_lgl",                       cIGraph_layout_lgl,                           7); /* in cIGraph_layout.c */

  rb_define_method(cIGraph_layout, "layout_random_3d",               cIGraph_layout_random_3d,               0); /* in cIGraph_layout3d.c */
  rb_define_method(cIGraph_layout, "layout_sphere",                  cIGraph_layout_sphere,                  0); /* in cIGraph_layout3d.c */
  rb_define_method(cIGraph_layout, "layout_fruchterman_reingold_3d", cIGraph_layout_fruchterman_reingold_3d, 5); /* in cIGraph_layout3d.c */
  rb_define_method(cIGraph_layout, "layout_kamada_kawai_3d",         cIGraph_layout_kamada_kawai_3d,         5); /* in cIGraph_layout3d.c */

  rb_define_singleton_method(cIGraph_layout, "layout_merge_dla", cIGraph_layout_merge_dla, 2); /* in cIGraph_layout.c */

  /* Minimum cuts related functions */
  cIGraph_mincuts = rb_define_module_under(cIGraph, "MinimumCuts");
  rb_include_module(cIGraph, cIGraph_mincuts);

  rb_define_method(cIGraph_mincuts, "maxflow_value",   cIGraph_maxflow_value,   3); /* in cIGraph_min_cuts.c */ 
  rb_define_method(cIGraph_mincuts, "st_mincut_value", cIGraph_st_mincut_value, 3); /* in cIGraph_min_cuts.c */  
  rb_define_method(cIGraph_mincuts, "mincut_value",    cIGraph_mincut_value,    1); /* in cIGraph_min_cuts.c */
  rb_define_method(cIGraph_mincuts, "mincut",          cIGraph_mincut,          1); /* in cIGraph_min_cuts.c */

  /* Vertex and edge connectivity functions */
  cIGraph_connectivity = rb_define_module_under(cIGraph, "Connectivity");
  rb_include_module(cIGraph, cIGraph_connectivity);

  rb_define_method(cIGraph_connectivity, "st_edge_connectivity",   cIGraph_st_edge_connectivity,   2); /* in cIGraph_connectivity.c */   
  rb_define_method(cIGraph_connectivity, "edge_connectivity",      cIGraph_edge_connectivity,      0); /* in cIGraph_connectivity.c */   
  rb_define_method(cIGraph_connectivity, "st_vertex_connectivity", cIGraph_st_vertex_connectivity, 3); /* in cIGraph_connectivity.c */   
  rb_define_method(cIGraph_connectivity, "vertex_connectivity",    cIGraph_vertex_connectivity,    0); /* in cIGraph_connectivity.c */   
  rb_define_method(cIGraph_connectivity, "edge_disjoint_paths",    cIGraph_edge_disjoint_paths,    2); /* in cIGraph_connectivity.c */ 
  rb_define_method(cIGraph_connectivity, "vertex_disjoint_paths",  cIGraph_vertex_disjoint_paths,  2); /* in cIGraph_connectivity.c */ 
  rb_define_method(cIGraph_connectivity, "adhesion",               cIGraph_adhesion,               0); /* in cIGraph_connectivity.c */    
  rb_define_method(cIGraph_connectivity, "cohesion",               cIGraph_cohesion,               0); /* in cIGraph_connectivity.c */   

  /* Community and modularity related functions */
  cIGraph_community = rb_define_module_under(cIGraph, "Community");
  rb_include_module(cIGraph, cIGraph_community);
  
  rb_define_method(cIGraph_community, "modularity",   cIGraph_modularity,   1); /* in cIGraph_community.c */
  rb_define_method(cIGraph_community, "community_to_membership", cIGraph_community_to_membership, 3);  /* in cIGraph_community.c */
  rb_define_method(cIGraph_community, "community_spinglass", cIGraph_community_spinglass, 8);  /* in cIGraph_community.c */
  rb_define_method(cIGraph_community, "community_spinglass_single", cIGraph_community_spinglass_single, 5);  /* in cIGraph_community.c */
  rb_define_method(cIGraph_community, "community_leading_eigenvector", cIGraph_community_leading_eigenvector, 1);  /* in cIGraph_community.c */      
  rb_define_method(cIGraph_community, "community_leading_eigenvector_naive", cIGraph_community_leading_eigenvector_naive, 1);  /* in cIGraph_community.c */
  rb_define_method(cIGraph_community, "community_leading_eigenvector_step", cIGraph_community_leading_eigenvector_step, 2);  /* in cIGraph_community.c */       rb_define_method(cIGraph_community, "community_walktrap", cIGraph_community_walktrap, 2);  /* in cIGraph_community.c */      
  rb_define_method(cIGraph_community, "community_edge_betweenness", cIGraph_community_edge_betweenness, 1);  /* in cIGraph_community.c */  
  rb_define_method(cIGraph_community, "community_eb_get_merges", cIGraph_community_eb_get_merges, 1);  /* in cIGraph_community.c */  
  rb_define_method(cIGraph_community, "community_fastgreedy", cIGraph_community_fastgreedy, 0);  /* in cIGraph_community.c */  

  rb_define_const(cIGraph, "VERSION", rb_str_new2("0.9.1"));

  rb_define_const(cIGraph, "EDGEORDER_ID",   INT2NUM(1));
  rb_define_const(cIGraph, "EDGEORDER_FROM", INT2NUM(2));
  rb_define_const(cIGraph, "EDGEORDER_TO",   INT2NUM(3));

  rb_define_const(cIGraph, "OUT",   INT2NUM(1));
  rb_define_const(cIGraph, "IN",    INT2NUM(2));
  rb_define_const(cIGraph, "ALL",   INT2NUM(3));
  rb_define_const(cIGraph, "TOTAL", INT2NUM(4));

  rb_define_const(cIGraph_components, "WEAK",   INT2NUM(1));
  rb_define_const(cIGraph_components, "STRONG", INT2NUM(2));  

  rb_define_const(cIGraph, "ARBITRARY", INT2NUM(0));
  rb_define_const(cIGraph, "MUTUAL",    INT2NUM(1));
  rb_define_const(cIGraph, "EACH",      INT2NUM(0));
  rb_define_const(cIGraph, "COLLAPSE",  INT2NUM(1));

  rb_define_const(cIGraph_otherop, "GET_ADJACENCY_UPPER", INT2NUM(0));
  rb_define_const(cIGraph_otherop, "GET_ADJACENCY_LOWER", INT2NUM(1));
  rb_define_const(cIGraph_otherop, "GET_ADJACENCY_BOTH",  INT2NUM(2));  

  rb_define_const(cIGraph, "ERDOS_RENYI_GNP", INT2NUM(0));
  rb_define_const(cIGraph, "ERDOS_RENYI_GNM", INT2NUM(1));

  rb_define_const(cIGraph_generate, "ADJ_DIRECTED",   INT2NUM(0));
  rb_define_const(cIGraph_generate, "ADJ_UNDIRECTED", INT2NUM(1));
  rb_define_const(cIGraph_generate, "ADJ_MAX",        INT2NUM(2));
  rb_define_const(cIGraph_generate, "ADJ_MIN",        INT2NUM(3));
  rb_define_const(cIGraph_generate, "ADJ_PLUS",       INT2NUM(4));
  rb_define_const(cIGraph_generate, "ADJ_UPPER",      INT2NUM(5));
  rb_define_const(cIGraph_generate, "ADJ_LOWER",      INT2NUM(6));

  rb_define_const(cIGraph_generate, "STAR_OUT",        INT2NUM(0));
  rb_define_const(cIGraph_generate, "STAR_IN",         INT2NUM(1));
  rb_define_const(cIGraph_generate, "STAR_UNDIRECTED", INT2NUM(2));

  rb_define_const(cIGraph_generate, "TREE_OUT",        INT2NUM(0));
  rb_define_const(cIGraph_generate, "TREE_IN",         INT2NUM(1));
  rb_define_const(cIGraph_generate, "TREE_UNDIRECTED", INT2NUM(2));

  rb_define_const(cIGraph_connectivity, "VCONN_NEI_ERROR",    INT2NUM(0));
  rb_define_const(cIGraph_connectivity, "VCONN_NEI_INFINITY", INT2NUM(1));
  rb_define_const(cIGraph_connectivity, "VCONN_NEI_IGNORE",   INT2NUM(2));  

  rb_define_const(cIGraph_community, "SPINCOMM_UPDATE_SIMPLE", INT2NUM(0));
  rb_define_const(cIGraph_community, "SPINCOMM_UPDATE_CONFIG", INT2NUM(1));  

  /* This class wraps the igraph matrix type. It can be created from and 
   * converted to an Array of Ruby Arrays.
   */
  cIGraphMatrix = rb_define_class("IGraphMatrix", rb_cObject);

  rb_define_alloc_func(cIGraphMatrix, cIGraph_matrix_alloc);
  rb_define_method(cIGraphMatrix, "initialize",      cIGraph_matrix_initialize, -1); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "initialize_copy", cIGraph_matrix_init_copy,   1); /* in cIGraph_matrix.c */
  //rb_define_singleton_method(cIGraphMatrix, "[]",    cIGraph_matrix_initialize, -1);
  rb_include_module(cIGraphMatrix, rb_mEnumerable);
  rb_define_method (cIGraphMatrix, "each", cIGraph_matrix_each,0); /* in cIGraph_matrix.c */
 
  rb_define_method(cIGraphMatrix, "[]",   cIGraph_matrix_get,  2); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "[]=",  cIGraph_matrix_set,  3); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "size", cIGraph_matrix_size, 0); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "nrow", cIGraph_matrix_nrow, 0); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "ncol", cIGraph_matrix_ncol, 0); /* in cIGraph_matrix.c */
  rb_define_method(cIGraphMatrix, "max",  cIGraph_matrix_max,  0); /* in cIGraph_matrix.c */

  rb_define_method(cIGraphMatrix, "*", cIGraph_matrix_scale, 1); /* in cIGraph_matrix.c */

  rb_define_method(cIGraphMatrix, "to_a", cIGraph_matrix_toa, 0); /* in cIGraph_matrix.c */

}
int main() {

    igraph_t g;
    igraph_vector_t v, v2;
    int i, ret;

    igraph_barabasi_game(&g, 10, 2, 0, 0, 1);
    if (igraph_ecount(&g) != 18) {
        return 1;
    }
    if (igraph_vcount(&g) != 10) {
        return 2;
    }
    if (!igraph_is_directed(&g)) {
        return 3;
    }

    igraph_vector_init(&v, 0);
    igraph_get_edgelist(&g, &v, 0);
    for (i=0; i<igraph_ecount(&g); i++) {
        if (VECTOR(v)[2*i] <= VECTOR(v)[2*i+1]) {
            return 4;
        }
    }
    igraph_destroy(&g);

    /* out degree sequence */
    igraph_vector_resize(&v, 10);
    VECTOR(v)[0]=0;
    VECTOR(v)[1]=1;
    VECTOR(v)[2]=3;
    VECTOR(v)[3]=3;
    VECTOR(v)[4]=4;
    VECTOR(v)[5]=5;
    VECTOR(v)[6]=6;
    VECTOR(v)[7]=7;
    VECTOR(v)[8]=8;
    VECTOR(v)[9]=9;

    igraph_barabasi_game(&g, 10, 0, &v, 0, 1);
    if (igraph_ecount(&g) != igraph_vector_sum(&v)) {
        return 5;
    }
    igraph_vector_init(&v2, 0);
    igraph_degree(&g, &v2, igraph_vss_all(), IGRAPH_OUT, 1);
    for (i=0; i<igraph_vcount(&g); i++) {
        if (VECTOR(v)[i] != VECTOR(v2)[i]) {
            return 6;
        }
    }
    igraph_vector_destroy(&v);
    igraph_vector_destroy(&v2);
    igraph_destroy(&g);

    /* outpref, we cannot really test this quantitatively,
       would need to set random seed */
    igraph_barabasi_game(&g, 10, 2, 0, 1, 1);
    igraph_vector_init(&v, 0);
    igraph_get_edgelist(&g, &v, 0);
    for (i=0; i<igraph_ecount(&g); i++) {
        if (VECTOR(v)[2*i] <= VECTOR(v)[2*i+1]) {
            return 7;
        }
    }
    if (!igraph_is_directed(&g)) {
        return 8;
    }
    igraph_vector_destroy(&v);
    igraph_destroy(&g);

    /* Error tests */
    igraph_set_error_handler(igraph_error_handler_ignore);
    ret=igraph_barabasi_game(&g, -10, 1, 0, 0, 0);
    if (ret != IGRAPH_EINVAL) {
        return 9;
    }
    ret=igraph_barabasi_game(&g, 10, -2, 0, 0, 0);
    if (ret != IGRAPH_EINVAL) {
        return 10;
    }
    igraph_vector_init(&v, 9);
    ret=igraph_barabasi_game(&g, 10, 0, &v, 0, 0);
    if (ret != IGRAPH_EINVAL) {
        return 11;
    }
    igraph_vector_destroy(&v);

    return 0;
}
Пример #16
0
//-------------------------------------------------------------------------------------------------
int main(int argc, char **argv) {
    
    igraph_set_error_handler(igraph_error_handler_printignore);
        igraph_i_set_attribute_table(&igraph_cattribute_table);
    
    
    
    drawingcontrol=1;
	runningcontrol=0;
    cleared=1;
    graphisloaded=0;
	newgraph=1;
    usesteady=0;
    ispii=0;
    haveout=0;
    isrelaxed=0;
    havecstop=0;
    isdissipating=0;
    
    
    
    //RANDOM NUMBER GENERATOR INITIALISE
    init_genrand(0); //srand(3);
    
    
    //preloaded graph:
    {
        latticedim=2;
        latticeside=5;
        istoro=1;
        islattice=1;
        isclustered=0;
        israndomER1=0;
        generatelattice(2,5,1,0,0,0,0);
        //inizializations
        igraph_matrix_init(&state, 0, 0);
        igraph_matrix_init(&density, 0, 0);
        igraph_matrix_init(&densityold,0,0);
        igraph_matrix_init(&statenew, 0, 0);
        igraph_matrix_init(&flux, 0, 0);
        igraph_matrix_init(&loss, 0, 0);
        beginner=(nodesnumber/2);
        InitialStateTAS(beginner,0,totrun);
        igraph_vector_init(&gain,nodesnumber);
        graphisloaded=1;
        newgraph=1;
        haveloadedstate=0;
        
        
        drnodes=1;
        drlinks=1;
        drfluxes=0;
    }
    
    
    
    
    havepath=0;
    sprintf(path,"No path");
  
	
    logDebug("\n DEFAULT ADJ MATRIX:\n");
    print_matrix_ur(&admatrix,stdout);
    printf("\n");
	printf("\n");
    rewrite=1;
    
    CreateMyWindow();
    
    
  //Fl::add_timeout(1.0,mainidle_cb);
  Fl::add_idle(mainidle_cb, 0);
  Fl::run();
    
    
    histdist.Clear();
    
    igraph_destroy(&graph);
    igraph_destroy(&sgraph);
    igraph_matrix_destroy(&admatrix);
    igraph_matrix_destroy(&layout);
    igraph_matrix_destroy(&density);
    igraph_matrix_destroy(&densityold);
    igraph_matrix_destroy(&state);
    igraph_matrix_destroy(&loadedstate);
    igraph_matrix_destroy(&statenew);
    igraph_matrix_destroy(&flux);
    igraph_vector_destroy(&gain);
    igraph_matrix_destroy(&loss);
    igraph_vector_destroy(&statstate);
    igraph_matrix_destroy(&estates);
    
    closeout();
    
  return 0;
}
Пример #17
0
int check_multi() {

  igraph_t g;
  igraph_vector_t vec;
  igraph_vector_t eids, eids2;
  int ret;
  long int i;

  igraph_real_t q1[] = { 0,1, 0,1 };
  igraph_real_t q2[] = { 0,1, 0,1, 0,1 };
  igraph_real_t q3[] = { 1,0, 3,4, 1,0, 0,1, 3,4, 0,1 };

  igraph_vector_init(&eids, 0);

  /*********************************/
  igraph_small(&g, /*n=*/ 10, /*directed=*/ 1, 
	       0,1, 0,1, 1,0, 1,2, 3,4, 3,4, 3,4, 3,5, 3,7, 
	       9,8,
	       -1);

  igraph_vector_view(&vec, q1, sizeof(q1) / sizeof(igraph_real_t));
  igraph_get_eids_multi(&g, &eids, &vec, 0, /*directed=*/ 1, /*error=*/ 1);
  igraph_vector_sort(&eids);
  print_vector(&eids, stdout);

  igraph_vector_view(&vec, q2, sizeof(q2) / sizeof(igraph_real_t));
  igraph_get_eids_multi(&g, &eids, &vec, 0, /*directed=*/ 0, /*error=*/ 1);
  igraph_vector_sort(&eids);
  print_vector(&eids, stdout);

  igraph_vector_view(&vec, q2, sizeof(q2) / sizeof(igraph_real_t));
  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_get_eids_multi(&g, &eids, &vec, 0, /*directed=*/ 1, /*error=*/1);
  if (ret != IGRAPH_EINVAL) { return 1; } 
  igraph_set_error_handler(igraph_error_handler_abort);

  igraph_destroy(&g);
  /*********************************/

  /*********************************/
  igraph_small(&g, /*n=*/10, /*directed=*/0, 
	       0,1, 1,0, 0,1, 3,4, 3,4, 5,4, 9,8, 
	       -1);
  
  igraph_vector_view(&vec, q1, sizeof(q1) / sizeof(igraph_real_t));
  igraph_get_eids_multi(&g, &eids, &vec, 0, /*directed=*/1, /*error=*/ 1);
  igraph_vector_sort(&eids);
  print_vector(&eids, stdout);

  igraph_vector_view(&vec, q3, sizeof(q3) / sizeof(igraph_real_t));
  igraph_set_error_handler(igraph_error_handler_ignore);
  ret=igraph_get_eids_multi(&g, &eids, &vec, 0, /*directed=*/0, /*error=*/ 1);
  if (ret != IGRAPH_EINVAL) { return 2; }
  igraph_set_error_handler(igraph_error_handler_abort);
  
  igraph_destroy(&g);

  /*********************************/

  igraph_vector_destroy(&eids);

  /*********************************/
  /* Speed tests */

#define NODES 10000
  igraph_barabasi_game(&g, /*n=*/ NODES, /*power=*/ 1.0, /*m=*/ 3, 
		       /*outseq=*/ 0, /*outpref=*/ 0, /*A=*/ 1,
		       /*directed=*/ 1, IGRAPH_BARABASI_BAG,
		       /*start_from=*/ 0);
  igraph_simplify(&g, /*multiple=*/ 1, /*loops=*/ 0, /*edge_comb=*/ 0);

  igraph_vector_init(&eids, NODES/2);
  igraph_random_sample(&eids, 0, igraph_ecount(&g)-1, NODES/2);
  igraph_vector_init(&vec, NODES);
  for (i=0; i<NODES/2; i++) {
    VECTOR(vec)[2*i]   = IGRAPH_FROM(&g, VECTOR(eids)[i]);
    VECTOR(vec)[2*i+1] = IGRAPH_TO(&g, VECTOR(eids)[i]);
  }
  igraph_vector_init(&eids2, 0);
  igraph_get_eids_multi(&g, &eids2, &vec, 0, /*directed=*/ 1, /*error=*/ 1);
  if (!igraph_vector_all_e(&eids, &eids2)) {
    return 3;
  }

  /**/

  for (i=0; i<NODES/2; i++) {
    VECTOR(vec)[2*i]   = IGRAPH_TO(&g, VECTOR(eids)[i]);
    VECTOR(vec)[2*i+1] = IGRAPH_FROM(&g, VECTOR(eids)[i]);
  }
  igraph_get_eids_multi(&g, &eids2, &vec, 0, /*directed=*/ 0, /*error=*/ 1);
  if (!igraph_vector_all_e(&eids, &eids2)) {
    return 4;
  }

  igraph_vector_destroy(&eids);
  igraph_vector_destroy(&eids2);
  igraph_vector_destroy(&vec);
  igraph_destroy(&g);
		  
  /*********************************/

  return 0;
}