Nodes are no longer comparable (confusion with Label comparison). Predefined ArcInspectors easier to get.

This commit is contained in:
Le Botlan Didier 2024-03-22 17:07:18 +01:00
parent 723b8ce660
commit 32f99dba49
4 changed files with 144 additions and 166 deletions

View File

@ -12,6 +12,137 @@ import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
public class ArcInspectorFactory {
// No filter (all arcs allowed):
static ArcInspector allArcsL = new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, all roads allowed";
}
} ;
// Only road allowed for cars and length:
static ArcInspector forCarsL = new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, only roads open for cars";
}
} ;
// Only road allowed for cars and time:
static ArcInspector forCarsT = new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime() ;
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.TIME ;
}
@Override
public String toString() {
return "Fastest path, all roads allowed";
}
} ;
// Non-private roads for pedestrian and bicycle:
static ArcInspector forBicyclesT = new ArcInspector() {
static final int maxPedestrianSpeed = 5 ;
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getTravelTime(
Math.min(maxPedestrianSpeed, arc.getRoadInformation().getMaximumSpeed()));
}
@Override
public String toString() {
return "Fastest path for pedestrian";
}
/*
@Override
public int getMaximumSpeed() {
return 5;
}
*/
@Override
public Mode getMode() {
return Mode.TIME;
}
} ;
/**
* @return List of all arc filters in this factory.
*/
@ -20,165 +151,11 @@ public class ArcInspectorFactory {
// Common filters:
// No filter (all arcs allowed):
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, all roads allowed";
}
});
// Only road allowed for cars and length:
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getLength();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.LENGTH;
}
@Override
public String toString() {
return "Shortest path, only roads open for cars";
}
});
// Only road allowed for cars and time:
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return true;
}
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.TIME;
}
@Override
public String toString() {
return "Fastest path, all roads allowed";
}
});
filters.add(new ArcInspector() {
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getMinimumTravelTime();
}
/*
@Override
public int getMaximumSpeed() {
return GraphStatistics.NO_MAXIMUM_SPEED;
}
*/
@Override
public Mode getMode() {
return Mode.TIME;
}
@Override
public String toString() {
return "Fastest path, only roads open for cars";
}
});
// Non-private roads for pedestrian and bicycle:
filters.add(new ArcInspector() {
static final int maxPedestrianSpeed = 5 ;
@Override
public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions()
.isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
}
@Override
public double getCost(Arc arc) {
return arc.getTravelTime(
Math.min(maxPedestrianSpeed, arc.getRoadInformation().getMaximumSpeed()));
}
@Override
public String toString() {
return "Fastest path for pedestrian";
}
/*
@Override
public int getMaximumSpeed() {
return 5;
}
*/
@Override
public Mode getMode() {
return Mode.TIME;
}
});
filters.add(allArcsL) ;
filters.add(forCarsL) ;
filters.add(forCarsT) ;
filters.add(forBicyclesT);
// Add your own filters here (do not forget to implement toString()
// to get an understandable output!):

View File

@ -16,7 +16,7 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
// Number of elements in heap.
private int currentSize;
// The heap array.
// The heap array, which can be larger than currentSize.
protected final ArrayList<E> array;
/**

View File

@ -684,7 +684,7 @@ public class BasicDrawing extends JPanel implements Drawing {
// Draw arcs only if there are one-way arcs or if origin is lower than
// destination, avoid drawing two-ways arc twice.
if (arc.getRoadInformation().isOneWay()
|| arc.getOrigin().compareTo(arc.getDestination()) < 0) {
|| arc.getOrigin().getId() < arc.getDestination().getId()) {
drawArc(arc, palette, false);
}
}

View File

@ -19,7 +19,7 @@ import java.util.List;
* </p>
*
*/
public final class Node implements Comparable<Node> {
public final class Node { //implements Comparable<Node> {
/**
* <p>
@ -144,6 +144,7 @@ public final class Node implements Comparable<Node> {
return false;
}
// Do we really need to compare nodes ? Confusion with Label comparisons.
/**
* Compare the ID of this node with the ID of the given node.
*
@ -151,9 +152,9 @@ public final class Node implements Comparable<Node> {
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Node other) {
return Integer.compare(getId(), other.getId());
}
// @Override
// public int compareTo(Node other) {
// return Integer.compare(getId(), other.getId());
// }
}