//  Prints the whole list
void print_list(node *n) {
    node *current = n;

    while (current != NULL) {
        graph_print(current->bank_account);
        current = current->next;
    }
}
Exemple #2
0
int main(void) {
   
    int d = 0;
    int i = 0;
    int x = 0;
    graph my_graph = NULL;


    if (1 == scanf("%d", &d)) {
        my_graph = graph_new(d);
    }
    while (2 == scanf("%d%d", &i, &x)) {
        graph_add_edge(my_graph, i, x);
    }

    /*
    graph my_graph = graph_new(8);

    graph_bi_add_edge(my_graph, 0, 1);
    graph_bi_add_edge(my_graph, 0, 4);
    
    graph_bi_add_edge(my_graph, 1, 0);
    graph_bi_add_edge(my_graph, 1, 5);
    
    graph_bi_add_edge(my_graph, 2, 3);
    graph_bi_add_edge(my_graph, 2, 5);
    graph_bi_add_edge(my_graph, 2, 6);
    
    graph_bi_add_edge(my_graph, 3, 2);
    graph_bi_add_edge(my_graph, 3, 6);
    graph_bi_add_edge(my_graph, 3, 7);
    
    graph_bi_add_edge(my_graph, 4, 0);

    graph_bi_add_edge(my_graph, 5, 1);
    graph_bi_add_edge(my_graph, 5, 2);
    graph_bi_add_edge(my_graph, 5, 6);

    graph_bi_add_edge(my_graph, 6, 2);
    graph_bi_add_edge(my_graph, 6, 3);
    graph_bi_add_edge(my_graph, 6, 5);
    graph_bi_add_edge(my_graph, 6, 7);

    graph_bi_add_edge(my_graph, 7, 3);
    graph_bi_add_edge(my_graph, 7, 6);
    */
    
    graph_dfs(my_graph);
    graph_print(my_graph);
    graph_free(my_graph);
    return EXIT_SUCCESS;
}
Exemple #3
0
int main(int argc, char** argv) {
  graph_p g = graph_init(8);
  edge_t e;
  e.v = 1;
  e.w = 3;

  printf("inserting edge\n");
  graph_insert_edge(g, e);
  graph_print(g);

  /*
  edge_t edges[8 * 7 / 2];
  printf("edges %d\n", graph_edges(g, edges));
  */

  printf("removing edge\n");
  graph_remove_edge(g, e);
  graph_print(g);

  graph_destroy(g);
  return EXIT_SUCCESS;
}
Exemple #4
0
int main(void)
{
	struct graph g;
	int k;

	graph_creat(&g, "graph.txt", 1); // create DAG
	graph_print(&g);

	topsort(&g);
	printf("topological sort: ");
	for (k = 0; k < g.nnode; k++)
		printf("%d-> ", sort[k]);
	printf("\n");

	return 0;
}
// main function: display the right messages. Please refer to MP5 requirement
 int main(int argc, const char **argv)
{
    int gc;
    int list[NUM_V];
    int origin;
    int destination;
    int sl;
    int i;
    
    if(argv[1]==NULL)
    {
    	printf("enter the input file name\n");
    	return -1;
    }
    
    gc = graph_reading(argv[1]); 
    
    if(gc==1)
    {
    	printf("input file cannot be opened\n");
    	return -1;
    }
    else
    	printf("The adjacency matrix has been loaded\n");
    
    graph_print();
    
    printf("Enter the origin vertex:\n");
    scanf("%d",&origin);
    printf("Enter the destination vertex:\n");
    scanf("%d",&destination);
    
    for(i=0;i<NUM_V;i++)  /*list[NUM_V] has recored of traversed vertices*/
    	list[NUM_V]=0;
    	
    sl = pathlength(origin,destination,list); /*shortest path length*/
    
    if(sl==0)
    	printf("%d and %d are seperated forever!",origin,destination);
    else
    	printf("%d needs %d step(s) to get %d",origin,sl,destination); 
     	
    
    return 0;
}
Exemple #6
0
int main(int argc, char *argv[]) {
    int v1;
    int v2;
    graph g;
    char option; 
    int size = 0;
    graph_t type = DIRECTED;
    const char *optstring = "s:";

    while((option = getopt(argc, argv, optstring)) != EOF) {
        switch(option) {
            case 's':
                size = atoi(optarg);
                break;
            default:
                printf("input the number of vertices\n");
                return EXIT_FAILURE;
        }
    }

    g = graph_new(size);
    while(2==scanf("%d%d", &v1, &v2)) {
        g = graph_add_edge(g, v1, v2, type);
    }
    /**
    g = graph_add_edge(g, 0, 1, type);
    g = graph_add_edge(g, 0, 4, type);
    g = graph_add_edge(g, 5, 1, type);
    g = graph_add_edge(g, 5, 2, type);
    g = graph_add_edge(g, 5, 6, type);
    g = graph_add_edge(g, 6, 2, type);
    g = graph_add_edge(g, 6, 3, type);
    g = graph_add_edge(g, 6, 7, type);
    g = graph_add_edge(g, 3, 2, type);
    g = graph_add_edge(g, 3, 7, type);
    */
    graph_print(g);
    graph_dfs(g);
    g = graph_free(g);
    return EXIT_SUCCESS;
}
Exemple #7
0
int main() {
    struct graph *g = graph_create();
    if (g == NULL) {
        printf("malloc error\n");
        return 1;
    }
    int values[] = {0, 1, 2, 3, 4, 5, 6, 7};
    int len = sizeof(values)/sizeof(values[0]);
    struct vertex *vertices[len];
    for (int i = 0; i < len; ++i) {
        vertices[i] = graph_vertex_add(g, values[i]);
        assert(vertices[i]);
        printf("Added vertex %p\n", vertices[i]);
    }
    graph_edge_add(g, vertices[0], vertices[7], 7);
    graph_edge_add(g, vertices[0], vertices[5], 5);
    graph_edge_add(g, vertices[0], vertices[3], 3);
    graph_edge_add(g, vertices[2], vertices[6], 8);
    graph_edge_add(g, vertices[5], vertices[4], 9);
    graph_edge_remove(g, vertices[0], vertices[7]);
    graph_edge_remove(g, vertices[0], vertices[5]);
    graph_edge_remove(g, vertices[2], vertices[6]);
    graph_edge_remove(g, vertices[5], vertices[4]);
    graph_edge_add(g, vertices[0], vertices[7], 7);
    graph_vertex_remove(g, vertices[0]);
    graph_print(g);

    graph_vertex_remove(g, vertices[1]);
    graph_vertex_remove(g, vertices[2]);
    graph_vertex_remove(g, vertices[3]);
    graph_vertex_remove(g, vertices[4]);
    graph_vertex_remove(g, vertices[5]);
    graph_vertex_remove(g, vertices[6]);
    graph_vertex_remove(g, vertices[7]);

    assert(graph_vertex_num(g) == 0);

    graph_destroy(g);

    return 0;
}
Exemple #8
0
int main() {
	int n, m, c, k;
	graph_t* g=NULL;
	int* color_freq=NULL;
	skipws(stdin);

	while (!feof(stdin)) {

		graph_read(&g, &color_freq, &n, &m, &k, &c);
		/* Print out what we just read in. */
		fprintf(stdout,
		        "parameters: n = %d, m = %d, c = %d, k = %d\n",
		        n, m, c, k);
		graph_print(g, color_freq, c);

		/* Release memory & consider next graph. */
		FREE(color_freq);
		graph_free(g);
		skipws(stdin);
	}

	return EXIT_SUCCESS;
}
dstring_t *haplo_split(GapIO *io, snp_t *snp, int nsnps, int verbose,
		       double min_score, int two_pass, int fast_mode,
		       double c_offset, int max_sets) {
    graph *g;
    edge *e;
    dstring_t *ds;

    verbosity = verbose;
    g = graph_from_snps(io, snp, nsnps, c_offset);
    if (verbosity >= 3)
	print_matrix(g);

    graph_add_edges(g);
    graph_calc_chimeric_scores(g);
    graph_calc_link_scores(g, 1);
    if (verbosity >= 3)
	graph_print(g, 0);

    if (verbosity)
	puts("Merging graph nodes");

    while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	if (verbosity >= 1) {
	    putchar('.');
	    fflush(stdout);
	}
	merge_node(g, e);
	graph_calc_link_scores(g, fast_mode ? 0 : 1);
	if (verbosity >= 4) {
	    print_matrix(g);
	    graph_print(g, 1);
	}
    }
    if (verbosity >= 1)
	puts("");

    /* graph_print(g, 1); */

    if (two_pass) {
	/* Add fake zero-score edges if we want just 2-haplotypes */
	add_zero_edges(g);
	graph_calc_link_scores(g, 1);
	if (verbosity >= 4)
	    graph_print(g, 1);

	puts("===pass 2===");
	while ((e = best_edge(g)) && (e->linkage_score > min_score)) {
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	    /* graph_print(g, 1); */
	}
	/* graph_print(g, 1); */
    }

    /* Force number of groups to be X? */
    if (max_sets) {
	int ngroups = count_groups(g);
	add_zero_edges(g);
	for (; ngroups > max_sets; ngroups--) {
	    e = best_edge(g);
	    if (!e) {
		printf("Bailed out as no edge connecting groups\n");
		break;
	    }
	    merge_node(g, e);
	    graph_calc_link_scores(g, fast_mode ? 0 : 1);
	}
    }

    /* print_groups(g); */

    ds = list_groups(g);
    graph_destroy(g);

    return ds;
}