Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
P
pygroupJ4
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Conditions générales et politique de confidentialité
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Christophe Leblanc
pygroupJ4
Validations
3a3ed699
Valider
3a3ed699
rédigé
2 years ago
par
Louis Navarre
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Format of code
parent
348931da
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
shortest_path.py
+66
-66
66 ajouts, 66 suppressions
shortest_path.py
avec
66 ajouts
et
66 suppressions
shortest_path.py
+
66
−
66
Voir le fichier @
3a3ed699
import
numpy
as
np
import
math
import
math
import
argparse
import
argparse
import
sys
import
sys
import
os
parser
=
argparse
.
ArgumentParser
(
parser
=
argparse
.
ArgumentParser
(
description
=
"
LEPL1503 - Détection et correction d
'
erreurs
"
)
description
=
"
LEPL1503 - Détection et correction d
'
erreurs
"
)
parser
.
add_argument
(
"
input_file
"
,
help
=
"
Nom du fichier contenant les données nécessaires
"
)
parser
.
add_argument
(
parser
.
add_argument
(
"
-f
"
,
help
=
"
Chemin vers le fichier de sortie
"
,
type
=
argparse
.
FileType
(
"
wb
"
),
default
=
sys
.
stdout
)
"
input_file
"
,
help
=
"
Nom du fichier contenant les données nécessaires
"
)
parser
.
add_argument
(
"
-v
"
,
help
=
"
\"
verbose
\"
mode: si ajouté, affiche des informations sur l
'
exécution du programme
"
,
action
=
"
store_true
"
)
parser
.
add_argument
(
"
-f
"
,
help
=
"
Chemin vers le fichier de sortie
"
,
type
=
argparse
.
FileType
(
"
wb
"
),
default
=
sys
.
stdout
)
parser
.
add_argument
(
"
-v
"
,
help
=
"
\"
verbose
\"
mode: si ajouté, affiche des informations sur l
'
exécution du programme
"
,
action
=
"
store_true
"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
verbose
=
args
.
v
verbose
=
args
.
v
...
@@ -21,102 +22,101 @@ nb_edges = None
...
@@ -21,102 +22,101 @@ nb_edges = None
if
verbose
:
if
verbose
:
print
(
args
,
file
=
sys
.
stderr
)
print
(
args
,
file
=
sys
.
stderr
)
def
get_file_infos
(
data
):
def
get_file_infos
(
data
):
nb_nodes
=
int
.
from_bytes
(
data
[
0
:
4
],
"
big
"
,
signed
=
True
)
nb_nodes
=
int
.
from_bytes
(
data
[
0
:
4
],
"
big
"
,
signed
=
True
)
nb_edges
=
int
.
from_bytes
(
data
[
4
:],
"
big
"
,
signed
=
True
)
nb_edges
=
int
.
from_bytes
(
data
[
4
:],
"
big
"
,
signed
=
True
)
return
nb_nodes
,
nb_edges
return
nb_nodes
,
nb_edges
def
bellman_ford
(
table
,
s
):
def
bellman_ford
(
table
,
s
):
dist
=
[
math
.
inf
]
*
nb_nodes
dist
=
[
math
.
inf
]
*
nb_nodes
dist
[
s
]
=
0
dist
[
s
]
=
0
path
=
[
-
1
]
*
nb_nodes
path
=
[
-
1
]
*
nb_nodes
for
_
in
range
(
nb_nodes
-
1
):
for
_
in
range
(
nb_nodes
-
1
):
for
j
in
range
(
len
(
table
)):
for
j
in
range
(
len
(
table
)):
a
,
b
,
cab
=
table
[
j
][
0
],
table
[
j
][
1
],
table
[
j
][
2
]
a
,
b
,
cab
=
table
[
j
][
0
],
table
[
j
][
1
],
table
[
j
][
2
]
if
(
dist
[
a
]
!=
math
.
inf
and
dist
[
b
]
>
dist
[
a
]
+
cab
):
if
(
dist
[
a
]
!=
math
.
inf
and
dist
[
b
]
>
dist
[
a
]
+
cab
):
dist
[
b
]
=
dist
[
a
]
+
cab
dist
[
b
]
=
dist
[
a
]
+
cab
path
[
b
]
=
a
path
[
b
]
=
a
for
j
in
range
(
len
(
table
)):
for
j
in
range
(
len
(
table
)):
a
,
b
,
cab
=
table
[
j
][
0
],
table
[
j
][
1
],
table
[
j
][
2
]
a
,
b
,
cab
=
table
[
j
][
0
],
table
[
j
][
1
],
table
[
j
][
2
]
if
(
dist
[
a
]
!=
math
.
inf
and
dist
[
b
]
>
dist
[
a
]
+
cab
):
if
(
dist
[
a
]
!=
math
.
inf
and
dist
[
b
]
>
dist
[
a
]
+
cab
):
print
(
"
Cycle négatif détecté
"
)
print
(
"
Cycle négatif détecté
"
)
return
-
1
,
-
1
return
-
1
,
-
1
return
dist
,
path
return
dist
,
path
def
get_path
(
dest
,
path
,
source
):
def
get_path
(
dest
,
path
,
source
):
r
=
[
dest
]
r
=
[
dest
]
i
=
dest
i
=
dest
while
(
True
):
while
(
True
):
if
(
i
==
source
):
if
(
i
==
source
):
break
break
r
.
insert
(
0
,
path
[
i
])
r
.
insert
(
0
,
path
[
i
])
i
=
path
[
i
]
i
=
path
[
i
]
return
r
return
r
def
get_max
(
dist
,
s
):
def
get_max
(
dist
,
s
):
max
=
-
math
.
inf
max
=
-
math
.
inf
n
=
s
n
=
s
for
i
in
range
(
len
(
dist
)):
for
i
in
range
(
len
(
dist
)):
if
(
i
!=
s
and
dist
[
i
]
!=
math
.
inf
and
dist
[
i
]
>=
max
):
if
(
i
!=
s
and
dist
[
i
]
!=
math
.
inf
and
dist
[
i
]
>=
max
):
max
=
dist
[
i
]
max
=
dist
[
i
]
n
=
i
n
=
i
if
(
max
==-
math
.
inf
):
if
(
max
==
-
math
.
inf
):
if
(
dist
[
s
]
!=
math
.
inf
and
dist
[
s
]
>=
max
):
if
(
dist
[
s
]
!=
math
.
inf
and
dist
[
s
]
>=
max
):
max
=
dist
[
s
]
max
=
dist
[
s
]
return
max
,
n
return
max
,
n
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
with
open
(
args
.
input_file
,
"
rb
"
)
as
input_file
:
with
open
(
args
.
input_file
,
"
rb
"
)
as
input_file
:
binary_data
=
input_file
.
read
()
binary_data
=
input_file
.
read
()
nb_nodes
,
nb_edges
=
get_file_infos
(
binary_data
[:
8
])
nb_nodes
,
nb_edges
=
get_file_infos
(
binary_data
[:
8
])
if
verbose
:
if
verbose
:
print
(
"
Number of nodes :
"
,
nb_nodes
,
"
, number of links :
"
,
nb_edges
)
print
(
"
Number of nodes :
"
,
nb_nodes
,
"
, number of links :
"
,
nb_edges
)
binary_data
=
binary_data
[
8
:]
binary_data
=
binary_data
[
8
:]
table
=
[]
table
=
[]
if
output_fd
==
sys
.
stdout
or
output_fd
==
sys
.
stderr
:
if
output_fd
==
sys
.
stdout
or
output_fd
==
sys
.
stderr
:
print
(
nb_nodes
)
print
(
nb_nodes
)
else
:
else
:
output_fd
.
write
(
nb_nodes
.
to_bytes
(
4
,
"
big
"
))
output_fd
.
write
(
nb_nodes
.
to_bytes
(
4
,
"
big
"
))
for
i
in
range
(
nb_edges
):
for
i
in
range
(
nb_edges
):
a
=
int
.
from_bytes
(
binary_data
[
i
*
16
:
i
*
16
+
4
],
"
big
"
,
signed
=
True
)
a
=
int
.
from_bytes
(
binary_data
[
i
*
12
:
i
*
12
+
4
],
"
big
"
,
signed
=
True
)
b
=
int
.
from_bytes
(
binary_data
[
i
*
16
+
4
:
i
*
16
+
8
],
"
big
"
,
signed
=
True
)
b
=
int
.
from_bytes
(
binary_data
[
i
*
12
+
4
:
i
*
12
+
8
],
"
big
"
,
signed
=
True
)
cab
=
int
.
from_bytes
(
binary_data
[
i
*
16
+
8
:
i
*
16
+
12
],
"
big
"
,
signed
=
True
)
cab
=
int
.
from_bytes
(
cba
=
int
.
from_bytes
(
binary_data
[
i
*
16
+
12
:
i
*
16
+
16
],
"
big
"
,
signed
=
True
)
binary_data
[
i
*
12
+
8
:
i
*
12
+
12
],
"
big
"
,
signed
=
True
)
if
(
cab
!=
0
):
l1
=
[
a
,
b
,
cab
]
l1
=
[
a
,
b
,
cab
]
table
.
append
(
l1
)
table
.
append
(
l1
)
if
(
cba
!=
0
):
l2
=
[
b
,
a
,
cba
]
table
.
append
(
l2
)
for
i
in
range
(
nb_nodes
):
for
i
in
range
(
nb_nodes
):
dist
,
path
=
bellman_ford
(
table
,
i
)
dist
,
path
=
bellman_ford
(
table
,
i
)
if
dist
==-
1
:
break
if
dist
==
-
1
:
continue
if
output_fd
==
sys
.
stdout
or
output_fd
==
sys
.
stderr
:
if
output_fd
==
sys
.
stdout
or
output_fd
==
sys
.
stderr
:
print
(
"
source :
"
+
str
(
i
))
print
(
"
source :
"
+
str
(
i
))
d
,
n
=
get_max
(
dist
,
i
)
d
,
n
=
get_max
(
dist
,
i
)
print
(
"
destination :
"
+
str
(
n
))
print
(
"
destination :
"
+
str
(
n
))
print
(
"
cout :
"
+
str
(
d
))
print
(
"
cout :
"
+
str
(
d
))
p
=
get_path
(
n
,
path
,
i
)
p
=
get_path
(
n
,
path
,
i
)
print
(
"
nombre de noeuds :
"
+
str
(
len
(
p
)))
print
(
"
nombre de noeuds :
"
+
str
(
len
(
p
)))
print
(
"
chemin :
"
+
"
"
.
join
(
str
(
x
)
for
x
in
p
))
print
(
"
chemin :
"
+
"
"
.
join
(
str
(
x
)
for
x
in
p
))
print
(
"
-----------------------
"
)
print
(
"
-----------------------
"
)
else
:
else
:
output_fd
.
write
(
i
.
to_bytes
(
4
,
"
big
"
))
output_fd
.
write
(
i
.
to_bytes
(
4
,
"
big
"
))
d
,
n
=
get_max
(
dist
,
i
)
d
,
n
=
get_max
(
dist
,
i
)
output_fd
.
write
(
n
.
to_bytes
(
4
,
"
big
"
,
signed
=
True
))
output_fd
.
write
(
d
.
to_bytes
(
4
,
"
big
"
,
signed
=
True
))
output_fd
.
write
(
d
.
to_bytes
(
4
,
"
big
"
,
signed
=
True
))
output_fd
.
write
(
n
.
to_bytes
(
4
,
"
big
"
))
r
=
get_path
(
n
,
path
,
i
)
r
=
get_path
(
n
,
path
,
i
)
output_fd
.
write
(
len
(
r
).
to_bytes
(
4
,
"
big
"
,
signed
=
True
))
output_fd
.
write
(
len
(
r
).
to_bytes
(
4
,
"
big
"
,
signed
=
True
))
for
j
in
range
(
len
(
r
))
:
for
j
in
range
(
len
(
r
))
:
output_fd
.
write
(
r
[
j
].
to_bytes
(
4
,
"
big
"
))
output_fd
.
write
(
r
[
j
].
to_bytes
(
4
,
"
big
"
))
\ No newline at end of file
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter