示例#1
0
int main(int argc, char** argv)
{
  int num_vertices, edges_per_vertex, iterations;
  double decrease_factor;
  if (argc < 5)
    goto err_usage;
  if (sscanf(argv[1], "%i", &num_vertices) != 1)
    goto err_usage;
  if (sscanf(argv[2], "%i", &edges_per_vertex) != 1)
    goto err_usage;
  if (sscanf(argv[3], "%i", &iterations) != 1)
    goto err_usage;
  if (sscanf(argv[4], "%lf", &decrease_factor) != 1)
    goto err_usage;

  if (edges_per_vertex % 2) {
    fprintf(stderr, "edges_per_vertex should be even\n");
    return EXIT_FAILURE;
  }

  if (decrease_factor < 1)
  {
    fprintf(stderr, "decrease_factor should be greater than 1");
    return EXIT_FAILURE;
  }

  struct graph_t *g;
  for (double p = 1.0; p > 0.001; p/=decrease_factor)
  {
    fprintf(stdout, "Using probability %f\n", p);
    g = build_regular_graph(num_vertices, edges_per_vertex);
    double l = 0, l0, c = 0, c0;
    c0 = get_global_clustering_coefficient(g);
    l0 = get_average_path_length(g);
    for (int i = 0; i < iterations; i++)
    {
      fprintf(stdout, "  Iteration %d\n", i+1);
      randomise_graph(g, p);
      l += get_average_path_length(g);
      c += get_global_clustering_coefficient(g);
      delete_graph(g);
      g = build_regular_graph(num_vertices, edges_per_vertex);
    }
    fprintf(stderr, "%f %f %f\n", p, (l / iterations) / l0, (c / iterations) / c0);
    delete_graph(g);
  }
  return 0;

err_usage:
  print_usage(stderr);
  return EXIT_FAILURE;
}
示例#2
0
void test_distance_layout(){
	int l = 5, k = 4;
	int radius = 5, width=1;
	graph_t *g = new_ravasz_barabasi(l, k);
	int n = graph_num_vertices(g);
	
	int *distance = malloc(n * sizeof(*distance));
	graph_geodesic_vertex(g, 0, distance);
	
	coord_t *p = malloc(n * sizeof(*p));
	graph_layout_shell(g, width+radius, distance, false, false, p);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	graph_print_svg_one_style("test/test_distance_layout.svg", 0, 0, g, p, 
	                          point_style, edge_style);
	
	free(p);
	delete_graph(g);
}
示例#3
0
void test_core_layout(){
	int radius = 5, width=1;
	graph_t *g = load_graph("datasets/email/edges.txt", false);
	int n = graph_num_vertices(g);
	
	coord_t *p = malloc(n * sizeof(*p));
	graph_layout_core_shell(g, width+radius, true, p);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	graph_print_svg_one_style("test/test_core_layout.svg", 0, 0, g, p, 
	                          point_style, edge_style);
	
	free(p);
	delete_graph(g);
}
示例#4
0
void test_degree_layout(){
	int n = 64, k = 4;
	int radius = 5, width=1;
	graph_t *g = new_barabasi_albert(n, k);
	
	coord_t *p = malloc(n * sizeof(*p));
	graph_layout_degree_shell(g, width+radius, true, p);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	graph_print_svg_one_style("test/test_degree_layout.svg", 0, 0, g, p, 
	                          point_style, edge_style);
	
	free(p);
	delete_graph(g);
}
示例#5
0
void test_circle_layout(){
	int n = 64, k = 4;
	int radius = 5, width=1;
	graph_t *g = new_watts_strogatz(n, k, 0.25);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	coord_t *p = malloc(n * sizeof(*p));
	double size = graph_layout_circle(width+radius, p, n);
	
	int m = graph_num_edges(g);
	int *es = malloc(m * sizeof(*es));
	path_style_t edge_style[2];
	
	graph_layout_circle_edges(g, size, width, black, es, &edge_style[0]);
	
	int *ps = malloc(n * sizeof(*ps));
	memset(ps, 0, n*sizeof(*ps));
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	graph_print_svg_some_styles("test/test_circle_layout.svg", 0, 0, g, p, 
	                            ps, &point_style, 1, 
	                            es, edge_style, 2);
	free(ps); free(es);
	free(p);
	delete_graph(g);
}
示例#6
0
void test_random_layout(){
	int n = 64, k = 4;
	int radius = 5, width=1;
	graph_t *g = new_erdos_renyi(n, (double)k);
	
	coord_t *p = malloc(n * sizeof(*p));
	graph_layout_random_wout_overlap(width+radius, 0.5, p, n);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	graph_print_svg_one_style("test/test_random_layout.svg", 0, 0, g, p, 
	                          point_style, edge_style);
	
	free(p);
	delete_graph(g);
}
示例#7
0
void test_many_styles(){
	int i, j, n = 8, m = 12;
	graph_t *g = make_a_graph(true);
	
	int width = 1, radius = 6;
	coord_t *p = make_a_position(width, radius);
	
	path_style_t *edge_style = malloc(m * sizeof(*edge_style));
	
	int e=0, adj[8]; 
	for (i=0; i < n; i++){
		int ki = graph_adjacents(g, i, adj);
		for (j=0; j < ki; j++){
			int v = adj[j];
			edge_style[e].from.x = p[i].x;
			edge_style[e].from.y = p[i].y;
			edge_style[e].to.x   = p[v].x;
			edge_style[e].to.y   = p[v].y;
			edge_style[e].type = GRAPH_STRAIGHT;
			
			edge_style[e].width = ki;
			
			edge_style[e].color[0] = rand() / (RAND_MAX/256);
			edge_style[e].color[1] = rand() / (RAND_MAX/256);
			edge_style[e].color[2] = rand() / (RAND_MAX/256);
			edge_style[e].color[3] = 128 + rand() / (RAND_MAX/128);
			
			e++;
		}
	}
	assert(e == m);
	
	circle_style_t *point_style = malloc(n * sizeof(*edge_style));
	
	for (i=0; i < n; i++){
		point_style[i].radius = 1+graph_num_adjacents(g, i);
		point_style[i].width = 1;
		
		int r = rand() / (RAND_MAX/256);
		point_style[i].fill[0] = r;
		point_style[i].fill[1] = r;
		point_style[i].fill[2] = r;
		point_style[i].fill[3] = 255;
		
		point_style[i].stroke[0] = 0;
		point_style[i].stroke[1] = 0;
		point_style[i].stroke[2] = 0;
		point_style[i].stroke[3] = 255;
	}
	
	graph_print_svg("test/test_many_style.svg", 0, 0, g, p, point_style, edge_style);
	
	delete_graph(g);
	free(p);
	free(edge_style);
	free(point_style);
}
void test_undirectedgraph()
{
    UndirectedGraph *graph = new_UndirectedGraph(10); 
    add_edges(graph); 

    printf("Printing vertices adjacent to 9...\n"); 
    print_adjacent_vertices(graph, 9); 
    delete_graph(graph); 
}
示例#9
0
文件: glpapi18.c 项目: cran/farmR
void glp_erase_graph(glp_graph *G, int v_size, int a_size)
{     if (!(0 <= v_size && v_size <= 256))
         xerror("glp_erase_graph: v_size = %d; invalid size of vertex d"
            "ata\n", v_size);
      if (!(0 <= a_size && a_size <= 256))
         xerror("glp_erase_graph: a_size = %d; invalid size of arc data"
            "\n", a_size);
      delete_graph(G);
      create_graph(G, v_size, a_size);
      return;
}
示例#10
0
int do_metis_kway_partition(network_t *network, options_t *opt, idx_t *part, idx_t mode) {
    int ret = ORCC_OK;
    idx_t ncon = 1;
    idx_t metis_opt[METIS_NOPTIONS];
    idx_t objval;
    adjacency_list *graph, *metis_graph;
    assert(network != NULL);
    assert(opt != NULL);
    assert(part != NULL);

    print_orcc_trace(ORCC_VL_VERBOSE_1, "Applying METIS Kway partition for mapping");

    METIS_SetDefaultOptions(metis_opt);
    metis_opt[METIS_OPTION_OBJTYPE] = mode;
    metis_opt[METIS_OPTION_CONTIG] = 0;  /* 0 or 1 */

    graph = set_graph_from_network(network);
    metis_graph = fix_graph_for_metis(graph);

    ret = METIS_PartGraphKway(&metis_graph->nb_vertices, /* idx_t *nvtxs */
                              &ncon, /*idx_t *ncon*/
                              metis_graph->xadj, /*idx_t *xadj*/
                              metis_graph->adjncy, /*idx_t *adjncy*/
                              metis_graph->vwgt, /*idx_t *vwgt*/
                              NULL, /*idx_t *vsize*/
                              metis_graph->adjwgt, /*idx_t *adjwgt*/
                              &opt->nb_processors, /*idx_t *nparts*/
                              NULL, /*real t *tpwgts*/
                              NULL, /*real t ubvec*/
                              metis_opt, /*idx_t *options*/
                              &objval, /*idx_t *objval*/
                              part); /*idx_t *part*/
    check_metis_error(ret);

    print_orcc_trace(ORCC_VL_VERBOSE_2, "METIS Edgecut : %d", objval);

    delete_graph(graph);
    delete_graph(metis_graph);
    return ret;
}
示例#11
0
void test_some_styles(){
	graph_t *g = make_a_graph(true);
	
	int width = 1, radius = 6;
	coord_t *p = make_a_position(width, radius);
	
	int num_edge_style = 3;
	int es[] = {0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 2};
	path_style_t edge_style[3];
	
	color_t solid_red   = {255, 0, 0, 255};
	color_t solid_green = {0, 255, 0, 255};
	color_t solid_blue  = {0, 0, 255, 255};
	color_t black       = {0, 0, 0,   255};
	
	// Edges within community 0 in blue
	edge_style[0].type = GRAPH_STRAIGHT;
	edge_style[0].width = 1;
	color_copy(edge_style[0].color, solid_blue);
	
	// Edges between communities 0 and 1 in red
	edge_style[1].type = GRAPH_STRAIGHT;
	edge_style[1].width = 1;
	color_copy(edge_style[1].color, solid_red);
	
	// Edges within community 1 in green
	edge_style[2].type = GRAPH_STRAIGHT;
	edge_style[2].width = 1;
	color_copy(edge_style[2].color, solid_green);
	
	int num_point_style = 2;
	int ps[] = {0, 0, 0, 1, 1, 1, 1, 1};
	circle_style_t point_style[2];
	
	// Vertices in community 0 are blue
	point_style[0].radius = radius;
	point_style[0].width = width;
	color_copy(point_style[0].fill, solid_blue);
	color_copy(point_style[0].stroke, black);
	
	// Vertices in community 1 are green
	point_style[1].radius = radius;
	point_style[1].width = width;
	color_copy(point_style[1].fill, solid_green);
	color_copy(point_style[1].stroke, black);
	
	graph_print_svg_some_styles("test/test_some_styles.svg", 0, 0, g, p, 
	                            ps, point_style, num_point_style,
	                            es, edge_style, num_edge_style);
	delete_graph(g);
	free(p);
}
示例#12
0
void test_animation(){
	int n = 64, k = 4;
	int radius = 5, width=1;
	int seed = 42;
	unsigned int state = seed;
	graph_t *g = new_barabasi_albert_r(n, k, &state);
	
	coord_t *p = malloc(n * sizeof(*p));
	double size = graph_layout_degree_shell(g, width+radius, true, p);
	delete_graph(g);
	
	color_t solid_red = {255, 0, 0, 255};
	color_t black     = {0,   0, 0, 255};
	
	circle_style_t point_style;
	point_style.radius = radius;
	point_style.width = width;
	color_copy(point_style.fill, solid_red);
	color_copy(point_style.stroke, black);
	
	path_style_t edge_style;
	edge_style.width = width;
	color_copy(edge_style.color, black);
	
	int i;
	for (i=k+1; i <= n; i++){
		state = seed;
		g = new_barabasi_albert_r(i, k, &state);
		
		char filename[256];
		sprintf(filename, "test/anim_ba/frame%03d.svg", i-k-1);
		graph_print_svg_one_style(filename, (int)size, (int)size, g, p, 
		                          point_style, edge_style);
		
		delete_graph(g);
	}
	
	free(p);
}
示例#13
0
int main(int argc, char** argv)
{
  int num_vertices, edges_per_vertex;
  float prob_of_swap;

  if (argc < 4)
    goto err_usage;
  if (sscanf(argv[1], "%i", &num_vertices) != 1)
    goto err_usage;
  if (sscanf(argv[2], "%i", &edges_per_vertex) != 1)
    goto err_usage;
  if (sscanf(argv[3], "%f", &prob_of_swap) != 1)
    goto err_usage;

  if (edges_per_vertex % 2) {
    fprintf(stderr, "edges_per_vertex should be even\n");
    return EXIT_FAILURE;
  }

  fprintf(stderr,
      "Configuration:\n"
      "  Vertices:         %d\n"
      "  Edges per vertex: %d\n"
      "  Swap probability: %f\n\n",
      num_vertices, edges_per_vertex, prob_of_swap);

  struct graph_t *g = build_regular_graph(num_vertices, edges_per_vertex);
  randomise_graph(g, prob_of_swap);
  struct histogram_t *h = get_degree_distribution(g);

  for (int i = 0; i < h->bins; i++)
    fprintf(stdout, "%d %d\n", i, h->data[i]);

  print_histogram(stderr, h);
  delete_histogram(h);
  delete_graph(g);
  return 0;

err_usage:
  print_usage(stderr);
  return EXIT_FAILURE;
}
示例#14
0
void test_one_style(){
	graph_t *g = make_a_graph(true);
	
	int width = 1, radius = 5;
	coord_t *p = make_a_position(width, radius);
	
	path_style_t edge_style = {
		{0.0f, 0.0f}, {0.0f, 0.0f}, {0.0f, 0.0f},
		GRAPH_STRAIGHT,
		1, {0, 0, 0, 255}
	};
	circle_style_t point_style = {
		5, 1, 
		{255, 0, 0, 255},
		{0  , 0, 0, 255}
	};
	
	graph_print_svg_one_style("test/test_one_style.svg", 0, 0, g, p, point_style, edge_style);
	
	delete_graph(g);
}
static int
bench(FibHeap<size_t, size_t> *pq,
      const struct settings &settings)
{

    int ret = 0;
    size_t number_of_nodes;
    vertex_t *graph = read_graph(settings.graph_file,
                                 settings.max_generated_random_weight != 0,
                                 settings.max_generated_random_weight,
                                 number_of_nodes,
                                 settings.seed);


    /* Our initial node is graph[0]. */

    graph[0].n = pq->push((size_t)0, (size_t)0);

    graph[0].distance = 0;


    struct timespec start, end;
    clock_gettime(CLOCK_MONOTONIC, &start);

    start_sssp(pq, graph);

    clock_gettime(CLOCK_MONOTONIC, &end);
    /* End benchmark. */

    //verify_graph(graph, number_of_nodes);
    print_graph(graph,
                number_of_nodes,
                settings.output_file);

    const double elapsed = timediff_in_s(start, end);
    fprintf(stdout, "%f", elapsed);

    delete_graph(graph, number_of_nodes);
    return ret;
}
示例#16
0
int main(){
int choice,i;
int v1,v2;
	do{
		printf("Choose the option:\n");
		printf("1.Create new empty graph\n");
		printf("2.Add edge\n");
		printf("3.Delete edge\n");
		printf("4.bfs\n");
		printf("5.dfs\n");
		printf("6.Increment graph-size\n");
		printf("7.Print list");	
		printf("Enter any other integer to exit\n");
		scanf("%d",&choice);
		printf("You entered:%d\n",choice);
		switch(choice){
			case 1:
			if(graph)
			 choice=delete_graph();
			if(choice){
				printf("Enter the initial number of nodes you want in the graph\n");
				scanf("%d",&node_count);
				graph=(node**)malloc(node_count*sizeof(node*));
				if(graph){
					printf("Empty graph of size:%d created\n",node_count);
					for(i=0;i<node_count;i++){
					graph[i]=(node*)malloc(sizeof(node));
					graph[i]->data=i;
					graph[i]->next=NULL;
					}
					break;
				}
				printf("Error allocating memory for empty graph of size:%d,try again...\n",node_count);
				break;	
			}
			case 2:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				printf("Enter the two vertices to add edge between them\n");
				scanf("%d%d",&v1,&v2);
				add_edge(v1,v2);
				break;
			case 3:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				printf("Enter the two vertices to delete edge between them\n");
				scanf("%d%d",&v1,&v2);
				delete_edge(v1,v2);
				break;
			case 4:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				printf("Enter the vertex to start bfs from\n");
				scanf("%d",&v1);
				bfs(v1);
				break;
			case 5:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				printf("Enter the vertex to start dfs from\n");
				scanf("%d",&v1);
				dfs(v1);
				break;
			case 6:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				printf("Enter the new size of the graph you want\n");
				scanf("%d",&choice);
				increment_graphsize(choice);
				break;
			case 7:
				if(!graph){
					printf("First Create a new empty graph\n");
					break;
				}
				print_list();
				break;
			default:
				printf("Exiting\n");
				return 0;
		}
	}while(true);
return 0;
}
示例#17
0
文件: glpapi18.c 项目: cran/farmR
void glp_delete_graph(glp_graph *G)
{     delete_graph(G);
      xfree(G);
      return;
}