implémentation de label + debut Djikstra

This commit is contained in:
Benmouffok Helwen 2026-05-13 18:12:04 +02:00
parent e24134bf5e
commit 857b0215f4
3 changed files with 92 additions and 5 deletions

View file

@ -1,5 +1,9 @@
package org.insa.graphs.algorithm.shortestpath; package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.algorithm.utils.BinaryHeap;
import org.insa.graphs.model.Graph;
import org.insa.graphs.model.Node;
public class DijkstraAlgorithm extends ShortestPathAlgorithm { public class DijkstraAlgorithm extends ShortestPathAlgorithm {
public DijkstraAlgorithm(ShortestPathData data) { public DijkstraAlgorithm(ShortestPathData data) {
@ -16,6 +20,35 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// variable that will contain the solution of the shortest path problem // variable that will contain the solution of the shortest path problem
ShortestPathSolution solution = null; ShortestPathSolution solution = null;
Graph graph = data.getGraph();
final int nbNodes = graph.size();
//Remplir le tableau
Label[] labels=new Label[nbNodes];
for (Node node:graph.getNodes()){
labels[node.getId()]=new Label(node);
BinaryHeap<Label> tas=new BinaryHeap<>();
}
// TODO: implement the Dijkstra algorithm // TODO: implement the Dijkstra algorithm
// when the algorithm terminates, return the solution that has been found // when the algorithm terminates, return the solution that has been found

View file

@ -0,0 +1,56 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Arc;
import org.insa.graphs.model.Node;
public class Label implements Comparable<Label>{
private Node sommetCourant;
private boolean marque;
private double coutRealise;
private Arc pere;
public Label(Node sommetCourant) {
this.sommetCourant=sommetCourant;
this.marque=false;
this.coutRealise=0;
this.pere=null;
}
public Node getSommetCourant(){
return this.sommetCourant;
}
public boolean isMarque(){
return this.marque;
}
public double getCoutRealise(){
return this.coutRealise;
}
public Arc getPere(){
return this.pere;
}
public void setMarque(){
this.marque=true;
}
public void setCoutRealise(double coutRealise){
this.coutRealise=coutRealise;
}
public void setPere(Arc pere){
this.pere=pere;
}
public double getCost(){
return this.coutRealise;
}
@Override
public int compareTo(Label other){
return Double.compare(this.getCost(), other.getCost());
}
}

View file

@ -233,19 +233,17 @@ public class Path {
* @deprecated Need to be implemented. * @deprecated Need to be implemented.
*/ */
public boolean isValid() { public boolean isValid() {
// Cas 1 : chemin vide
if (this.isEmpty()) { if (this.isEmpty()) {
return true; return true;
} }
// Cas 2 : nœud unique, pas d'arcs
if (this.arcs.isEmpty()) { if (this.arcs.isEmpty()) {
return true; return true;
} }
// Cas 3 : le premier arc doit partir de l'origine if (!this.arcs.get(0).getOrigin().equals(this.origin)) {
if (!this.arcs.get(0).getOrigin().equals(this.origin)) {
return false; return false;
} }
// Cas 4 : chaque arc doit enchaîner sur le suivant
for (int i = 0; i < this.arcs.size() - 1; i++) { for (int i = 0; i < this.arcs.size() - 1; i++) {
if (!this.arcs.get(i).getDestination().equals(this.arcs.get(i + 1).getOrigin())) { if (!this.arcs.get(i).getDestination().equals(this.arcs.get(i + 1).getOrigin())) {
return false; return false;