Integrate access information in RoadInformation.
This commit is contained in:
parent
0963f4a12f
commit
875a0c8518
@ -28,9 +28,36 @@ public class RoadInformation {
|
|||||||
COASTLINE
|
COASTLINE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access mode.
|
||||||
|
*/
|
||||||
|
public enum AccessMode {
|
||||||
|
FOOT, BICYCLE, SMALL_MOTORCYCLE, MOTORCYCLE, MOTORCAR, BUS
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some masks...
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static final int MASK_UNKNOWN = 0x01;
|
||||||
|
private static final int MASK_PRIVATE = 0x02;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static final int MASK_AGRICULTURAL = 0x04;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private static final int MASK_SERVICE = 0x08;
|
||||||
|
private static final int MASK_PUBLIC_TRANSPORT = 0x10;
|
||||||
|
|
||||||
|
private static final int MASK_FOOT = 0x01 << 8;
|
||||||
|
private static final int MASK_BICYCLE = 0x02 << 8;
|
||||||
|
private static final int MASK_MOTORCYCLE = 0x0C << 8;
|
||||||
|
private static final int MASK_SMALL_MOTORCYCLE = 0x08 << 8;
|
||||||
|
private static final int MASK_MOTORCAR = 0x10 << 8;
|
||||||
|
private static final int MASK_BUS = 0x20 << 8;
|
||||||
|
|
||||||
// Type of the road (see above).
|
// Type of the road (see above).
|
||||||
private final RoadType type;
|
private final RoadType type;
|
||||||
|
|
||||||
|
// Access information
|
||||||
|
private final int access;
|
||||||
|
|
||||||
// One way road?
|
// One way road?
|
||||||
private final boolean oneway;
|
private final boolean oneway;
|
||||||
|
|
||||||
@ -40,13 +67,64 @@ public class RoadInformation {
|
|||||||
// Name of the road.
|
// Name of the road.
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public RoadInformation(RoadType roadType, boolean isOneWay, int maxSpeed, String name) {
|
public RoadInformation(RoadType roadType, int access, boolean isOneWay, int maxSpeed,
|
||||||
|
String name) {
|
||||||
this.type = roadType;
|
this.type = roadType;
|
||||||
|
this.access = access;
|
||||||
this.oneway = isOneWay;
|
this.oneway = isOneWay;
|
||||||
this.maxSpeed = maxSpeed;
|
this.maxSpeed = maxSpeed;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Access information
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this is a private road.
|
||||||
|
*/
|
||||||
|
public boolean isPrivate() {
|
||||||
|
return (this.access & MASK_PRIVATE) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this road is reserved for public transport.
|
||||||
|
*/
|
||||||
|
public boolean isPublicTransport() {
|
||||||
|
return (this.access & MASK_PUBLIC_TRANSPORT) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mode
|
||||||
|
*
|
||||||
|
* @return true if this road is allowed for the specified mode.
|
||||||
|
*/
|
||||||
|
public boolean isAllowedFor(AccessMode mode) {
|
||||||
|
if ((this.access & MASK_UNKNOWN) != 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int maskedAccess = 0;
|
||||||
|
switch (mode) {
|
||||||
|
case FOOT:
|
||||||
|
maskedAccess = access & MASK_FOOT;
|
||||||
|
break;
|
||||||
|
case BICYCLE:
|
||||||
|
maskedAccess = access & MASK_BICYCLE;
|
||||||
|
break;
|
||||||
|
case SMALL_MOTORCYCLE:
|
||||||
|
maskedAccess = access & MASK_SMALL_MOTORCYCLE;
|
||||||
|
break;
|
||||||
|
case MOTORCYCLE:
|
||||||
|
maskedAccess = access & MASK_MOTORCYCLE;
|
||||||
|
break;
|
||||||
|
case MOTORCAR:
|
||||||
|
maskedAccess = access & MASK_MOTORCAR;
|
||||||
|
break;
|
||||||
|
case BUS:
|
||||||
|
maskedAccess = access & MASK_BUS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return maskedAccess != 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Type of the road.
|
* @return Type of the road.
|
||||||
*/
|
*/
|
||||||
@ -77,7 +155,6 @@ public class RoadInformation {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -89,7 +166,8 @@ public class RoadInformation {
|
|||||||
if (getType() == RoadType.MOTORWAY) {
|
if (getType() == RoadType.MOTORWAY) {
|
||||||
typeAsString = "highway";
|
typeAsString = "highway";
|
||||||
}
|
}
|
||||||
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "") + maxSpeed + " km/h (max.)";
|
return typeAsString + " : " + getName() + " " + (isOneWay() ? " (oneway) " : "") + maxSpeed
|
||||||
|
+ " km/h (max.)";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,8 @@ public class BinaryGraphReaderInsa2016 extends BinaryReader implements GraphRead
|
|||||||
float dlon = (dis.readShort()) / 2.0e5f;
|
float dlon = (dis.readShort()) / 2.0e5f;
|
||||||
float dlat = (dis.readShort()) / 2.0e5f;
|
float dlat = (dis.readShort()) / 2.0e5f;
|
||||||
|
|
||||||
points.add(new Point(lastPoint.getLongitude() + dlon, lastPoint.getLatitude() + dlat));
|
points.add(new Point(lastPoint.getLongitude() + dlon,
|
||||||
|
lastPoint.getLatitude() + dlat));
|
||||||
}
|
}
|
||||||
|
|
||||||
points.add(nodes.get(destNode).getPoint());
|
points.add(nodes.get(destNode).getPoint());
|
||||||
@ -188,7 +189,8 @@ public class BinaryGraphReaderInsa2016 extends BinaryReader implements GraphRead
|
|||||||
private RoadInformation readRoadInformation() throws IOException {
|
private RoadInformation readRoadInformation() throws IOException {
|
||||||
char type = (char) dis.readUnsignedByte();
|
char type = (char) dis.readUnsignedByte();
|
||||||
int x = dis.readUnsignedByte();
|
int x = dis.readUnsignedByte();
|
||||||
return new RoadInformation(toRoadType(type), (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
return new RoadInformation(toRoadType(type), 0, (x & 0x80) > 0, (x & 0x7F) * 5,
|
||||||
|
dis.readUTF());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,8 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
|||||||
float dlon = (dis.readShort()) / 2.0e5f;
|
float dlon = (dis.readShort()) / 2.0e5f;
|
||||||
float dlat = (dis.readShort()) / 2.0e5f;
|
float dlat = (dis.readShort()) / 2.0e5f;
|
||||||
|
|
||||||
points.add(new Point(lastPoint.getLongitude() + dlon, lastPoint.getLatitude() + dlat));
|
points.add(new Point(lastPoint.getLongitude() + dlon,
|
||||||
|
lastPoint.getLatitude() + dlat));
|
||||||
}
|
}
|
||||||
|
|
||||||
points.add(nodes.get(destNode).getPoint());
|
points.add(nodes.get(destNode).getPoint());
|
||||||
@ -193,7 +194,12 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
|||||||
private RoadInformation readRoadInformation() throws IOException {
|
private RoadInformation readRoadInformation() throws IOException {
|
||||||
char type = (char) dis.readUnsignedByte();
|
char type = (char) dis.readUnsignedByte();
|
||||||
int x = dis.readUnsignedByte();
|
int x = dis.readUnsignedByte();
|
||||||
return new RoadInformation(toRoadType(type), (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
int access = 0xFF00;
|
||||||
|
if (getCurrentVersion() >= 6) {
|
||||||
|
access = dis.readUnsignedShort();
|
||||||
|
}
|
||||||
|
return new RoadInformation(toRoadType(type), access, (x & 0x80) > 0, (x & 0x7F) * 5,
|
||||||
|
dis.readUTF());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,8 @@ import java.util.List;
|
|||||||
public abstract class BinaryReader {
|
public abstract class BinaryReader {
|
||||||
|
|
||||||
// Map version and magic number targeted for this reader.
|
// Map version and magic number targeted for this reader.
|
||||||
private int version;
|
private int minVersion;
|
||||||
|
private int curVersion;
|
||||||
private int magicNumber;
|
private int magicNumber;
|
||||||
|
|
||||||
// InputStream
|
// InputStream
|
||||||
@ -17,9 +18,9 @@ public abstract class BinaryReader {
|
|||||||
// List of observers
|
// List of observers
|
||||||
protected List<GraphReaderObserver> observers = new ArrayList<>();
|
protected List<GraphReaderObserver> observers = new ArrayList<>();
|
||||||
|
|
||||||
protected BinaryReader(int magicNumber, int version, DataInputStream dis) {
|
protected BinaryReader(int magicNumber, int minVersion, DataInputStream dis) {
|
||||||
this.magicNumber = magicNumber;
|
this.magicNumber = magicNumber;
|
||||||
this.version = version;
|
this.minVersion = minVersion;
|
||||||
this.dis = dis;
|
this.dis = dis;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,20 +32,31 @@ public abstract class BinaryReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Check if the given version is greater than the minimum version, and update
|
||||||
|
* the current version if it is.
|
||||||
|
*
|
||||||
* @param version
|
* @param version
|
||||||
* @throws BadVersionException
|
* @throws BadVersionException
|
||||||
*/
|
*/
|
||||||
public void checkVersionOrThrow(int version) throws BadVersionException {
|
protected void checkVersionOrThrow(int version) throws BadVersionException {
|
||||||
if (this.version != version) {
|
if (version < this.minVersion) {
|
||||||
throw new BadVersionException(version, this.version);
|
throw new BadVersionException(version, this.minVersion);
|
||||||
}
|
}
|
||||||
|
this.curVersion = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the current version.
|
||||||
|
*/
|
||||||
|
protected int getCurrentVersion() {
|
||||||
|
return this.curVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param magicNumber
|
* @param magicNumber
|
||||||
* @throws BadMagicNumberException
|
* @throws BadMagicNumberException
|
||||||
*/
|
*/
|
||||||
public void checkMagicNumberOrThrow(int magicNumber) throws BadMagicNumberException {
|
protected void checkMagicNumberOrThrow(int magicNumber) throws BadMagicNumberException {
|
||||||
if (this.magicNumber != magicNumber) {
|
if (this.magicNumber != magicNumber) {
|
||||||
throw new BadMagicNumberException(magicNumber, this.magicNumber);
|
throw new BadMagicNumberException(magicNumber, this.magicNumber);
|
||||||
}
|
}
|
||||||
@ -58,7 +70,7 @@ public abstract class BinaryReader {
|
|||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void checkByteOrThrow(int i) throws IOException {
|
protected void checkByteOrThrow(int i) throws IOException {
|
||||||
if (dis.readUnsignedByte() != i) {
|
if (dis.readUnsignedByte() != i) {
|
||||||
throw new BadFormatException();
|
throw new BadFormatException();
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ public class PathTest {
|
|||||||
public static void initAll() throws IOException {
|
public static void initAll() throws IOException {
|
||||||
|
|
||||||
// 10 and 20 meters per seconds
|
// 10 and 20 meters per seconds
|
||||||
RoadInformation speed10 = new RoadInformation(RoadType.ROAD, true, 36, ""),
|
RoadInformation speed10 = new RoadInformation(RoadType.ROAD, 0, true, 36, ""),
|
||||||
speed20 = new RoadInformation(RoadType.ROAD, true, 72, "");
|
speed20 = new RoadInformation(RoadType.ROAD, 0, true, 72, "");
|
||||||
|
|
||||||
// Create nodes
|
// Create nodes
|
||||||
nodes = new Node[5];
|
nodes = new Node[5];
|
||||||
@ -55,11 +55,12 @@ public class PathTest {
|
|||||||
graph = new Graph(0, Arrays.asList(nodes));
|
graph = new Graph(0, Arrays.asList(nodes));
|
||||||
|
|
||||||
emptyPath = new Path(graph, new ArrayList<Arc>());
|
emptyPath = new Path(graph, new ArrayList<Arc>());
|
||||||
shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
|
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 }));
|
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 }));
|
loopPath = new Path(graph, Arrays.asList(new Arc[]{ a2b, b2c, c2d_1, d2a }));
|
||||||
longLoopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
longLoopPath = new Path(graph,
|
||||||
invalidPath = new Path(graph, Arrays.asList(new Arc[] { 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 }));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,8 +125,9 @@ public class PathTest {
|
|||||||
Arc[] expected;
|
Arc[] expected;
|
||||||
|
|
||||||
// Simple construction
|
// Simple construction
|
||||||
path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2] }));
|
path = Path.createFastestPathFromNodes(graph,
|
||||||
expected = new Arc[] { a2b, b2c };
|
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2] }));
|
||||||
|
expected = new Arc[]{ a2b, b2c };
|
||||||
assertEquals(expected.length, path.getArcs().size());
|
assertEquals(expected.length, path.getArcs().size());
|
||||||
for (int i = 0; i < expected.length; ++i) {
|
for (int i = 0; i < expected.length; ++i) {
|
||||||
assertEquals(expected[i], path.getArcs().get(i));
|
assertEquals(expected[i], path.getArcs().get(i));
|
||||||
@ -133,8 +135,8 @@ public class PathTest {
|
|||||||
|
|
||||||
// Not so simple construction
|
// Not so simple construction
|
||||||
path = Path.createFastestPathFromNodes(graph,
|
path = Path.createFastestPathFromNodes(graph,
|
||||||
Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2], nodes[3] }));
|
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2], nodes[3] }));
|
||||||
expected = new Arc[] { a2b, b2c, c2d_3 };
|
expected = new Arc[]{ a2b, b2c, c2d_3 };
|
||||||
assertEquals(expected.length, path.getArcs().size());
|
assertEquals(expected.length, path.getArcs().size());
|
||||||
for (int i = 0; i < expected.length; ++i) {
|
for (int i = 0; i < expected.length; ++i) {
|
||||||
assertEquals(expected[i], path.getArcs().get(i));
|
assertEquals(expected[i], path.getArcs().get(i));
|
||||||
@ -147,8 +149,9 @@ public class PathTest {
|
|||||||
Arc[] expected;
|
Arc[] expected;
|
||||||
|
|
||||||
// Simple construction
|
// Simple construction
|
||||||
path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2] }));
|
path = Path.createShortestPathFromNodes(graph,
|
||||||
expected = new Arc[] { a2b, b2c };
|
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2] }));
|
||||||
|
expected = new Arc[]{ a2b, b2c };
|
||||||
assertEquals(expected.length, path.getArcs().size());
|
assertEquals(expected.length, path.getArcs().size());
|
||||||
for (int i = 0; i < expected.length; ++i) {
|
for (int i = 0; i < expected.length; ++i) {
|
||||||
assertEquals(expected[i], path.getArcs().get(i));
|
assertEquals(expected[i], path.getArcs().get(i));
|
||||||
@ -156,8 +159,8 @@ public class PathTest {
|
|||||||
|
|
||||||
// Not so simple construction
|
// Not so simple construction
|
||||||
path = Path.createShortestPathFromNodes(graph,
|
path = Path.createShortestPathFromNodes(graph,
|
||||||
Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2], nodes[3] }));
|
Arrays.asList(new Node[]{ nodes[0], nodes[1], nodes[2], nodes[3] }));
|
||||||
expected = new Arc[] { a2b, b2c, c2d_2 };
|
expected = new Arc[]{ a2b, b2c, c2d_2 };
|
||||||
assertEquals(expected.length, path.getArcs().size());
|
assertEquals(expected.length, path.getArcs().size());
|
||||||
for (int i = 0; i < expected.length; ++i) {
|
for (int i = 0; i < expected.length; ++i) {
|
||||||
assertEquals(expected[i], path.getArcs().get(i));
|
assertEquals(expected[i], path.getArcs().get(i));
|
||||||
@ -166,12 +169,12 @@ public class PathTest {
|
|||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testCreateFastestPathFromNodesException() {
|
public void testCreateFastestPathFromNodesException() {
|
||||||
Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
|
Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[]{ nodes[1], nodes[0] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testCreateShortestPathFromNodesException() {
|
public void testCreateShortestPathFromNodesException() {
|
||||||
Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
|
Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[]{ nodes[1], nodes[0] }));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user