Add my AStar for computing path. Change ID and map names in file.

This commit is contained in:
Mikael Capelle 2018-03-02 17:49:30 +01:00
parent 4017577269
commit 2e7a1c564a
12 changed files with 57 additions and 103 deletions

61
FORMAT
View File

@ -1,61 +0,0 @@
=== Format des fichiers .map ===
- Version du document (= version du format) : 4
- Sauf mention contraire, les entiers sont codés en big endian (compatible DataOutputStream).
[No d'octets] = signification
[0-3] = Magic number 0xbacaff (doit se trouver au début du fichier)
[4-7] = Version du format
[8-11] = Identifiant de carte
[12-15] = Numéro de zone
[16-19] = Nombre de descripteurs dans ce fichier
[20-23] = Nombre de noeuds dans ce fichier
[24-..] =
* Tous les noeuds, les uns après les autres, en commençant par le numéro 0. Voir le format d'un noeud.
* Puis un octet à 255.
* Puis, tous les descripteurs, les uns après les autres, en commençant par le numéro 0.
Voir le format des descripteurs.
* Puis un octet à 254.
* Puis, toutes les routes sortantes (routes sortantes du premier noeud, puis celles du deuxième noeud, etc. )
* Puis un octet à 253.
(fin du fichier)
=== Format des noeuds ===
[0-3] = longitude sur 32 bits (à diviser par 1E6)
[4-7] = latitude sur 32 bits (à diviser par 1E6)
[8] = Nombre de routes sortantes sur 8 bits
=== Format des routes sortantes (taille variable car dépend du nombre de segments) ===
[0] = Numéro de zone du noeud destination (8 bits)
[1-3] = Numéro du noeud destination, dans la zone donnée (24 bits, big endian)
[4-6] = Numéro de descripteur (24 bits)
[7-8] = Longueur de l'arête (16 bits), en mètres, prenant en compte tous les segments.
[9-10] = Nombre de segments (16 bits), éventuellement 0.
[11-...] = Segments
=== Format des segments ===
[0-1] = Delta de longitude, sur 16 bits signés (à diviser par 2.0E5)
[2-3] = Delta de latitude, sur 16 bits signés (à diviser par 2.0E5)
=== Format des descripteurs (la taille est variable, car elle dépend du nom du chemin) ===
[0] = Un caractère indiquant le type de chemin (voir dans Descripteur.java)
[1]
.bit 7 = sens unique
.bits 0-6 = vitesse max en km/h à multiplier par 5.
[2-] = Nom du chemin, de type String-UTF8 (les deux premiers octets donnent la longueur de la chaîne)

View File

@ -1,21 +0,0 @@
=== Format des fichiers .path ===
- Version du document (= version du format) : 1
- Sauf mention contraire, les entiers sont codés en big endian (compatible DataOutputStream).
[No d'octets] = signification
[0-3] = Magic number 0xdecafe (doit se trouver au début du fichier)
[4-7] = Version du format
[8-11] = Identifiant de carte
[12-15] = Nombre de noeuds dans le chemin
[16-19] = Identifiant du premier noeud (8 bits zone + 24 bits numéro noeud)
[20-23] = Identifiant du dernier noeud (8 bits zone + 24 bits numéro noeud)
[24-27] = Identifiant du premier noeud (encore)
[28-31] = Identifiant du deuxième noeud
[32-35] = Identifiant du troisième noeud
etc.
[derniers octets] = Identifiant du dernier noeud

View File

@ -6,7 +6,10 @@ import java.util.List;
public class Graph { public class Graph {
// Map identifier. // Map identifier.
private final int mapId; private final String mapId;
// Map name
private final String mapName;
// Nodes of the graph. // Nodes of the graph.
private final List<Node> nodes; private final List<Node> nodes;
@ -15,8 +18,9 @@ public class Graph {
* @param mapId ID of this graph. * @param mapId ID of this graph.
* @param list List of nodes for 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.mapId = mapId;
this.mapName = mapName;
this.nodes = list; this.nodes = list;
} }
@ -50,10 +54,17 @@ public class Graph {
/** /**
* @return Map ID of this graph. * @return Map ID of this graph.
*/ */
public int getMapId() { public String getMapId() {
return mapId; return mapId;
} }
/**
* @return Name of the map associated with this graph.
*/
public String getMapName() {
return mapName;
}
/** /**
* @return Return the transpose graph of this graph. * @return Return the transpose graph of this graph.
*/ */

View File

@ -179,7 +179,7 @@ public class BinaryGraphReaderInsa2016 extends BinaryReader implements GraphRead
// Check format. // Check format.
checkByteOrThrow(253); checkByteOrThrow(253);
return new Graph(mapId, nodes); return new Graph(Integer.toHexString(mapId), "", nodes);
} }
/** /**

View File

@ -12,8 +12,8 @@ import org.insa.graph.Graph;
import org.insa.graph.Node; import org.insa.graph.Node;
import org.insa.graph.Point; import org.insa.graph.Point;
import org.insa.graph.RoadInformation; import org.insa.graph.RoadInformation;
import org.insa.graph.RoadInformation.AccessRestriction;
import org.insa.graph.RoadInformation.AccessMode; import org.insa.graph.RoadInformation.AccessMode;
import org.insa.graph.RoadInformation.AccessRestriction;
import org.insa.graph.RoadInformation.RoadType; import org.insa.graph.RoadInformation.RoadType;
public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphReader { 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 VERSION = 5;
private static final int MAGIC_NUMBER = 0x208BC3B3; 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... // Some masks...
private static final int MASK_UNKNOWN = 0x01; private static final int MASK_UNKNOWN = 0x01;
private static final int MASK_PRIVATE = 0x02; private static final int MASK_PRIVATE = 0x02;
@ -128,7 +131,18 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
checkVersionOrThrow(dis.readInt()); checkVersionOrThrow(dis.readInt());
// Read map id. // 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)); observers.forEach((observer) -> observer.notifyStartReading(mapId));
@ -229,7 +243,7 @@ public class BinaryGraphReaderInsa2018 extends BinaryReader implements GraphRead
observers.forEach((observer) -> observer.notifyEndReading()); observers.forEach((observer) -> observer.notifyEndReading());
return new Graph(mapId, nodes); return new Graph(mapId, mapName, nodes);
} }
/** /**

View File

@ -26,9 +26,12 @@ public class BinaryPathReader extends BinaryReader implements PathReader {
checkVersionOrThrow(dis.readInt()); checkVersionOrThrow(dis.readInt());
// Read map ID and check against graph. // 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()); throw new MapMismatchException(mapId, graph.getMapId());
} }

View File

@ -2,6 +2,7 @@ package org.insa.graph.io;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import org.insa.graph.Arc; import org.insa.graph.Arc;
import org.insa.graph.Path; import org.insa.graph.Path;
@ -23,9 +24,11 @@ public class BinaryPathWriter extends BinaryWriter implements PathWriter {
dos.writeInt(BinaryPathReader.VERSION); dos.writeInt(BinaryPathReader.VERSION);
// Write map id. // 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); dos.writeInt(path.getArcs().size() + 1);
// Write origin / destination. // Write origin / destination.

View File

@ -12,7 +12,7 @@ public interface GraphReaderObserver {
* *
* @param mapId ID of the graph. * @param mapId ID of the graph.
*/ */
public void notifyStartReading(int mapId); public void notifyStartReading(String mapId);
/** /**
* Notify that the graph has been fully read. * Notify that the graph has been fully read.

View File

@ -9,14 +9,14 @@ public class MapMismatchException extends IOException {
*/ */
private static final long serialVersionUID = 3076730078387819138L; private static final long serialVersionUID = 3076730078387819138L;
// Actual and expected magic numbers. // Actual and expected magic numbers.
private int actualMapId, expectedMapId; private String actualMapId, expectedMapId;
/** /**
* *
* @param actualVersion * @param actualVersion
* @param expectedVersion * @param expectedVersion
*/ */
public MapMismatchException(int actualMapId, int expectedMapId) { public MapMismatchException(String actualMapId, String expectedMapId) {
super(); super();
this.actualMapId = actualMapId; this.actualMapId = actualMapId;
this.expectedMapId = expectedMapId; this.expectedMapId = expectedMapId;
@ -25,14 +25,14 @@ public class MapMismatchException extends IOException {
/** /**
* @return * @return
*/ */
public int getActualMapId() { public String getActualMapId() {
return actualMapId; return actualMapId;
} }
/** /**
* @return * @return
*/ */
public int getExpectedMapId() { public String getExpectedMapId() {
return expectedMapId; return expectedMapId;
} }
} }

View File

@ -73,8 +73,8 @@ public class GraphReaderProgressBar extends JDialog implements GraphReaderObserv
} }
@Override @Override
public void notifyStartReading(int mapId) { public void notifyStartReading(String mapId) {
setTitle(String.format("Reading graph %#x... ", mapId)); setTitle("Reading graph " + mapId + "... ");
setVisible(true); setVisible(true);
} }

View File

@ -278,6 +278,7 @@ public class MainWindow extends JFrame {
threadTimer.stop(); threadTimer.stop();
threadPanel.setVisible(false); threadPanel.setVisible(false);
currentThread.setThread(null); currentThread.setThread(null);
spPanel.setEnabled(true);
} }
private void displayShortestPathSolution(ShortestPathSolution solution) { private void displayShortestPathSolution(ShortestPathSolution solution) {
@ -428,8 +429,12 @@ public class MainWindow extends JFrame {
} }
notifyNewGraphLoaded(); notifyNewGraphLoaded();
graphInfoPanel.setText(String.format("Map ID: %#x, %d nodes", graph.getMapId(), String info = graph.getMapId();
graph.getNodes().size())); if (graph.getMapName() != null && !graph.getMapName().isEmpty()) {
info += " - " + graph.getMapName();
}
info += ", " + graph.getNodes().size() + " nodes";
graphInfoPanel.setText(info);
drawGraph(); drawGraph();
for (JMenuItem item: graphLockItems) { for (JMenuItem item: graphLockItems) {

View File

@ -52,7 +52,7 @@ public class PathTest {
d2e = new Arc(nodes[3], nodes[4], 20, speed20, null); d2e = new Arc(nodes[3], nodes[4], 20, speed20, null);
e2d = new Arc(nodes[4], nodes[0], 10, speed10, null); e2d = new Arc(nodes[4], nodes[0], 10, speed10, null);
graph = new Graph(0, Arrays.asList(nodes)); graph = new Graph("ID", "", 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 }));