Classe Path complétée

This commit is contained in:
Cavailles Kevin 2020-03-20 18:30:23 +01:00
parent 1ffafeaef8
commit 348c250ac7

View file

@ -29,13 +29,47 @@ public class Path {
*
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph.
*
* @deprecated Need to be implemented.
*/
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {
Arc currentArc = null;
for(int i=0; i<nodes.size()-1;i++) {
for(Arc a : nodes.get(i).getSuccessors()) {
if(a.getDestination().equals(nodes.get(i+1)) ) {
currentArc = a;
}
}
if(currentArc == null) {
throw new IllegalArgumentException();
}
currentArc = null;
}
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
double travelTime = 9999;
if(nodes.size() == 0) {
return new Path(graph);
}
if(nodes.size() == 1) {
return new Path(graph, nodes.get(0) );
}
for(int i=0; i<nodes.size()-1;i++) {
for(Arc a : nodes.get(i).getSuccessors()) {
if(a.getMinimumTravelTime() < travelTime
&& a.getDestination().equals(nodes.get(i+1)) ) {
currentArc = a;
travelTime = a.getMinimumTravelTime();
}
}
arcs.add(currentArc);
travelTime = 9999;
}
return new Path(graph, arcs);
}
@ -50,13 +84,46 @@ public class Path {
*
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
* consecutive nodes in the list are not connected in the graph.
*
* @deprecated Need to be implemented.
*/
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
throws IllegalArgumentException {
Arc currentArc = null;
for(int i=0; i<nodes.size()-1;i++) {
for(Arc a : nodes.get(i).getSuccessors()) {
if(a.getDestination().equals(nodes.get(i+1)) ) {
currentArc = a;
}
}
if(currentArc == null) {
throw new IllegalArgumentException();
}
currentArc = null;
}
List<Arc> arcs = new ArrayList<Arc>();
// TODO:
float distanceMin = 9999;
if(nodes.size() == 0) {
return new Path(graph);
}
if(nodes.size() == 1) {
return new Path(graph, nodes.get(0) );
}
for(int i=0; i<nodes.size()-1;i++) {
for(Arc a : nodes.get(i).getSuccessors()) {
if(a.getLength() < distanceMin
&& a.getDestination().equals(nodes.get(i+1)) ) {
currentArc = a;
distanceMin = a.getLength();
}
}
arcs.add(currentArc);
distanceMin = 9999;
}
return new Path(graph, arcs);
}
@ -197,24 +264,42 @@ public class Path {
* </ul>
*
* @return true if the path is valid, false otherwise.
*
* @deprecated Need to be implemented.
*/
public boolean isValid() {
// TODO:
if(this.isEmpty()) {
return true;
}
if(this.origin != null && this.arcs.isEmpty()) {
return true;
}
if(!this.arcs.get(0).getOrigin().equals(this.getOrigin()) ) {
return false;
}
if(!this.arcs.get(this.arcs.size() -1 ).getDestination().equals(this.getDestination()) ) {
return false;
}
for(int i=0;i<this.arcs.size()-1; i++) {
if(!this.arcs.get(i).getDestination().equals(this.arcs.get(i+1).getOrigin()) ) {
return false;
}
}
return true;
}
/**
* Compute the length of this path (in meters).
*
* @return Total length of the path (in meters).
*
* @deprecated Need to be implemented.
*/
public float getLength() {
// TODO:
return 0;
float res = 0.0f;
for(Arc a : this.arcs) {
res+= a.getLength();
}
return res;
}
/**
@ -224,12 +309,9 @@ public class Path {
*
* @return Time (in seconds) required to travel this path at the given speed (in
* kilometers-per-hour).
*
* @deprecated Need to be implemented.
*/
public double getTravelTime(double speed) {
// TODO:
return 0;
return this.getLength()/(speed/3.6f);
}
/**
@ -237,12 +319,13 @@ public class Path {
* on every arc.
*
* @return Minimum travel time to travel this path (in seconds).
*
* @deprecated Need to be implemented.
*/
public double getMinimumTravelTime() {
// TODO:
return 0;
double res = 0.0f;
for(Arc a : this.arcs) {
res+= a.getMinimumTravelTime();
}
return res;
}
}