Add my AStar for computing path. Change ID and map names in file.
This commit is contained in:
@@ -6,7 +6,10 @@ import java.util.List;
|
||||
public class Graph {
|
||||
|
||||
// Map identifier.
|
||||
private final int mapId;
|
||||
private final String mapId;
|
||||
|
||||
// Map name
|
||||
private final String mapName;
|
||||
|
||||
// Nodes of the graph.
|
||||
private final List<Node> nodes;
|
||||
@@ -15,8 +18,9 @@ public class Graph {
|
||||
* @param mapId ID of this graph.
|
||||
* @param list List of nodes for this graph.
|
||||
*/
|
||||
public Graph(int mapId, List<Node> list) {
|
||||
public Graph(String mapId, String mapName, List<Node> list) {
|
||||
this.mapId = mapId;
|
||||
this.mapName = mapName;
|
||||
this.nodes = list;
|
||||
}
|
||||
|
||||
@@ -50,10 +54,17 @@ public class Graph {
|
||||
/**
|
||||
* @return Map ID of this graph.
|
||||
*/
|
||||
public int getMapId() {
|
||||
public String getMapId() {
|
||||
return mapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Name of the map associated with this graph.
|
||||
*/
|
||||
public String getMapName() {
|
||||
return mapName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Return the transpose graph of this graph.
|
||||
*/
|
||||
|
@@ -179,7 +179,7 @@ public class BinaryGraphReaderInsa2016 extends BinaryReader implements GraphRead
|
||||
// Check format.
|
||||
checkByteOrThrow(253);
|
||||
|
||||
return new Graph(mapId, nodes);
|
||||
return new Graph(Integer.toHexString(mapId), "", nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -12,8 +12,8 @@ import org.insa.graph.Graph;
|
||||
import org.insa.graph.Node;
|
||||
import org.insa.graph.Point;
|
||||
import org.insa.graph.RoadInformation;
|
||||
import org.insa.graph.RoadInformation.AccessRestriction;
|
||||
import org.insa.graph.RoadInformation.AccessMode;
|
||||
import org.insa.graph.RoadInformation.AccessRestriction;
|
||||
import org.insa.graph.RoadInformation.RoadType;
|
||||
|
||||
public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphReader {
|
||||
@@ -22,6 +22,9 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
||||
private static final int VERSION = 5;
|
||||
private static final int MAGIC_NUMBER = 0x208BC3B3;
|
||||
|
||||
// Length of the map id field (in bytes)
|
||||
protected static final int MAP_ID_FIELD_LENGTH = 32;
|
||||
|
||||
// Some masks...
|
||||
private static final int MASK_UNKNOWN = 0x01;
|
||||
private static final int MASK_PRIVATE = 0x02;
|
||||
@@ -128,7 +131,18 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
||||
checkVersionOrThrow(dis.readInt());
|
||||
|
||||
// Read map id.
|
||||
int mapId = dis.readInt();
|
||||
String mapId;
|
||||
String mapName = "";
|
||||
|
||||
if (getCurrentVersion() < 6) {
|
||||
mapId = "0x" + Integer.toHexString(dis.readInt());
|
||||
}
|
||||
else {
|
||||
byte[] byteId = new byte[MAP_ID_FIELD_LENGTH];
|
||||
dis.read(byteId);
|
||||
mapId = new String(byteId, "UTF-8");
|
||||
mapName = dis.readUTF();
|
||||
}
|
||||
|
||||
observers.forEach((observer) -> observer.notifyStartReading(mapId));
|
||||
|
||||
@@ -229,7 +243,7 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
|
||||
|
||||
observers.forEach((observer) -> observer.notifyEndReading());
|
||||
|
||||
return new Graph(mapId, nodes);
|
||||
return new Graph(mapId, mapName, nodes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -26,9 +26,12 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
|
||||
checkVersionOrThrow(dis.readInt());
|
||||
|
||||
// Read map ID and check against graph.
|
||||
int mapId = dis.readInt();
|
||||
byte[] mapIdBytes = new byte[BinaryGraphReaderInsa2018.MAP_ID_FIELD_LENGTH];
|
||||
dis.read(mapIdBytes);
|
||||
|
||||
if (mapId != graph.getMapId()) {
|
||||
String mapId = new String(mapIdBytes, "UTF-8");
|
||||
|
||||
if (!mapId.equals(graph.getMapId())) {
|
||||
throw new MapMismatchException(mapId, graph.getMapId());
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@ package org.insa.graph.io;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.insa.graph.Arc;
|
||||
import org.insa.graph.Path;
|
||||
@@ -23,9 +24,11 @@ public class BinaryPathWriter extends BinaryWriter implements PathWriter {
|
||||
dos.writeInt(BinaryPathReader.VERSION);
|
||||
|
||||
// Write map id.
|
||||
dos.writeInt(path.getGraph().getMapId());
|
||||
byte[] bytes = Arrays.copyOf(path.getGraph().getMapId().getBytes("UTF-8"),
|
||||
BinaryGraphReaderInsa2018.MAP_ID_FIELD_LENGTH);
|
||||
dos.write(bytes);
|
||||
|
||||
// Write number of racs
|
||||
// Write number of arcs
|
||||
dos.writeInt(path.getArcs().size() + 1);
|
||||
|
||||
// Write origin / destination.
|
||||
|
@@ -12,7 +12,7 @@ public interface GraphReaderObserver {
|
||||
*
|
||||
* @param mapId ID of the graph.
|
||||
*/
|
||||
public void notifyStartReading(int mapId);
|
||||
public void notifyStartReading(String mapId);
|
||||
|
||||
/**
|
||||
* Notify that the graph has been fully read.
|
||||
|
@@ -9,14 +9,14 @@ public class MapMismatchException extends IOException {
|
||||
*/
|
||||
private static final long serialVersionUID = 3076730078387819138L;
|
||||
// Actual and expected magic numbers.
|
||||
private int actualMapId, expectedMapId;
|
||||
private String actualMapId, expectedMapId;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param actualVersion
|
||||
* @param expectedVersion
|
||||
*/
|
||||
public MapMismatchException(int actualMapId, int expectedMapId) {
|
||||
public MapMismatchException(String actualMapId, String expectedMapId) {
|
||||
super();
|
||||
this.actualMapId = actualMapId;
|
||||
this.expectedMapId = expectedMapId;
|
||||
@@ -25,14 +25,14 @@ public class MapMismatchException extends IOException {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getActualMapId() {
|
||||
public String getActualMapId() {
|
||||
return actualMapId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getExpectedMapId() {
|
||||
public String getExpectedMapId() {
|
||||
return expectedMapId;
|
||||
}
|
||||
}
|
||||
|
@@ -73,8 +73,8 @@ public class GraphReaderProgressBar extends JDialog implements GraphReaderObserv
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyStartReading(int mapId) {
|
||||
setTitle(String.format("Reading graph %#x... ", mapId));
|
||||
public void notifyStartReading(String mapId) {
|
||||
setTitle("Reading graph " + mapId + "... ");
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
|
@@ -278,6 +278,7 @@ public class MainWindow extends JFrame {
|
||||
threadTimer.stop();
|
||||
threadPanel.setVisible(false);
|
||||
currentThread.setThread(null);
|
||||
spPanel.setEnabled(true);
|
||||
}
|
||||
|
||||
private void displayShortestPathSolution(ShortestPathSolution solution) {
|
||||
@@ -428,8 +429,12 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
notifyNewGraphLoaded();
|
||||
|
||||
graphInfoPanel.setText(String.format("Map ID: %#x, %d nodes", graph.getMapId(),
|
||||
graph.getNodes().size()));
|
||||
String info = graph.getMapId();
|
||||
if (graph.getMapName() != null && !graph.getMapName().isEmpty()) {
|
||||
info += " - " + graph.getMapName();
|
||||
}
|
||||
info += ", " + graph.getNodes().size() + " nodes";
|
||||
graphInfoPanel.setText(info);
|
||||
drawGraph();
|
||||
|
||||
for (JMenuItem item: graphLockItems) {
|
||||
|
Reference in New Issue
Block a user