feat(marathon): display path-finding on gui
This commit is contained in:
parent
d6f469e32f
commit
0dbe233d75
5 changed files with 37 additions and 1 deletions
|
@ -62,9 +62,11 @@ public class MarathonAlgorithm extends ShortestPathAlgorithm {
|
|||
if (newPath != null) {
|
||||
// Ajout du path trouvé à l'indice où on l'a enlevé
|
||||
path.replaceArc(arcToRemove, newPath.getArcs());
|
||||
// display path
|
||||
notifyMarathonPathUpdated(path, newPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return solution;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
|
||||
import org.insa.graphs.algorithm.AbstractAlgorithm;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPathObserver> {
|
||||
|
||||
|
@ -69,6 +70,17 @@ public abstract class ShortestPathAlgorithm extends AbstractAlgorithm<ShortestPa
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the observer that the path has been updated.
|
||||
*
|
||||
* @param path Path that has been updated.
|
||||
*/
|
||||
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
|
||||
for (ShortestPathObserver obs: getObservers()) {
|
||||
obs.notifyMarathonPathUpdated(path, newSegment);
|
||||
}
|
||||
}
|
||||
|
||||
public double getCostPath() {
|
||||
return this.pathCost;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.insa.graphs.algorithm.shortestpath;
|
||||
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
public interface ShortestPathObserver {
|
||||
|
||||
|
@ -33,5 +34,12 @@ public interface ShortestPathObserver {
|
|||
* @param node Destination.
|
||||
*/
|
||||
public void notifyDestinationReached(Node node);
|
||||
|
||||
/**
|
||||
* Notify the observer that the path has been updated.
|
||||
*
|
||||
* @param path Path that has been updated.
|
||||
*/
|
||||
public void notifyMarathonPathUpdated(Path path, Path newSegment);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
|||
import java.io.PrintStream;
|
||||
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
public class ShortestPathTextObserver implements ShortestPathObserver {
|
||||
|
||||
|
@ -34,4 +35,9 @@ public class ShortestPathTextObserver implements ShortestPathObserver {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
|
||||
// noop
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.insa.graphs.algorithm.shortestpath.ShortestPathObserver;
|
|||
import org.insa.graphs.gui.drawing.Drawing;
|
||||
import org.insa.graphs.gui.drawing.overlays.PointSetOverlay;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
|
||||
public class ShortestPathGraphicObserver implements ShortestPathObserver {
|
||||
|
||||
|
@ -39,4 +40,11 @@ public class ShortestPathGraphicObserver implements ShortestPathObserver {
|
|||
// drawing.drawMarker(node.getPoint(), Color.RED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyMarathonPathUpdated(Path path, Path newSegment) {
|
||||
drawing.clearOverlays();
|
||||
drawing.drawPath(path, Color.BLUE, true);
|
||||
drawing.drawPath(newSegment, Color.RED, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue