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
8bd72610
Commit
8bd72610
authored
Jun 23, 2021
by
Valentin MEUNIER
Browse files
Aetoile mais avec la distance euclidienne ça marche bcp top bien prblemt faux
parent
2c700235
Changes
2
Hide whitespace changes
Inline
Side-by-side
laby/Aetoile.c
View file @
8bd72610
#include "Aetoile.h"
int
distance_euclidienne
(
int
a
,
int
b
);
int
max
(
int
a
,
int
b
)
{
if
(
a
>
b
)
return
a
;
else
return
b
;
}
int
distance_euclidienne
(
int
a
,
int
b
)
{
return
(
int
)
sqrt
((
a
/
P
-
b
/
b
)
*
(
a
/
P
-
b
/
P
)
+
(
a
%
P
-
b
%
P
)
*
(
a
%
P
-
b
%
P
));
}
...
...
@@ -15,7 +23,7 @@ int distance_manhattan(int a, int b)
return
(
abs
(
a
/
P
-
b
/
P
)
+
abs
(
a
%
P
-
b
%
P
));
}
int
*
Aetoile_euclidienne
(
int
**
laby
,
int
noeuds
,
int
depart
)
int
*
dijsktra
(
int
**
laby
,
int
noeuds
,
int
depart
)
{
int
*
parent
=
malloc
(
noeuds
*
sizeof
(
int
));
parent
[
depart
]
=
depart
;
...
...
@@ -62,15 +70,15 @@ int * Aetoile_euclidienne(int ** laby, int noeuds, int depart)
{
if
(
indice_valeur
[
voisin
[
j
]]
==-
1
)
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_euclidienne
(
voisin
[
j
],
sommet
)
;
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
;
ajouter_tas_min
(
tas
,
distance
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
else
{
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
+
distance_euclidienne
(
voisin
[
j
],
sommet
)
)
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
)
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_euclidienne
(
voisin
[
j
],
sommet
)
;
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
;
percolation_bas_tas_min
(
tas
,
indice_valeur
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
...
...
@@ -98,7 +106,7 @@ int * Aetoile_euclidienne(int ** laby, int noeuds, int depart)
return
parent
;
}
int
*
Aetoile_
tcheby
(
int
**
laby
,
int
noeuds
,
int
depart
)
int
*
Aetoile_
euclidienne
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
arrivee
)
{
int
*
parent
=
malloc
(
noeuds
*
sizeof
(
int
));
parent
[
depart
]
=
depart
;
...
...
@@ -145,15 +153,15 @@ int * Aetoile_tcheby(int ** laby, int noeuds, int depart)
{
if
(
indice_valeur
[
voisin
[
j
]]
==-
1
)
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
sommet
);
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
euclidienne
(
voisin
[
j
],
arrivee
);
ajouter_tas_min
(
tas
,
distance
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
else
{
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
sommet
))
if
(
distance
[
voisin
[
j
]].
poids
>
(
1
+
distance
[
sommet
].
poids
+
distance_
euclidienne
(
voisin
[
j
],
arrivee
)
))
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
sommet
);
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
euclidienne
(
voisin
[
j
],
arrivee
);
percolation_bas_tas_min
(
tas
,
indice_valeur
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
...
...
@@ -181,7 +189,7 @@ int * Aetoile_tcheby(int ** laby, int noeuds, int depart)
return
parent
;
}
int
*
Aetoile_
manhattan
(
int
**
laby
,
int
noeuds
,
int
depart
)
int
*
Aetoile_
tcheby
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
arrivee
)
{
int
*
parent
=
malloc
(
noeuds
*
sizeof
(
int
));
parent
[
depart
]
=
depart
;
...
...
@@ -228,15 +236,15 @@ int * Aetoile_manhattan(int ** laby, int noeuds, int depart)
{
if
(
indice_valeur
[
voisin
[
j
]]
==-
1
)
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
manhattan
(
voisin
[
j
],
sommet
);
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
arrivee
);
ajouter_tas_min
(
tas
,
distance
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
else
{
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
+
distance_
manhattan
(
voisin
[
j
],
sommet
))
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
arrivee
))
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
manhattan
(
voisin
[
j
],
sommet
);
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_
tcheby
(
voisin
[
j
],
arrivee
);
percolation_bas_tas_min
(
tas
,
indice_valeur
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
...
...
@@ -263,3 +271,141 @@ int * Aetoile_manhattan(int ** laby, int noeuds, int depart)
liberer
(
tas
);
return
parent
;
}
int
*
Aetoile_manhattan
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
arrivee
)
{
int
*
parent
=
malloc
(
noeuds
*
sizeof
(
int
));
parent
[
depart
]
=
depart
;
poids_t
*
distance
=
malloc
(
noeuds
*
sizeof
(
poids_t
));
for
(
int
i
=
0
;
i
<
noeuds
;
i
++
)
{
distance
[
i
].
poids
=
noeuds
;
distance
[
i
].
val
=
i
;
}
distance
[
depart
].
poids
=
0
;
int
*
indice_valeur
=
malloc
(
noeuds
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
noeuds
;
i
++
)
indice_valeur
[
i
]
=-
1
;
tas_t
*
tas
=
init_tas
(
noeuds
+
1
);
for
(
int
i
=
0
;
i
<
noeuds
;
i
++
)
tas
->
tab
[
i
]
=
distance
[
i
];
int
*
voisin
=
malloc
(
4
*
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
4
;
i
++
)
voisin
[
i
]
=-
1
;
int
sommet
=
depart
;
ajouter_tas_min
(
tas
,
distance
[
depart
],
indice_valeur
);
while
(
tas
->
taille
>-
1
)
{
if
(
laby
[
sommet
%
P
][
sommet
/
P
]
&
FLAG_N
)
voisin
[
0
]
=
sommet
-
P
;
if
(
laby
[
sommet
%
P
][
sommet
/
P
]
&
FLAG_S
)
voisin
[
1
]
=
sommet
+
P
;
if
(
laby
[
sommet
%
P
][
sommet
/
P
]
&
FLAG_O
)
voisin
[
2
]
=
sommet
-
1
;
if
(
laby
[
sommet
%
P
][
sommet
/
P
]
&
FLAG_E
)
voisin
[
3
]
=
sommet
+
1
;
for
(
int
j
=
0
;
j
<
4
;
j
++
)
{
if
(
voisin
[
j
]
!=-
1
)
{
if
(
indice_valeur
[
voisin
[
j
]]
!=-
2
)
{
if
(
indice_valeur
[
voisin
[
j
]]
==-
1
)
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_manhattan
(
voisin
[
j
],
arrivee
);
ajouter_tas_min
(
tas
,
distance
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
else
{
if
(
distance
[
voisin
[
j
]].
poids
>
1
+
distance
[
sommet
].
poids
+
distance_manhattan
(
voisin
[
j
],
arrivee
))
{
distance
[
voisin
[
j
]].
poids
=
1
+
distance
[
sommet
].
poids
+
distance_manhattan
(
voisin
[
j
],
arrivee
);
percolation_bas_tas_min
(
tas
,
indice_valeur
[
voisin
[
j
]],
indice_valeur
);
parent
[
voisin
[
j
]]
=
sommet
;
}
}
}
}
voisin
[
j
]
=-
1
;
}
indice_valeur
[
tas
->
tab
[
0
].
val
]
=-
2
;
indice_valeur
[
tas
->
tab
[
tas
->
taille
].
val
]
=
0
;
typetas
aux
=
tas
->
tab
[
0
];
tas
->
tab
[
0
]
=
tas
->
tab
[
tas
->
taille
];
tas
->
tab
[
tas
->
taille
]
=
aux
;
tas
->
taille
+=-
1
;
percolation_bas_tas_min
(
tas
,
0
,
indice_valeur
);
sommet
=
tas
->
tab
[
0
].
val
;
}
free
(
distance
);
free
(
indice_valeur
);
liberer
(
tas
);
return
parent
;
}
int
main
(
int
argc
,
char
**
argv
)
{
double
p
;
if
(
argc
==
2
)
p
=
atof
(
argv
[
1
]);
else
p
=
1
;
srand
(
time
(
0
));
int
noeuds
=
N
*
P
;
int
nb_aretes
=
2
*
N
*
P
-
N
-
P
;
int
**
tab
;
int
*
parent
;
int
cours
=
0
;
graph_t
*
graph
=
creer_graph
(
noeuds
,
nb_aretes
);
generation
(
graph
);
graph
=
Fisher
(
graph
,
nb_aretes
);
graph
=
kruskal
(
graph
,
noeuds
,
nb_aretes
,
&
cours
,
p
);
tab
=
tableau_ligne
(
graph
,
cours
);
int
depart
=
rand
()
%
noeuds
;
int
arrivee
=
rand
()
%
noeuds
;
clock_t
t_depart
,
t_fin
;
float
temps
;
t_depart
=
clock
();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
parent
=
dijsktra
(
tab
,
noeuds
,
arrivee
);
t_fin
=
clock
();
temps
=-
t_depart
+
t_fin
;
printf
(
"temps dijsktra : %f
\n
"
,
temps
/
1000
);
t_depart
=
clock
();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
parent
=
Aetoile_euclidienne
(
tab
,
noeuds
,
depart
,
arrivee
);
t_fin
=
clock
();
temps
=-
t_depart
+
t_fin
;
printf
(
"temps Aetoile_euclidienne : %f
\n
"
,
temps
/
1000
);
t_depart
=
clock
();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
parent
=
Aetoile_tcheby
(
tab
,
noeuds
,
depart
,
arrivee
);
t_fin
=
clock
();
temps
=-
t_depart
+
t_fin
;
printf
(
"temps Aetoile_tcheby : %f
\n
"
,
temps
/
1000
);
t_depart
=
clock
();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
parent
=
Aetoile_manhattan
(
tab
,
noeuds
,
depart
,
arrivee
);
t_fin
=
clock
();
temps
=-
t_depart
+
t_fin
;
printf
(
"temps Aetoile_manhattan: %f
\n
"
,
temps
/
1000
);
}
laby/Aetoile.h
0 → 100644
View file @
8bd72610
#ifndef _gard_Aetoile_
#define _gard_Aetoile__
/*gcc Aetoile.c -c -Wall -Wextra
gcc Aetoile.o kruskal.o graph_aretes_tab.o tas.o partition.o -lm -o Aetoile -g*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include <time.h>
#include <math.h>
#include "graph_aretes_tab.h"
#include "tas.h"
#include "kruskal.h"
typedef
enum
{
FLAG_N
=
1
,
FLAG_S
=
2
,
FLAG_E
=
4
,
FLAG_O
=
8
}
flag_t
;
int
distance_euclidienne
(
int
a
,
int
b
);
int
distance_tcheby
(
int
a
,
int
b
);
int
distance_manhattan
(
int
a
,
int
b
);
int
*
dijsktra
(
int
**
,
int
,
int
);
int
*
Aetoile_euclidienne
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
);
int
*
Aetoile_tcheby
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
);
int
*
Aetoile_manhattan
(
int
**
laby
,
int
noeuds
,
int
depart
,
int
);
int
main
(
int
argc
,
char
**
argv
);
#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