refactor(marathon): make constant references as final

This commit is contained in:
Paul Alnet 2024-05-25 15:38:14 +02:00
parent de340c65dd
commit f45f0027f0

View file

@ -47,25 +47,24 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
if (!solution.isFeasible()) if (!solution.isFeasible())
return solution; return solution;
while (path.getLength() < getDistance()) { while (path.getLength() < distanceMarathon) {
// Recuperation Arc à supprimer // Recuperation Arc à supprimer (cacher) et extremites
Arc arcToRemove = getLongestArc(path); final Arc arcToRemove = getLongestArc(path);
Node originArcToRemove = arcToRemove.getOrigin(); final Node originArcToRemove = arcToRemove.getOrigin();
Node destinationArcToRemove = arcToRemove.getDestination(); final Node destinationArcToRemove = arcToRemove.getDestination();
// On le supprime dans une copie du tableau (getter Collections.unmodifiable dans Path.java)
path.getArcs().remove(arcToRemove); path.getArcs().remove(arcToRemove);
originArcToRemove.removeArc(arcToRemove); originArcToRemove.removeArc(arcToRemove); // TODO and similar ?
// Creations du chemin entre les 2 noeuds dont l'arc a été supprimé // Creations du chemin entre les 2 noeuds dont l'arc a été supprimé
ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0); final ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0);
ShortestPathData newData = new ShortestPathData(graph, originArcToRemove, destinationArcToRemove, arcInspector); final ShortestPathData newData = new ShortestPathData(graph, originArcToRemove, destinationArcToRemove, arcInspector);
DijkstraAlgorithm newDijkstra = new DijkstraAlgorithm(newData); Path newPath = (new DijkstraAlgorithm(newData)).run().getPath();
ShortestPathSolution newPath = newDijkstra.run();
if (newPath.getPath() != null) { // could get stuck in a loop if no path is found, given the current arcToRemove strategy
if (newPath != null) {
// Ajout du path trouvé à l'indice on l'a enlevé // Ajout du path trouvé à l'indice on l'a enlevé
path.getArcs().addAll(newPath.getPath().getArcs()); path.getArcs().addAll(newPath.getArcs());
} }
} }