示例#1
0
void			displays_all(t_all *all)
{
	getmaxyx(stdscr, all->env.col, all->env.row);
	check_valid_win(all);
	display_grid(all);
	display_scores(all);
	if (all->env.win)
		display_victory(all);
	attron(COLOR_PAIR(2));
	display_edges(all);
	attroff(COLOR_PAIR(2));
}
示例#2
0
array_edges* kruskal(Graphe *graphe)
{
	int nb_vertices= graphe->vertices.nb_vertices;
	int nb_edges= graphe->edges.nb_edges;
	
	mysort(&(graphe->edges), nb_edges);
	array_edges* mst=(array_edges*)malloc(sizeof(array_edges));
	// Number of edges initialized at the number of vertices -1
	// (number of edges of the final mst)
	init_size_edges(mst, nb_vertices-1);
	int taille_mst=0;
	int noeud_actuel=0;
	subset mysubset[nb_vertices-1];
	int i;
	for(i=0;i<nb_vertices;i++)
	{
		mysubset[i].father=i;
		mysubset[i].value=0;
	}
	
	while(taille_mst < (nb_vertices-1))
	{
		edge *actual_edge=get_edge(graphe->edges, noeud_actuel);
		noeud_actuel++;
		
		int compressed_children=path_compression(mysubset,actual_edge->first_v-1);
		int compressed_father=path_compression(mysubset,actual_edge->second_v-1);
		if(compressed_children != compressed_father)
		{
			add_edge(mst, actual_edge->first_v,actual_edge->second_v,actual_edge->cost,taille_mst);
			taille_mst++;
			subset_union(mysubset,compressed_children,compressed_father);
		}
	}
	
	int total_weight=0;
	int nb;
#ifdef DEBUG
	display_edges(mst,taille_mst);
	for(nb=0;nb<taille_mst;nb++)
	{
		total_weight+=(get_edge(*mst, nb))->cost;
	}
	printf("Le cout total est de %d\n",(int) total_weight);
#endif
	
	return mst;
}
示例#3
0
void ntPolyline::display() {
    display_edges();
}
示例#4
0
void ntPolyline::display(float w) {
    stroke = w;
    display_edges(w);
}
示例#5
0
int main()
{
    char buffer[128], z[128];
    int num_nodes;
    struct node *nodes;
    int i, edge;
    char name[128];
    struct item **adj, *ptr;
    struct node *u;
    int source;
    struct entry *queue = NULL;
    
    printf("Enter nuber of nodes: ");
    fgets(buffer, 127, stdin);
    sscanf(buffer, "%d", &num_nodes);
    nodes = (struct node *) malloc(num_nodes * sizeof(struct node));
    
    /*Initialize the vertices*/
    for(i=0; i<num_nodes; ++i)
    {
        nodes[i].id = i+1;
        printf("Enter name of node %d: ", i+1);
        fgets(buffer, 127, stdin);
        sscanf(buffer, "%[^\n]s", name);
        nodes[i].name = (char *) (malloc((strlen(name)+1) * sizeof(char)));
        strcpy(nodes[i].name, name);
        nodes[i].d = LONG_MAX;
        nodes[i].c = 'w';
        nodes[i].p = NULL;
    }
    
    adj = (struct item **)malloc(num_nodes * sizeof(struct item *));
    /*Initialize adjacency list to NULL*/
    for(i=0; i<num_nodes; ++i)
        adj[i] = NULL;
        
    /*Add all the edges to adjacency list. No mechanism implemented to prevent multi-edges or self-loop*/
    for(i=0; i<num_nodes; ++i)
    {
        printf("Enter all edges from %s: (-1 to end)\n", nodes[i].name);
        while(1)
        {
            fgets(buffer, 127, stdin);
            sscanf(buffer, "%s", z);
            if(strcmp(z, "exit") == 0)
                break;
            edge = find_vertex(nodes, num_nodes, z);
            if(edge == -1)
            {
                printf("Vertex %s does not exist\n", z);
                break;
            }
            add_edge(&adj[i], edge);
        }
    }
    
    #ifdef DEBUG
    /*Display all the edges*/
    for(i=0; i<num_nodes; ++i)
        display_edges(adj[i], nodes, i);
    #endif
    
    /*Choose a source vertex*/
    printf("Enter the source vertex: ");
    fgets(buffer, 127, stdin);
    sscanf(buffer, "%s", z);
    source = find_vertex(nodes, num_nodes, z);
    if(source == -1)
    {
        printf("Invalid vertex\n");
        exit(-1);
    }
    #ifdef DEBUG
    printf("***DEBUG MODE ON***\n");
    #endif
    /*Perform a BFS*/
    nodes[source-1].d = 0;
    nodes[source-1].p = NULL;
    nodes[source-1].c = 'g';
    push(&queue, &nodes[source-1]);
    #ifdef DEBUG
    printf("Pushed %s\n", nodes[source-1].name);
    display_queue(queue);
    #endif
    while(!empty(queue))
    {
        u = pop(&queue);
        #ifdef DEBUG
        printf("Popped %s\n", u->name);
        display_queue(queue);
        #endif
        i = u->id;
        ptr = adj[i-1];
        while(ptr != NULL)
        {
            if(nodes[ptr->vertex-1].c == 'w')
            {
                nodes[ptr->vertex-1].c = 'g';
                nodes[ptr->vertex-1].d = u->d + 1;
                nodes[ptr->vertex-1].p = u;
                push(&queue, &nodes[ptr->vertex-1]);
                #ifdef DEBUG
                printf("Pushed %s\n", nodes[ptr->vertex-1].name);
                display_queue(queue);
                #endif
            }
            ptr = ptr->next;
        }
        u->c = 'b';
    }
    
    #ifdef DEBUG
    printf("***Printing paths***\n");
    #endif
    for(i=0; i<num_nodes; ++i)
    {
        if(i != source-1)
        {
            print_path(&nodes[source-1], &nodes[i]);
            printf("\n");
        }
    }
    
    return 1;
}