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,16 +12,9 @@ import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
public class ArcInspectorFactory { public class ArcInspectorFactory {
/**
* @return List of all arc filters in this factory.
*/
public static List<ArcInspector> getAllFilters() {
List<ArcInspector> filters = new ArrayList<>();
// Common filters:
// No filter (all arcs allowed): // No filter (all arcs allowed):
filters.add(new ArcInspector() { static ArcInspector allArcsL = new ArcInspector() {
@Override @Override
public boolean isAllowed(Arc arc) { public boolean isAllowed(Arc arc) {
return true; return true;
@ -48,10 +41,11 @@ public class ArcInspectorFactory {
public String toString() { public String toString() {
return "Shortest path, all roads allowed"; return "Shortest path, all roads allowed";
} }
}); } ;
// Only road allowed for cars and length: // Only road allowed for cars and length:
filters.add(new ArcInspector() { static ArcInspector forCarsL = new ArcInspector() {
@Override @Override
public boolean isAllowed(Arc arc) { public boolean isAllowed(Arc arc) {
return arc.getRoadInformation().getAccessRestrictions() return arc.getRoadInformation().getAccessRestrictions()
@ -80,11 +74,11 @@ public class ArcInspectorFactory {
public String toString() { public String toString() {
return "Shortest path, only roads open for cars"; return "Shortest path, only roads open for cars";
} }
}); } ;
// Only road allowed for cars and time: // Only road allowed for cars and time:
static ArcInspector forCarsT = new ArcInspector() {
filters.add(new ArcInspector() {
@Override @Override
public boolean isAllowed(Arc arc) { public boolean isAllowed(Arc arc) {
return true; return true;
@ -111,41 +105,10 @@ public class ArcInspectorFactory {
public String toString() { public String toString() {
return "Fastest path, all roads allowed"; 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: // Non-private roads for pedestrian and bicycle:
filters.add(new ArcInspector() { static ArcInspector forBicyclesT = new ArcInspector() {
static final int maxPedestrianSpeed = 5 ; static final int maxPedestrianSpeed = 5 ;
@ -178,7 +141,21 @@ public class ArcInspectorFactory {
public Mode getMode() { public Mode getMode() {
return Mode.TIME; return Mode.TIME;
} }
}); } ;
/**
* @return List of all arc filters in this factory.
*/
public static List<ArcInspector> getAllFilters() {
List<ArcInspector> filters = new ArrayList<>();
// Common filters:
filters.add(allArcsL) ;
filters.add(forCarsL) ;
filters.add(forCarsT) ;
filters.add(forBicyclesT);
// Add your own filters here (do not forget to implement toString() // Add your own filters here (do not forget to implement toString()
// to get an understandable output!): // 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. // Number of elements in heap.
private int currentSize; private int currentSize;
// The heap array. // The heap array, which can be larger than currentSize.
protected final ArrayList<E> array; 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 // Draw arcs only if there are one-way arcs or if origin is lower than
// destination, avoid drawing two-ways arc twice. // destination, avoid drawing two-ways arc twice.
if (arc.getRoadInformation().isOneWay() if (arc.getRoadInformation().isOneWay()
|| arc.getOrigin().compareTo(arc.getDestination()) < 0) { || arc.getOrigin().getId() < arc.getDestination().getId()) {
drawArc(arc, palette, false); drawArc(arc, palette, false);
} }
} }

View File

@ -19,7 +19,7 @@ import java.util.List;
* </p> * </p>
* *
*/ */
public final class Node implements Comparable<Node> { public final class Node { //implements Comparable<Node> {
/** /**
* <p> * <p>
@ -144,6 +144,7 @@ public final class Node implements Comparable<Node> {
return false; 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. * 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) * @see java.lang.Comparable#compareTo(java.lang.Object)
*/ */
@Override // @Override
public int compareTo(Node other) { // public int compareTo(Node other) {
return Integer.compare(getId(), other.getId()); // return Integer.compare(getId(), other.getId());
} // }
} }