refactor(marathon): find next arc to remove to own function
This commit is contained in:
parent
26a662bb1b
commit
63da86ab0f
1 changed files with 26 additions and 14 deletions
|
@ -12,6 +12,8 @@ import org.insa.graphs.algorithm.shortestpath.ShortestPathSolution;
|
|||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
|
@ -42,26 +44,17 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
|
|||
DijkstraAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
||||
ShortestPathSolution path = dijkstra.run();
|
||||
|
||||
if (!path.isFeasible())
|
||||
return path;
|
||||
|
||||
while (path.getPath().getLength() < getDistance()) {
|
||||
// Recuperation indices
|
||||
// TODO : A MODIFIER POUR AMELIORER LA COHERENCE DU CHEMIN
|
||||
List<Arc> pathMax = path.getPath().getArcs();
|
||||
float max = 0;
|
||||
int indiceArcToRemove = 0; //Math.abs(rand.nextInt() % (longueurPath - 1));
|
||||
for (int i = 0; i < pathMax.size(); i++) {
|
||||
if (pathMax.get(i).getLength() > max) {
|
||||
max = pathMax.get(i).getLength();
|
||||
indiceArcToRemove = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Recuperation Arc à supprimer
|
||||
Arc arcToRemove = path.getPath().getArcs().get(indiceArcToRemove);
|
||||
Arc arcToRemove = getLongestArc(path.getPath());
|
||||
Node originArcToRemove = arcToRemove.getOrigin();
|
||||
Node destinationArcToRemove = arcToRemove.getDestination();
|
||||
|
||||
// On le supprime dans une copie du tableau (getter Collections.unmodifiable dans Path.java)
|
||||
path.getPath().getArcs().remove(indiceArcToRemove);
|
||||
path.getPath().getArcs().remove(arcToRemove);
|
||||
originArcToRemove.removeArc(arcToRemove);
|
||||
|
||||
// Creations du chemin entre les 2 noeuds dont l'arc a été supprimé
|
||||
|
@ -88,5 +81,24 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
|
|||
public static int getDistance() {
|
||||
return distanceMarathon;
|
||||
}
|
||||
|
||||
private Arc getLongestArc(Path path) {
|
||||
// TODO : A MODIFIER POUR AMELIORER LA COHERENCE DU CHEMIN
|
||||
final List<Arc> arcs = path.getArcs();
|
||||
// we checked that the path is feasible in run
|
||||
// so there should be at least one Arc (unless start = destination ?)
|
||||
if (arcs.size() == 0)
|
||||
return null;
|
||||
|
||||
Arc longestArc = arcs.get(0);
|
||||
for (Arc arc : arcs) {
|
||||
if (arc.getLength() > longestArc.getLength()) {
|
||||
longestArc = arc;
|
||||
}
|
||||
}
|
||||
|
||||
return longestArc;
|
||||
//int indiceArcToRemove = 0; //Math.abs(rand.nextInt() % (longueurPath - 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue