création de label marathon et presque fin de marathon

This commit is contained in:
Pellerin Tiphaine 2026-05-29 18:07:34 +02:00
parent 42cc651834
commit b798f06053
4 changed files with 48 additions and 4 deletions

View file

@ -0,0 +1,41 @@
package org.insa.graphs.algorithm.shortestpath;
import org.insa.graphs.model.Arc;
import org.insa.graphs.model.Node;
public class LabelMarathon extends Label implements Comparable<Label> {
protected double coutDest;
public LabelMarathon(Node s, Boolean m, double c, Arc p, double cd) {
super(s, m, c, p);
this.coutDest = cd;
}
public double getCoutDest() {
return this.coutDest;
}
@Override
public double getTotalCost() {
return this.coutDest + this.cout;
}
public double difMarathon (double d) {
return d - this.getTotalCost() ;
}
public int compareTo(LabelMarathon l) {
if (this.difMarathon (43)< l.difMarathon (43)) {
return -1;
}
else if (this.difMarathon (43)> l.difMarathon (43)) {
return 1;
}
else {
return 0;
}
}
}

View file

@ -16,15 +16,15 @@ public class Marathon extends ShortestPathAlgorithm {
super(data); super(data);
} }
public Label newLabelMarathon(Node s) { public Label newLabelMarathon(Node s, ShortestPathData dataPath) {
return new LabelMarathon(s, false, Double.MAX_VALUE, null); return new LabelMarathon(s, false, Integer.MAX_VALUE, null, s.getPoint().distanceTo(dataPath.getDestination().getPoint()));
} }
@Override @Override
public ShortestPathSolution doRun() { public ShortestPathSolution doRun() {
// retrieve data from the input problem (getInputData() is inherited from the // retrieve data from the input problem (getInputData() is inherited from the
// parent class ShortestPathAlgorithm) // parent class ShortestPathAlgorithm)@Override
final ShortestPathData dataInput = getInputData(); final ShortestPathData dataInput = getInputData();
Graph graph = dataInput.getGraph(); Graph graph = dataInput.getGraph();
final int nbNodes = graph.size(); final int nbNodes = graph.size();
@ -61,7 +61,7 @@ public class Marathon extends ShortestPathAlgorithm {
if (dataInput.isAllowed(a)) { if (dataInput.isAllowed(a)) {
Node n = a.getDestination(); Node n = a.getDestination();
if (listLabel[n.getId()] == null) { if (listLabel[n.getId()] == null) {
listLabel[n.getId()] = newLabelMarathon(n); listLabel[n.getId()] = newLabelMarathon(n, dataInput);
} }
if (!listLabel[n.getId()].getMarque()) { if (!listLabel[n.getId()].getMarque()) {
possible = true ; possible = true ;
@ -70,6 +70,9 @@ public class Marathon extends ShortestPathAlgorithm {
if ((!n.equals(dest)) && (listLabel[n.getId()].getCost()) < 43){ if ((!n.equals(dest)) && (listLabel[n.getId()].getCost()) < 43){
tas.insert(listLabel[n.getId()]) ; tas.insert(listLabel[n.getId()]) ;
} }
if ((n.equals(dest)) && (42<listLabel[n.getId()].getCost()) && (listLabel[n.getId()].getCost()< 43)){
fini = true ;
}
} }
} }
} }