From ce9743650bf5a72ea76fb7c06cfa70d7d4e308ab Mon Sep 17 00:00:00 2001 From: Raph Date: Wed, 12 Apr 2023 17:13:04 +0200 Subject: [PATCH] observer dijkstra --- .../algorithm/shortestpath/DijkstraAlgorithm.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java index f5208d7..ed37cd5 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java @@ -34,10 +34,12 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { Label label_dest =tab.get(data.getDestination().getId()); /*insertion de label origine dans le tas */ tas.insert(label_origine); + notifyOriginProcessed(label_origine.getSommet()); Label x; while (label_dest.getMarque()==false && tas.isEmpty()==false) { x=tas.deleteMin(); x.setMarque(true); + notifyNodeMarked(x.getSommet()); for (Arc suc:x.getSommet().getSuccessors() ) { int index=suc.getDestination().getId(); if (!tab.get(index).getMarque()) { @@ -47,11 +49,16 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { tas.remove(tab.get(index)); } catch (Exception e) { System.out.println("l'élement n'est pas dans la tas"); + notifyNodeReached(tab.get(index).getSommet()); + if(tab.get(index).getSommet().equals(data.getDestination())){ + notifyDestinationReached(tab.get(index).getSommet()); + } } tab.get(index).setCoutmin(x.getCost()+suc.getLength()); tab.get(index).setPere(suc); /*insertion dans le tas */ - tas.insert(tab.get(index)); + tas.insert(tab.get(index)); + // The destination has been found, notify the observers. } } @@ -63,8 +70,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { } else { - // The destination has been found, notify the observers. - notifyDestinationReached(data.getDestination()); + ArrayList arcs = new ArrayList<>(); Arc arc = label_dest.getPere();