Merge new-length.
This commit is contained in:
commit
440dc48c6a
@ -20,7 +20,7 @@ public abstract class AbstractInputData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtering inteface for arcs - This class can be used to indicate to an
|
||||
* Filtering interface for arcs - This class can be used to indicate to an
|
||||
* algorithm which arc can be used.
|
||||
*
|
||||
*/
|
||||
|
@ -31,7 +31,7 @@ public interface Arc {
|
||||
/**
|
||||
* @return Length of this arc, in meters.
|
||||
*/
|
||||
public int getLength();
|
||||
public float getLength();
|
||||
|
||||
/**
|
||||
* @return Minimum time required to travel this arc, in seconds.
|
||||
|
@ -37,7 +37,7 @@ class ArcBackward implements Arc {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
public float getLength() {
|
||||
return this.originalArc.getLength();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class ArcForward implements Arc {
|
||||
private final Node origin, destination;
|
||||
|
||||
// Length of the road (in meters).
|
||||
private final int length;
|
||||
private final float length;
|
||||
|
||||
// Road information.
|
||||
private final RoadInformation info;
|
||||
@ -32,7 +32,7 @@ class ArcForward implements Arc {
|
||||
* @param roadInformation Road information for this arc.
|
||||
* @param points Points representing this arc.
|
||||
*/
|
||||
protected ArcForward(Node origin, Node dest, int length, RoadInformation roadInformation,
|
||||
protected ArcForward(Node origin, Node dest, float length, RoadInformation roadInformation,
|
||||
ArrayList<Point> points) {
|
||||
this.origin = origin;
|
||||
this.destination = dest;
|
||||
@ -52,7 +52,7 @@ class ArcForward implements Arc {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLength() {
|
||||
public float getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class GraphStatistics {
|
||||
private final int maximumSpeed;
|
||||
|
||||
// Maximum length of any arc on this graph.
|
||||
private final int maximumLength;
|
||||
private final float maximumLength;
|
||||
|
||||
/**
|
||||
* Create a new GraphStatistics instance with the given value.
|
||||
@ -23,7 +23,7 @@ public class GraphStatistics {
|
||||
* be used to indicate that this graph has no maximum limitation.
|
||||
* @param maximumLength Maximum length of any arc of the graph.
|
||||
*/
|
||||
public GraphStatistics(int maximumSpeed, int maximumLength) {
|
||||
public GraphStatistics(int maximumSpeed, float maximumLength) {
|
||||
this.maximumLength = maximumLength;
|
||||
this.maximumSpeed = maximumSpeed;
|
||||
}
|
||||
@ -39,7 +39,7 @@ public class GraphStatistics {
|
||||
/**
|
||||
* @return Maximum length of any arc in the graph.
|
||||
*/
|
||||
public int getMaximumLength() {
|
||||
public float getMaximumLength() {
|
||||
return this.maximumLength;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class Node implements Comparable<Node> {
|
||||
*
|
||||
* @return The newly created forward arc (origin to destination).
|
||||
*/
|
||||
public static Arc linkNodes(Node origin, Node destination, int length,
|
||||
public static Arc linkNodes(Node origin, Node destination, float length,
|
||||
RoadInformation roadInformation, ArrayList<Point> points) {
|
||||
ArcForward arc = new ArcForward(origin, destination, length, roadInformation, points);
|
||||
origin.addSuccessor(arc);
|
||||
@ -95,6 +95,9 @@ public class Node implements Comparable<Node> {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null) {
|
||||
return false;
|
||||
}
|
||||
if (other instanceof Node) {
|
||||
return getId() == ((Node) other).getId();
|
||||
}
|
||||
|
@ -212,7 +212,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
checkByteOrThrow(254);
|
||||
|
||||
// Read successors and convert to arcs.
|
||||
int maxLength = 0;
|
||||
float maxLength = 0;
|
||||
final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
|
||||
observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
|
||||
for (int node = 0; node < nbNodes; ++node) {
|
||||
@ -225,7 +225,13 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||
int descrNum = this.read24bits();
|
||||
|
||||
// Length of the arc.
|
||||
int length = dis.readUnsignedShort();
|
||||
float length;
|
||||
if (getCurrentVersion() < 8) {
|
||||
length = dis.readUnsignedShort();
|
||||
}
|
||||
else {
|
||||
length = dis.readInt() / 1000.0f;
|
||||
}
|
||||
maxLength = Math.max(length, maxLength);
|
||||
|
||||
// Number of segments.
|
||||
|
@ -126,9 +126,9 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
|
||||
String info = "";
|
||||
|
||||
// Display length
|
||||
int length = path.getLength();
|
||||
float length = path.getLength();
|
||||
if (length < 2000) {
|
||||
info += String.format("Length = %d meters", length);
|
||||
info += String.format("Length = %.1f meters", length);
|
||||
}
|
||||
else {
|
||||
info += String.format("Length = %.3f kilometers", length / 1000.);
|
||||
|
@ -22,7 +22,7 @@ public class PathTest {
|
||||
|
||||
// List of arcs in the graph, a2b is the arc from node A (0) to B (1).
|
||||
@SuppressWarnings("unused")
|
||||
private static ArcForward a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
|
||||
private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
|
||||
|
||||
// Some paths...
|
||||
private static Path emptyPath, shortPath, longPath, loopPath, longLoopPath, invalidPath;
|
||||
@ -41,26 +41,26 @@ public class PathTest {
|
||||
}
|
||||
|
||||
// Add arcs...
|
||||
a2b = new ArcForward(nodes[0], nodes[1], 10, speed10, null);
|
||||
a2c = new ArcForward(nodes[0], nodes[2], 15, speed10, null);
|
||||
a2e = new ArcForward(nodes[0], nodes[4], 15, speed20, null);
|
||||
b2c = new ArcForward(nodes[1], nodes[2], 10, speed10, null);
|
||||
c2d_1 = new ArcForward(nodes[2], nodes[3], 20, speed10, null);
|
||||
c2d_2 = new ArcForward(nodes[2], nodes[3], 10, speed10, null);
|
||||
c2d_3 = new ArcForward(nodes[2], nodes[3], 15, speed20, null);
|
||||
d2a = new ArcForward(nodes[3], nodes[0], 15, speed10, null);
|
||||
d2e = new ArcForward(nodes[3], nodes[4], 20, speed20, null);
|
||||
e2d = new ArcForward(nodes[4], nodes[0], 10, speed10, null);
|
||||
a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
|
||||
a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null);
|
||||
a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null);
|
||||
b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null);
|
||||
c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null);
|
||||
c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null);
|
||||
c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null);
|
||||
d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null);
|
||||
d2e = Node.linkNodes(nodes[3], nodes[4], 20, speed20, null);
|
||||
e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null);
|
||||
|
||||
graph = new Graph("ID", "", Arrays.asList(nodes), null);
|
||||
|
||||
emptyPath = new Path(graph, new ArrayList<Arc>());
|
||||
shortPath = new Path(graph, Arrays.asList(new ArcForward[]{ a2b, b2c, c2d_1 }));
|
||||
longPath = new Path(graph, Arrays.asList(new ArcForward[]{ a2b, b2c, c2d_1, d2e }));
|
||||
loopPath = new Path(graph, Arrays.asList(new ArcForward[]{ a2b, b2c, c2d_1, d2a }));
|
||||
shortPath = new Path(graph, Arrays.asList(new Arc[]{ a2b, b2c, c2d_1 }));
|
||||
longPath = new Path(graph, Arrays.asList(new Arc[]{ a2b, b2c, c2d_1, d2e }));
|
||||
loopPath = new Path(graph, Arrays.asList(new Arc[]{ a2b, b2c, c2d_1, d2a }));
|
||||
longLoopPath = new Path(graph,
|
||||
Arrays.asList(new ArcForward[]{ a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
||||
invalidPath = new Path(graph, Arrays.asList(new ArcForward[]{ a2b, c2d_1, d2e }));
|
||||
Arrays.asList(new Arc[]{ a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
||||
invalidPath = new Path(graph, Arrays.asList(new Arc[]{ a2b, c2d_1, d2e }));
|
||||
|
||||
}
|
||||
|
||||
@ -103,11 +103,11 @@ public class PathTest {
|
||||
|
||||
@Test
|
||||
public void testGetLength() {
|
||||
assertEquals(emptyPath.getLength(), 0);
|
||||
assertEquals(shortPath.getLength(), 40);
|
||||
assertEquals(longPath.getLength(), 60);
|
||||
assertEquals(loopPath.getLength(), 55);
|
||||
assertEquals(longLoopPath.getLength(), 120);
|
||||
assertEquals(emptyPath.getLength(), 0, 1e-6);
|
||||
assertEquals(shortPath.getLength(), 40, 1e-6);
|
||||
assertEquals(longPath.getLength(), 60, 1e-6);
|
||||
assertEquals(loopPath.getLength(), 55, 1e-6);
|
||||
assertEquals(longLoopPath.getLength(), 120, 1e-6);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -122,12 +122,12 @@ public class PathTest {
|
||||
@Test
|
||||
public void testCreateFastestPathFromNodes() {
|
||||
Path path;
|
||||
ArcForward[] expected;
|
||||
Arc[] expected;
|
||||
|
||||
// Simple construction
|
||||
path = Path.createFastestPathFromNodes(graph,
|
||||
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2] }));
|
||||
expected = new ArcForward[]{ a2b, b2c };
|
||||
expected = new Arc[]{ a2b, b2c };
|
||||
assertEquals(expected.length, path.getArcs().size());
|
||||
for (int i = 0; i < expected.length; ++i) {
|
||||
assertEquals(expected[i], path.getArcs().get(i));
|
||||
@ -136,7 +136,7 @@ public class PathTest {
|
||||
// Not so simple construction
|
||||
path = Path.createFastestPathFromNodes(graph,
|
||||
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2], nodes[3] }));
|
||||
expected = new ArcForward[]{ a2b, b2c, c2d_3 };
|
||||
expected = new Arc[]{ a2b, b2c, c2d_3 };
|
||||
assertEquals(expected.length, path.getArcs().size());
|
||||
for (int i = 0; i < expected.length; ++i) {
|
||||
assertEquals(expected[i], path.getArcs().get(i));
|
||||
@ -146,12 +146,12 @@ public class PathTest {
|
||||
@Test
|
||||
public void testCreateShortestPathFromNodes() {
|
||||
Path path;
|
||||
ArcForward[] expected;
|
||||
Arc[] expected;
|
||||
|
||||
// Simple construction
|
||||
path = Path.createShortestPathFromNodes(graph,
|
||||
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2] }));
|
||||
expected = new ArcForward[]{ a2b, b2c };
|
||||
expected = new Arc[]{ a2b, b2c };
|
||||
assertEquals(expected.length, path.getArcs().size());
|
||||
for (int i = 0; i < expected.length; ++i) {
|
||||
assertEquals(expected[i], path.getArcs().get(i));
|
||||
@ -160,7 +160,7 @@ public class PathTest {
|
||||
// Not so simple construction
|
||||
path = Path.createShortestPathFromNodes(graph,
|
||||
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2], nodes[3] }));
|
||||
expected = new ArcForward[]{ a2b, b2c, c2d_2 };
|
||||
expected = new Arc[]{ a2b, b2c, c2d_2 };
|
||||
assertEquals(expected.length, path.getArcs().size());
|
||||
for (int i = 0; i < expected.length; ++i) {
|
||||
assertEquals(expected[i], path.getArcs().get(i));
|
||||
|
Loading…
Reference in New Issue
Block a user