Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marian POIROT
Our awesome project
Commits
cd8a8cf6
Commit
cd8a8cf6
authored
Jun 21, 2021
by
Valentin MEUNIER
Browse files
enfin
parent
de4059ec
Changes
5
Hide whitespace changes
Inline
Side-by-side
laby/graph_aretes_tab.h
View file @
cd8a8cf6
...
...
@@ -35,5 +35,4 @@ void partition_connexe(partition_t *,graph_t *,int);
void
affiche_graph2
(
graph_t
*
,
partition_t
*
,
int
,
int
,
int
);
int
main
();
#endif
laby/kruskal.c
View file @
cd8a8cf6
...
...
@@ -2,27 +2,46 @@
int
**
tableau_ligne
(
graph_t
*
graph
,
int
nb_aretes
)
{
int
**
tab
=
malloc
(
N
*
sizeof
(
int
*
));
for
(
int
i
=
0
;
i
<
N
;
i
++
)
tab
[
i
]
=
malloc
(
P
*
sizeof
(
int
));
int
**
tab
=
malloc
(
P
*
sizeof
(
int
*
));
for
(
int
i
=
0
;
i
<
P
;
i
++
)
tab
[
i
]
=
malloc
(
N
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
P
;
i
++
)
for
(
int
j
=
0
;
j
<
N
;
j
++
)
tab
[
i
][
j
]
=
0
;
int
diff
;
int
x
;
int
y
;
for
(
int
i
=
0
;
i
<
nb_aretes
;
i
++
)
{
diff
=
graph
->
liste
[
i
].
un
-
graph
->
liste
[
i
].
deux
;
x
=
graph
->
liste
[
i
].
un
%
N
;
y
=
graph
->
liste
[
i
].
un
%
P
;
if
(
x
==
0
)
tab
[
x
][
y
]
+=
8
;
if
(
y
==
0
)
tab
[
x
][
y
]
+=
1
;
diff
=
abs
(
graph
->
liste
[
i
].
un
-
graph
->
liste
[
i
].
deux
);
x
=
graph
->
liste
[
i
].
un
%
P
;
y
=
graph
->
liste
[
i
].
un
/
P
;
// printf("sommet1: %d sommet2: %d x :%d y :%d diff :%d\n",graph->liste[i].un,graph->liste[i].deux,x,y,diff);
if
(
diff
==
1
)
tab
[
x
][
y
]
+=
4
;
else
else
// ne marche pas c'est incomprehensibleif (diff==P)
tab
[
x
][
y
]
+=
2
;
}
return
tab
;
/*
for (int i=0; i<N; i++)
{
tab[i][0]-=8;
tab[i][P-1]-=4;
}
for(int j=0; j<P; j++)
{
tab[0][j]-=1;
tab[N-1][j]-=2;
}*/
/* for (int i=0; i<N; i++)
{
for (int j=0; j<P; j++)
printf("%d ", tab[j][i]);
printf("\n");
}*/
return
tab
;
}
graph_t
*
kruskal
(
graph_t
*
graph
,
int
noeuds
,
int
nb_aretes
,
int
*
cours
)
...
...
@@ -65,32 +84,27 @@ graph_t * Fisher(graph_t * graph, int nb_aretes)
return
graph
;
}
int
generation
(
graph_t
*
graph
,
int
n
,
int
p
)
void
generation
(
graph_t
*
graph
)
{
int
nb_aretes
=
0
;
int
rand1
;
int
rand2
;
for
(
int
i
=
0
;
i
<
n
*
p
;
i
++
)
int
c
=
0
;
for
(
int
i
=
0
;
i
<
N
*
P
;
i
++
)
{
rand1
=
(
rand
()
%
8
);
rand2
=
(
rand
()
%
8
);
printf
(
"%d %d
\n
"
,
rand1
,
rand2
);
if
(
rand1
&&
(
i
+
1
)
%
n
)
if
((
i
+
1
)
%
P
)
{
graph
->
liste
[
nb_aretes
].
un
=
i
;
graph
->
liste
[
nb_aretes
].
deux
=
i
+
1
;
graph
->
liste
[
nb_aretes
].
valuation
=
1
;
nb_aretes
++
;
graph
->
liste
[
c
].
un
=
i
;
graph
->
liste
[
c
].
deux
=
i
+
1
;
graph
->
liste
[
c
].
valuation
=
1
;
c
++
;
}
if
(
rand2
&&
i
<
(
n
-
1
)
*
p
)
if
(
i
/
P
<
N
-
1
)
{
graph
->
liste
[
nb_aretes
].
un
=
i
;
graph
->
liste
[
nb_aretes
].
deux
=
i
+
n
;
graph
->
liste
[
nb_aretes
].
valuation
=
1
;
nb_aretes
++
;
}
graph
->
liste
[
c
].
un
=
i
;
graph
->
liste
[
c
].
deux
=
i
+
P
;
graph
->
liste
[
c
].
valuation
=
1
;
c
++
;
}
}
return
nb_aretes
;
}
/*
int main()
...
...
laby/kruskal.h
View file @
cd8a8cf6
...
...
@@ -4,14 +4,14 @@
#include "tas.h"
#include "graph_aretes_tab.h"
#define N
4
#define P 5
#define N
30
#define P 5
2
graph_t
*
kruskal
(
graph_t
*
graph
,
int
noeuds
,
int
nb_aretes
,
int
*
cours
);
graph_t
*
Fisher
(
graph_t
*
graph
,
int
nb_aretes
);
int
generation
(
graph_t
*
graph
,
int
n
,
int
p
);
void
generation
(
graph_t
*
graph
);
int
**
tableau_ligne
(
graph_t
*
,
int
);
...
...
laby/main.c
View file @
cd8a8cf6
...
...
@@ -27,40 +27,40 @@ void end_sdl(char ok,char const* msg,SDL_Window* window, SDL_Renderer* renderer)
void
afficherEcranIntelligemment
(
SDL_Renderer
*
renderer
,
int
**
tab
,
int
taille_cell
)
{
int
i1
,
j1
,
x
,
noeud
=
0
;
int
x
=
0
;
SDL_SetRenderDrawColor
(
renderer
,
255
,
255
,
255
,
0
);
SDL_RenderClear
(
renderer
);
SDL_SetRenderDrawColor
(
renderer
,
0
,
0
,
0
,
0
);
SDL_SetRenderDrawColor
(
renderer
,
255
,
0
,
0
,
0
);
SDL_RenderDrawLine
(
renderer
,
0
,
0
,
P
*
taille_cell
,
0
);
//mur au nord
SDL_RenderDrawLine
(
renderer
,
0
,
N
*
taille_cell
,
P
*
taille_cell
,(
N
)
*
taille_cell
);
//mur au sud
SDL_RenderDrawLine
(
renderer
,
0
,
0
,
0
,(
N
)
*
taille_cell
);
//mur à l'ouest
SDL_RenderDrawLine
(
renderer
,(
P
)
*
taille_cell
,
0
,(
P
)
*
taille_cell
,(
N
)
*
taille_cell
);
//mur à l'est
for
(
int
i
=
0
;
i
<
N
;
i
++
)
SDL_SetRenderDrawColor
(
renderer
,
0
,
0
,
0
,
0
);
for
(
int
i
=
0
;
i
<
P
;
i
++
)
{
for
(
int
j
=
0
;
j
<
P
;
j
++
)
for
(
int
j
=
0
;
j
<
N
;
j
++
)
{
x
=
tab
[
i
][
j
];
i1
=
(
noeud
%
P
)
+
1
;
j1
=
(
noeud
/
P
)
+
1
;
printf
(
"%d %d
\n
"
,
noeud
,
x
);
if
(
x
%
2
!=
1
)
SDL_RenderDrawLine
(
renderer
,
i1
*
taille_cell
+
50
,
j1
*
taille_cell
+
50
,(
i1
+
1
)
*
taille_cell
+
50
,
j1
*
taille_cell
+
50
);
//mur au nord
if
((
x
!=
2
)
&&
(
x
!=
3
)
&&
(
x
!=
6
)
&&
(
x
!=
7
)
&&
(
x
!=
10
)
&&
(
x
!=
11
)
&&
(
x
!=
14
)
&&
(
x
!=
15
))
SDL_RenderDrawLine
(
renderer
,
i1
*
taille_cell
+
50
,(
j1
+
1
)
*
taille_cell
+
50
,(
i1
+
1
)
*
taille_cell
+
50
,(
j1
+
1
)
*
taille_cell
+
50
);
//mur au sud
if
((
x
!=
4
)
&&
(
x
!=
5
)
&&
(
x
!=
6
)
&&
(
x
!=
7
)
&&
(
x
!=
12
)
&&
(
x
!=
13
)
&&
(
x
!=
14
)
&&
(
x
!=
15
))
SDL_RenderDrawLine
(
renderer
,(
i1
+
1
)
*
taille_cell
+
50
,
j1
*
taille_cell
+
50
,(
i1
+
1
)
*
taille_cell
+
50
,(
j1
+
1
)
*
taille_cell
+
50
);
//mur à l'est
if
(
x
<
8
)
SDL_RenderDrawLine
(
renderer
,
i1
*
taille_cell
+
50
,
j1
*
taille_cell
+
50
,
i1
*
taille_cell
+
50
,(
j1
+
1
)
*
taille_cell
+
50
);
//mur à l'ouest
noeud
+=
1
;
if
((
x
!=
2
)
&&
(
x
!=
6
))
SDL_RenderDrawLine
(
renderer
,
i
*
taille_cell
,(
j
+
1
)
*
taille_cell
,(
i
+
1
)
*
taille_cell
,(
j
+
1
)
*
taille_cell
);
//mur au sud
if
((
x
!=
4
)
&&
(
x
!=
6
))
SDL_RenderDrawLine
(
renderer
,(
i
+
1
)
*
taille_cell
,
j
*
taille_cell
,(
i
+
1
)
*
taille_cell
,(
j
+
1
)
*
taille_cell
);
//mur à l'est
}
}
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
3000
);
SDL_RenderClear
(
renderer
);
}
int
min
(
int
a
,
int
b
)
{
if
(
a
>
b
)
return
b
;
else
return
a
;
}
int
main
()
...
...
@@ -71,30 +71,32 @@ int main ()
return
EXIT_FAILURE
;
}
int
width
=
800
;
int
height
=
900
;
SDL_DisplayMode
screen
;
SDL_GetCurrentDisplayMode
(
0
,
&
screen
)
;
SDL_Window
*
window
;
window
=
SDL_CreateWindow
(
"SDL2 Programme 0.1"
,
SDL_WINDOWPOS_CENTERED
,
SDL_WINDOWPOS_CENTERED
,
width
,
height
,
SDL_WINDOW_RESIZABLE
);
window
=
SDL_CreateWindow
(
"SDL2 Programme 0.1"
,
SDL_WINDOWPOS_CENTERED
,
SDL_WINDOWPOS_CENTERED
,
screen
.
w
,
screen
.
h
,
SDL_WINDOW_RESIZABLE
);
if
(
window
==
0
)
fprintf
(
stderr
,
"Erreur d'initialisation de la SDL : %s
\n
"
,
SDL_GetError
());
SDL_SetWindowTitle
(
window
,
"Mon_chef d'oeuvre"
);
SDL_Renderer
*
renderer
;
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
));
int
noeuds
=
N
*
P
;
int
nb_aretes
;
int
nb_aretes
=
2
*
N
*
P
-
N
-
P
;
int
**
tab
;
graph_t
*
graph
=
creer_graph
(
noeuds
,
100
);
partition_t
*
part
=
creer
(
noeuds
);
nb_aretes
=
generation
(
graph
,
4
,
5
);
int
cours
=
0
;
int
taille_cell
=
min
(
screen
.
w
/
(
P
+
2
),
screen
.
h
/
(
N
+
2
));
printf
(
"%d
\n
"
,
taille_cell
);
graph_t
*
graph
=
creer_graph
(
noeuds
,
nb_aretes
);
generation
(
graph
);
graph
=
Fisher
(
graph
,
nb_aretes
);
affiche_graph_couple
(
graph
,
noeuds
,
nb_aretes
);
//printf("%d \n",
nb_aretes);
graph
=
kruskal
(
graph
,
noeuds
,
nb_aretes
,
&
cours
);
affiche_graph_couple
(
graph
,
noeuds
,
nb_aretes
);
tab
=
tableau_ligne
(
graph
,
nb_aretes
);
//printf("cours %d\n",cours);
// affiche_graph_couple(graph,noeuds,cours);
tab
=
tableau_ligne
(
graph
,
cours
);
SDL_Event
event
;
while
(
running
)
...
...
@@ -112,21 +114,17 @@ int main ()
case
SDL_WINDOWEVENT_CLOSE
:
running
=
0
;
break
;
case
SDL_WINDOWEVENT_SIZE_CHANGED
:
width
=
event
.
window
.
data1
;
height
=
event
.
window
.
data2
;
break
;
case
SDL_WINDOWEVENT_EXPOSED
:
default:
break
;
}
break
;
break
;
}
afficherEcranIntelligemment
(
renderer
,
tab
,
taille_cell
);
SDL_RenderPresent
(
renderer
);
SDL_Delay
(
10
);
SDL_RenderClear
(
renderer
);
}
afficherEcranIntelligemment
(
renderer
,
tab
,
100
);
SDL_RenderClear
(
renderer
);
SDL_Delay
(
30
);
SDL_RenderPresent
(
renderer
);
}
end_sdl
(
1
,
"Normal ending"
,
window
,
renderer
);
return
1
;
...
...
laby/main.h
View file @
cd8a8cf6
...
...
@@ -6,10 +6,11 @@
#include<SDL2/SDL.h>
#include "kruskal.h"
#include <math.h>
void
end_sdl
(
char
ok
,
char
const
*
msg
,
SDL_Window
*
window
,
SDL_Renderer
*
renderer
);
void
afficheEcranIntelligement
(
SDL_Renderer
*
,
int
**
,
int
);
int
min
(
int
,
int
);
int
main
();
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment