feat(marathon): use marathonArcInspector

This commit is contained in:
Paul Alnet 2024-05-25 17:29:19 +02:00
parent b7012ee892
commit 7cc3c39211

View file

@ -2,6 +2,7 @@ package org.insa.graphs.algorithm.marathon;
import java.util.List; import java.util.List;
import org.insa.graphs.algorithm.AbstractSolution.Status;
import org.insa.graphs.algorithm.ArcInspector; import org.insa.graphs.algorithm.ArcInspector;
import org.insa.graphs.algorithm.ArcInspectorFactory; import org.insa.graphs.algorithm.ArcInspectorFactory;
import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm; import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
@ -53,18 +54,17 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
final Node originArcToRemove = arcToRemove.getOrigin(); final Node originArcToRemove = arcToRemove.getOrigin();
final Node destinationArcToRemove = arcToRemove.getDestination(); final Node destinationArcToRemove = arcToRemove.getDestination();
path.getArcs().remove(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é
final ArcInspector arcInspector = ArcInspectorFactory.getAllFilters().get(0); final ArcInspector arcInspector = new MarathonArcInspector(path, arcToRemove); // filters out cycles and current arc
final ShortestPathData newData = new ShortestPathData(graph, originArcToRemove, destinationArcToRemove, arcInspector); final ShortestPathData newData = new ShortestPathData(graph, originArcToRemove, destinationArcToRemove, arcInspector);
Path newPath = (new DijkstraAlgorithm(newData)).run().getPath(); final Path newPath = (new DijkstraAlgorithm(newData)).run().getPath();
// could get stuck in a loop if no path is found, given the current arcToRemove strategy // could get stuck in a loop if no path is found, given the current arcToRemove strategy
if (newPath != null) { 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.getArcs()); path.getArcs().addAll(newPath.getArcs());
path.replaceArc(arcToRemove, newPath.getArcs());
} }
} }
@ -95,8 +95,9 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
longestArc = arc; longestArc = arc;
} }
} }
return arcs.get(Math.abs(rand.nextInt() % (arcs.size())));
return longestArc; //return longestArc;
//int indiceArcToRemove = 0; //Math.abs(rand.nextInt() % (longueurPath - 1)); //int indiceArcToRemove = 0; //Math.abs(rand.nextInt() % (longueurPath - 1));
} }
} }