Newer
Older
parser = argparse.ArgumentParser(
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("-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()
verbose = args.v
output_fd = args.f
nb_nodes = None
nb_edges = None
if verbose:
print(args, file=sys.stderr)
nb_nodes = int.from_bytes(data[0:4], "big", signed=True)
nb_edges = int.from_bytes(data[4:], "big", signed=True)
return nb_nodes, nb_edges
path = [-1]*nb_nodes
for _ in range(nb_nodes-1):
for j in range(len(table)):
a, b, cab = table[j][0], table[j][1], table[j][2]
if (dist[a] != math.inf and dist[b] > dist[a]+cab):
dist[b] = dist[a]+cab
path[b] = a
a, b, cab = table[j][0], table[j][1], table[j][2]
if (dist[a] != math.inf and dist[b] > dist[a]+cab):
print("Cycle négatif détecté")
dist = [math.inf] * nb_nodes
dist[s] = 0
path = [-1] * nb_nodes
n = i
if (max == -math.inf):
if (dist[s] != math.inf and dist[s] >= max):
with open(args.input_file, "rb") as input_file:
binary_data = input_file.read()
nb_nodes, nb_edges = get_file_infos(binary_data[:8])
if verbose:
print("Number of nodes :", nb_nodes,
", number of links :", nb_edges)
binary_data = binary_data[8:]
table = []
if output_fd == sys.stdout or output_fd == sys.stderr:
print(nb_nodes)
output_fd.write(nb_nodes.to_bytes(4, "big"))
for i in range(nb_edges):
a = int.from_bytes(binary_data[i*12:i*12+4], "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*12+8:i*12+12], "big", signed=True)
l1 = [a, b, cab]
table.append(l1)
continue # TODO: if there is no shortest path (negative cycle or empty path), put a 0 value instead of not showing it at all
if output_fd == sys.stdout or output_fd == sys.stderr:
print("source : "+str(i))
d, n = get_max(dist, i)
print("destination : " + str(n))
print("cout : " + str(d))
p = get_path(n, path, i)
print("nombre de noeuds : "+str(len(p)))
print("chemin : "+" ".join(str(x) for x in p))
print("-----------------------")
d, n = get_max(dist, i)
output_fd.write(d.to_bytes(4, "big", signed=True))
output_fd.write(n.to_bytes(4, "big"))
r = get_path(n, path, i)
output_fd.write(len(r).to_bytes(4, "big", signed=True))
for j in range(len(r)):