add information regarding number of arcs in graph.
This commit is contained in:
parent
23b46fd4bc
commit
97775a9714
3 changed files with 43 additions and 4 deletions
|
@ -86,6 +86,9 @@ public class GraphStatistics {
|
||||||
// Bounding box for this graph.
|
// Bounding box for this graph.
|
||||||
private final BoundingBox boundingBox;
|
private final BoundingBox boundingBox;
|
||||||
|
|
||||||
|
// Number of roads
|
||||||
|
private final int nbRoadOneWay, nbRoadTwoWays;
|
||||||
|
|
||||||
// Maximum speed on this graph (in kmph).
|
// Maximum speed on this graph (in kmph).
|
||||||
private final int maximumSpeed;
|
private final int maximumSpeed;
|
||||||
|
|
||||||
|
@ -96,13 +99,18 @@ public class GraphStatistics {
|
||||||
* Create a new GraphStatistics instance with the given value.
|
* Create a new GraphStatistics instance with the given value.
|
||||||
*
|
*
|
||||||
* @param boundingBox Bounding-box for the graph.
|
* @param boundingBox Bounding-box for the graph.
|
||||||
|
* @param nbRoadOneWay Number of one-way roads in the graph.
|
||||||
|
* @param nbRoadTwoTayws Number of two-ways roads in the graph.
|
||||||
* @param maximumSpeed Maximum speed of any road of the graph. You can use
|
* @param maximumSpeed Maximum speed of any road of the graph. You can use
|
||||||
* {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
|
* {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
|
||||||
* speed limit.
|
* speed limit.
|
||||||
* @param maximumLength Maximum length of any arc of the graph.
|
* @param maximumLength Maximum length of any arc of the graph.
|
||||||
*/
|
*/
|
||||||
public GraphStatistics(BoundingBox boundingBox, int maximumSpeed, float maximumLength) {
|
public GraphStatistics(BoundingBox boundingBox, int nbRoadOneWay, int nbRoadTwoWays,
|
||||||
|
int maximumSpeed, float maximumLength) {
|
||||||
this.boundingBox = boundingBox;
|
this.boundingBox = boundingBox;
|
||||||
|
this.nbRoadOneWay = nbRoadOneWay;
|
||||||
|
this.nbRoadTwoWays = nbRoadTwoWays;
|
||||||
this.maximumLength = maximumLength;
|
this.maximumLength = maximumLength;
|
||||||
this.maximumSpeed = maximumSpeed;
|
this.maximumSpeed = maximumSpeed;
|
||||||
}
|
}
|
||||||
|
@ -114,6 +122,30 @@ public class GraphStatistics {
|
||||||
return this.boundingBox;
|
return this.boundingBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Amount of one-way roads in this graph.
|
||||||
|
*/
|
||||||
|
public int getOneWayRoadCount() {
|
||||||
|
return this.nbRoadOneWay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Amount of two-ways roads in this graph.
|
||||||
|
*/
|
||||||
|
public int getTwoWaysRoadCount() {
|
||||||
|
return this.nbRoadTwoWays;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Number of arcs in this graph.
|
||||||
|
*
|
||||||
|
* @see #getOneWayRoadCount()
|
||||||
|
* @see #getTwoWaysRoadCount()
|
||||||
|
*/
|
||||||
|
public int getArcCount() {
|
||||||
|
return getOneWayRoadCount() + 2 * getTwoWaysRoadCount();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if this graph has a maximum speed limit, false otherwise.
|
* @return true if this graph has a maximum speed limit, false otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -228,6 +228,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||||
// Read successors and convert to arcs.
|
// Read successors and convert to arcs.
|
||||||
float maxLength = 0;
|
float maxLength = 0;
|
||||||
final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
|
final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
|
||||||
|
int nbOneWayRoad = 0;
|
||||||
observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
|
observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
|
||||||
for (int node = 0; node < nbNodes; ++node) {
|
for (int node = 0; node < nbNodes; ++node) {
|
||||||
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
|
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
|
||||||
|
@ -273,6 +274,9 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||||
|
|
||||||
// Add successor to initial arc.
|
// Add successor to initial arc.
|
||||||
Arc arc = Node.linkNodes(orig, dest, length, info, points);
|
Arc arc = Node.linkNodes(orig, dest, length, info, points);
|
||||||
|
if (info.isOneWay()) {
|
||||||
|
nbOneWayRoad++;
|
||||||
|
}
|
||||||
observers.forEach((observer) -> observer.notifyNewArcRead(arc));
|
observers.forEach((observer) -> observer.notifyNewArcRead(arc));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,8 +289,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||||
this.dis.close();
|
this.dis.close();
|
||||||
|
|
||||||
return new Graph(mapId, mapName, nodes,
|
return new Graph(mapId, mapName, nodes,
|
||||||
new GraphStatistics(new BoundingBox(new Point(minLongitude, maxLatitude),
|
new GraphStatistics(
|
||||||
new Point(maxLongitude, minLatitude)), maxSpeed, maxLength));
|
new BoundingBox(new Point(minLongitude, maxLatitude),
|
||||||
|
new Point(maxLongitude, minLatitude)),
|
||||||
|
nbOneWayRoad, nbTotalSuccessors - nbOneWayRoad, maxSpeed, maxLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -593,7 +593,8 @@ public class MainWindow extends JFrame {
|
||||||
// name that are right-to-left (e.g. arabic names).
|
// name that are right-to-left (e.g. arabic names).
|
||||||
info += " - " + graph.getMapName() + "\u200e";
|
info += " - " + graph.getMapName() + "\u200e";
|
||||||
}
|
}
|
||||||
info += ", " + graph.getNodes().size() + " nodes";
|
info += ", " + graph.getNodes().size() + " nodes, "
|
||||||
|
+ graph.getGraphInformation().getArcCount() + " arcs.";
|
||||||
graphInfoPanel.setText(info);
|
graphInfoPanel.setText(info);
|
||||||
|
|
||||||
drawGraph();
|
drawGraph();
|
||||||
|
|
Loading…
Reference in a new issue