Commit f8ddd30d authored by Valentin MEUNIER's avatar Valentin MEUNIER
Browse files

debut de l aleatoir

parent d5abab2c
......@@ -26,13 +26,10 @@ int * dijsktra(graph_t * graph, int noeuds, int nb_aretes, int depart)
for (int i=0; i<noeuds; i++)
tas->tab[i]=distance[i];
int sommet= depart;
ajouter_tas_min(tas,distance[depart],indice_valeur);
int i=0;
int voisin;
affiche_graph_couple(graph,noeuds,nb_aretes);
while (nb_aretes)
{
for (int j=0; j<4; j++)
......@@ -54,10 +51,10 @@ int * dijsktra(graph_t * graph, int noeuds, int nb_aretes, int depart)
ajouter_tas_min(tas,distance[voisin],indice_valeur);
parent[voisin]=sommet;
A[i]=A[nb_aretes-1];
nb_aretes--;
if (i!=nb_aretes)
nb_aretes--;
voisin=-1;
}
// printf("poids :%d \n",tas->tab[indice_valeur[voisin]].poids);
else
{
if (distance[voisin].poids>1+distance[sommet].poids)
......@@ -68,7 +65,8 @@ int * dijsktra(graph_t * graph, int noeuds, int nb_aretes, int depart)
}
A[i]=A[nb_aretes-1];
voisin=-1;
nb_aretes--;
if (i!=nb_aretes)
nb_aretes--;
}
}
}
......@@ -86,12 +84,6 @@ int * dijsktra(graph_t * graph, int noeuds, int nb_aretes, int depart)
sommet=tas->tab[0].val;
}
//affichage(tas);
for(int i=0; i<noeuds; i++)
printf("%d ",parent[i]);
printf("\n");
printf("taille tas: %d\n",tas->taille);
printf("nb_aretes: %d\n", nb_aretes);
free(distance);
free(indice_valeur);
free(A);
......
#include "graph_aretes_tab.h"
int plusgrand(aretes_t a, aretes_t b)
/*int plusgrand(aretes_t a, aretes_t b)
{
return a.valuation>b.valuation;
}
return a.etiqdji>b.etiqdji;
}*/
graph_t * creer_graph(int n, int nb_aretes)
{
......
......@@ -13,6 +13,7 @@ typedef struct aretes
int un;
int deux;
int valuation;
int etiqdji;
}aretes_t;
......@@ -23,7 +24,7 @@ typedef struct graph
aretes_t * liste;
}graph_t;
int plusgrand(aretes_t, aretes_t);
/*int plusgrand(aretes_t, aretes_t);*/
graph_t * creer_graph(int n,int);
......
......@@ -95,6 +95,7 @@ void generation(graph_t * graph)
graph->liste[c].un=i;
graph->liste[c].deux=i+1;
graph->liste[c].valuation=1;
graph->liste[c].etiqdji=-1;
c++;
}
if (i/P<N-1)
......@@ -102,6 +103,7 @@ void generation(graph_t * graph)
graph->liste[c].un=i;
graph->liste[c].deux=i+P;
graph->liste[c].valuation=1;
graph->liste[c].etiqdji=-1;
c++;
}
}
......
......@@ -4,8 +4,8 @@
#include "tas.h"
#include "graph_aretes_tab.h"
#define N 30
#define P 52
#define N 13
#define P 15
graph_t * kruskal(graph_t * graph,int noeuds, int nb_aretes,int * cours,double p);
......
......@@ -57,6 +57,37 @@ void afficherEcranIntelligemment(SDL_Renderer *renderer,int **tab,int taille_cel
}
void chemin(SDL_Renderer * renderer, int depart, int arrivee, int taille_cell,int *parent)
{
SDL_DisplayMode screen;
SDL_GetCurrentDisplayMode(0,&screen);
int decalage_horizontale=(screen.w/taille_cell-P)*taille_cell/3;
int decalage_vertical=(screen.h/taille_cell-N)*taille_cell/4;
SDL_Rect rectangle;
int cours=depart;
SDL_SetRenderDrawColor(renderer, 0,255,0,0);
rectangle.x=taille_cell*(cours%P)+decalage_horizontale;
rectangle.y=taille_cell*(cours/P)+decalage_vertical;
rectangle.w=rectangle.h=taille_cell;
SDL_RenderFillRect(renderer, &rectangle);
cours=parent[cours];
SDL_SetRenderDrawColor(renderer, 255,0,0,0);
while(cours!=arrivee)
{
rectangle.x=taille_cell*(cours%P)+decalage_horizontale;
rectangle.y=taille_cell*(cours/P)+decalage_vertical;
rectangle.w=rectangle.h=taille_cell;
SDL_RenderFillRect(renderer, &rectangle);
cours=parent[cours];
}
cours=arrivee;
SDL_SetRenderDrawColor(renderer, 0,0,255,0);
rectangle.x=taille_cell*(cours%P)+decalage_horizontale;
rectangle.y=taille_cell*(cours/P)+decalage_vertical;
rectangle.w=rectangle.h=taille_cell;
SDL_RenderFillRect(renderer, &rectangle);
}
int min(int a, int b)
{
if (a>b)
......@@ -88,13 +119,16 @@ int main (int argc, char** argv)
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); /* SDL_RENDERER_SOFTWARE */
if (renderer == 0) fprintf(stderr, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError());
int running=1;
srand(time(0));
srand(0);
int noeuds=N*P;
int nb_aretes=2*N*P-N-P;
int **tab;
int *parent;
int cours=0;
int depart=0;
int arrivee=12;
int taille_cell=min(screen.w/(P+2),screen.h/(N+2));
printf("%d \n", taille_cell);
//printf("%d \n", taille_cell);
graph_t * graph=creer_graph(noeuds,nb_aretes);
generation(graph);
graph=Fisher(graph,nb_aretes);
......@@ -124,9 +158,13 @@ int main (int argc, char** argv)
break;
}
afficherEcranIntelligemment(renderer,tab,taille_cell);
SDL_RenderPresent(renderer);
SDL_Delay(10);
SDL_RenderClear(renderer);
depart=rand()%noeuds;
arrivee=rand()%noeuds;
parent=dijsktra(graph,noeuds,cours,arrivee);
chemin(renderer,depart, arrivee, taille_cell, parent);
SDL_RenderPresent(renderer);
SDL_Delay(1000);
SDL_RenderClear(renderer);
}
}
end_sdl(1, "Normal ending", window, renderer);
......
......@@ -6,6 +6,7 @@
#include<SDL2/SDL.h>
#include "kruskal.h"
#include "dijsktra.h"
#include <math.h>
void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment