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
c659adca
Commit
c659adca
authored
Jun 21, 2021
by
Valentin MEUNIER
Browse files
keuskam ok
parent
f5a1c2a8
Changes
2
Hide whitespace changes
Inline
Side-by-side
kruskal.c
View file @
c659adca
#include "kruskal.h"
int
*
tableau_ligne
(
graph_t
*
graph
,
int
noeuds
,
int
nb_aretes
)
{
for
(
int
i
=
0
;
i
<
nb_aretes
;
i
++
)
{
diff
=
graph
->
liste
[
i
].
un
-
graph
->
liste
[
i
].
deux
if
(
diff
==
1
)
tab
[
}
int
main
(
)
graph_t
*
kruskal
(
graph_t
*
graph
,
int
noeuds
,
int
nb_aretes
,
int
*
cours
)
{
int
noeuds
=
10
;
srand
(
time
(
0
));
int
nb_aretes
=
10
;
int
c1
;
int
c2
;
// int ** mat=NULL;
// mat= creer_mat(10);
graph_t
*
graph
=
creer_graph
(
noeuds
,
nb_aretes
);
graph_t
*
A
=
creer_graph
(
noeuds
,
nb_aretes
);
partition_t
*
part
=
creer
(
noeuds
);
partition_t
*
partA
=
creer
(
noeuds
);
// int liste_part[noeuds];
for
(
int
i
=
0
;
i
<
nb_aretes
;
i
++
)
{
graph
->
liste
[
i
].
un
=
rand
()
%
noeuds
;
graph
->
liste
[
i
].
deux
=
rand
()
%
noeuds
;
graph
->
liste
[
i
].
valuation
=
rand
()
%
noeuds
;
}
affiche_graph_couple
(
graph
,
noeuds
,
nb_aretes
);
affiche_part
(
part
,
noeuds
);
graph
->
liste
=
tri_par_tas
(
graph
->
liste
,
nb_aretes
)
->
tab
;
int
cours
=
0
;
for
(
int
i
=
0
;
i
<
nb_aretes
;
i
++
)
{
// printf("dans le for\n");
// printf("%d \n", graph->liste[i].un);
// affiche_part(partA,noeuds);
c1
=
recuperer_classe
(
graph
->
liste
[
i
].
un
,
partA
);
c2
=
recuperer_classe
(
graph
->
liste
[
i
].
deux
,
partA
);
// printf("%d %d\n",c1,c2);
if
(
c1
!=
c2
)
{
A
->
liste
[
cours
]
=
graph
->
liste
[
i
];
fusion
(
A
->
liste
[
cours
].
un
,
A
->
liste
[
cours
].
deux
,
partA
);
cours
+=
1
;
A
->
liste
[
*
cours
]
=
graph
->
liste
[
i
];
fusion
(
A
->
liste
[
*
cours
].
un
,
A
->
liste
[
*
cours
].
deux
,
partA
);
*
cours
+=
1
;
}
}
return
A
;
}
graph_t
*
Fisher
(
graph_t
*
graph
,
int
nb_aretes
)
{
aretes_t
aux
;
int
random
;
for
(
int
i
=
nb_aretes
-
1
;
i
>
0
;
i
--
)
{
random
=
rand
()
%
i
;
// printf("%d ",random);
aux
=
graph
->
liste
[
random
];
graph
->
liste
[
random
]
=
graph
->
liste
[
i
];
graph
->
liste
[
i
]
=
aux
;
}
return
graph
;
}
int
generation
(
graph_t
*
graph
,
int
n
,
int
p
)
{
int
nb_aretes
=
0
;
int
rand1
;
int
rand2
;
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
)
{
graph
->
liste
[
nb_aretes
].
un
=
i
;
graph
->
liste
[
nb_aretes
].
deux
=
i
+
1
;
graph
->
liste
[
nb_aretes
].
valuation
=
1
;
nb_aretes
++
;
}
if
(
rand2
&&
i
<
(
n
-
1
)
*
p
)
{
graph
->
liste
[
nb_aretes
].
un
=
i
;
graph
->
liste
[
nb_aretes
].
deux
=
i
+
n
;
graph
->
liste
[
nb_aretes
].
valuation
=
1
;
nb_aretes
++
;
}
}
return
nb_aretes
;
}
int
main
()
{
srand
(
time
(
0
));
int
nb_aretes
=
10
;
int
ligne
=
4
;
int
colonne
=
5
;
int
noeuds
=
ligne
*
colonne
;
int
cours
=
0
;
// int ** mat=NULL;
// mat= creer_mat(10);
graph_t
*
graph
=
creer_graph
(
noeuds
,
100
);
partition_t
*
part
=
creer
(
noeuds
);
printf
(
"%d
\n
"
,
nb_aretes
);
nb_aretes
=
generation
(
graph
,
4
,
5
);
/* for (int i=0; i<nb_aretes; i++)
{
printf("un :%d ",graph->liste[i].un);
printf("deux :%d ",graph->liste[i].deux);
printf("val :%d ",graph->liste[i].valuation);
printf("\n");
}
printf("\n");
*/
graph
=
Fisher
(
graph
,
nb_aretes
);
// int liste_part[noeuds];
/* for (int i=0; i<nb_aretes; i++)
{
graph->liste[i].un=rand()%noeuds;
graph->liste[i].deux=rand()%noeuds;
graph->liste[i].valuation=rand()%noeuds;
}
graph->liste=tri_par_tas(graph->liste,nb_aretes)->tab;
*/
affiche_graph_couple
(
graph
,
noeuds
,
nb_aretes
);
// affiche_part(part,noeuds);
graph
=
kruskal
(
graph
,
noeuds
,
nb_aretes
,
&
cours
);
affiche_graph_couple
(
A
,
noeuds
,
cours
);
affiche_graph_couple
(
graph
,
noeuds
,
cours
);
system
(
"dot -Tpng graph_part.dot -o graph_part.png"
);
/*
system("dot -Tpng graph_part.dot -o graph_part.png");
system("display graph_part.png &");
*/
/* nbpart=lister_partition(part,10,liste_part);
for (int i=0;i<nbpart;i++)
{
...
...
@@ -53,8 +131,6 @@ int main()
*/
free
(
graph
->
liste
);
free
(
graph
);
free
(
A
->
liste
);
free
(
A
);
free
(
part
);
return
0
;
}
kruskal.h
View file @
c659adca
...
...
@@ -3,6 +3,13 @@
#include "tas.h"
#include "graph_aretes_tab.h"
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
);
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