From fc581c42bebc19be584c94d1b64fd7128c8dfd6b Mon Sep 17 00:00:00 2001 From: georgia Date: Tue, 2 May 2023 18:08:43 +0200 Subject: [PATCH] dijkstra --- .../algorithm/shortestpath/DijkstraAlgorithm.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 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 41be114..222297c 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 @@ -47,22 +47,22 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { for (Arc suc:x.getSommet().getSuccessors() ) { int index=suc.getDestination().getId(); if (!tab.get(index).getMarque()) { - if (tab.get(index).getCost()>x.getCost()+suc.getLength()) { + if (data.isAllowed(suc) && tab.get(index).getCost()>x.getCost()+suc.getLength()) { /*on vérifie si présent dans le tas ou pas en utilisant remove */ try { tas.remove(tab.get(index)); } catch (Exception e) { - System.out.println("l'élement n'est pas dans la tas"); + System.out.println("l'élement n'est pas dans le tas"); notifyNodeReached(tab.get(index).getSommet()); if(tab.get(index).getSommet().equals(data.getDestination())){ + // The destination has been found, notify the observers. 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)); - // The destination has been found, notify the observers. + tas.insert(tab.get(index)); } } @@ -74,8 +74,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { } else { - - ArrayList arcs = new ArrayList<>(); Arc arc = label_dest.getPere(); while (arc != null) {