Classe Path complétée
This commit is contained in:
parent
1ffafeaef8
commit
348c250ac7
1 changed files with 106 additions and 23 deletions
|
@ -29,13 +29,47 @@ public class Path {
|
||||||
*
|
*
|
||||||
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
||||||
* consecutive nodes in the list are not connected in the graph.
|
* 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)
|
public static Path createFastestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
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>();
|
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);
|
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
|
* @throws IllegalArgumentException If the list of nodes is not valid, i.e. two
|
||||||
* consecutive nodes in the list are not connected in the graph.
|
* 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)
|
public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes)
|
||||||
throws IllegalArgumentException {
|
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>();
|
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);
|
return new Path(graph, arcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,24 +264,42 @@ public class Path {
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @return true if the path is valid, false otherwise.
|
* @return true if the path is valid, false otherwise.
|
||||||
*
|
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public boolean isValid() {
|
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;
|
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).
|
* Compute the length of this path (in meters).
|
||||||
*
|
*
|
||||||
* @return Total length of the path (in meters).
|
* @return Total length of the path (in meters).
|
||||||
*
|
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public float getLength() {
|
public float getLength() {
|
||||||
// TODO:
|
float res = 0.0f;
|
||||||
return 0;
|
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
|
* @return Time (in seconds) required to travel this path at the given speed (in
|
||||||
* kilometers-per-hour).
|
* kilometers-per-hour).
|
||||||
*
|
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public double getTravelTime(double speed) {
|
public double getTravelTime(double speed) {
|
||||||
// TODO:
|
return this.getLength()/(speed/3.6f);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,12 +319,13 @@ public class Path {
|
||||||
* on every arc.
|
* on every arc.
|
||||||
*
|
*
|
||||||
* @return Minimum travel time to travel this path (in seconds).
|
* @return Minimum travel time to travel this path (in seconds).
|
||||||
*
|
|
||||||
* @deprecated Need to be implemented.
|
|
||||||
*/
|
*/
|
||||||
public double getMinimumTravelTime() {
|
public double getMinimumTravelTime() {
|
||||||
// TODO:
|
double res = 0.0f;
|
||||||
return 0;
|
for(Arc a : this.arcs) {
|
||||||
|
res+= a.getMinimumTravelTime();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue