From 97775a971466d53f11539a3c478459c217534ceb Mon Sep 17 00:00:00 2001 From: Holt59 Date: Sun, 11 Mar 2018 20:34:16 +0100 Subject: [PATCH] add information regarding number of arcs in graph. --- src/main/org/insa/graph/GraphStatistics.java | 34 ++++++++++++++++++- .../org/insa/graph/io/BinaryGraphReader.java | 10 ++++-- src/main/org/insa/graphics/MainWindow.java | 3 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/main/org/insa/graph/GraphStatistics.java b/src/main/org/insa/graph/GraphStatistics.java index 91d1656..d4f4b71 100644 --- a/src/main/org/insa/graph/GraphStatistics.java +++ b/src/main/org/insa/graph/GraphStatistics.java @@ -86,6 +86,9 @@ public class GraphStatistics { // Bounding box for this graph. private final BoundingBox boundingBox; + // Number of roads + private final int nbRoadOneWay, nbRoadTwoWays; + // Maximum speed on this graph (in kmph). private final int maximumSpeed; @@ -96,13 +99,18 @@ public class GraphStatistics { * Create a new GraphStatistics instance with the given value. * * @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 * {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum * speed limit. * @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.nbRoadOneWay = nbRoadOneWay; + this.nbRoadTwoWays = nbRoadTwoWays; this.maximumLength = maximumLength; this.maximumSpeed = maximumSpeed; } @@ -114,6 +122,30 @@ public class GraphStatistics { 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. */ diff --git a/src/main/org/insa/graph/io/BinaryGraphReader.java b/src/main/org/insa/graph/io/BinaryGraphReader.java index c439953..ba33d25 100644 --- a/src/main/org/insa/graph/io/BinaryGraphReader.java +++ b/src/main/org/insa/graph/io/BinaryGraphReader.java @@ -228,6 +228,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { // Read successors and convert to arcs. float maxLength = 0; final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java... + int nbOneWayRoad = 0; observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors)); for (int node = 0; node < nbNodes; ++node) { for (int succ = 0; succ < nbSuccessors[node]; ++succ) { @@ -273,6 +274,9 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { // Add successor to initial arc. Arc arc = Node.linkNodes(orig, dest, length, info, points); + if (info.isOneWay()) { + nbOneWayRoad++; + } observers.forEach((observer) -> observer.notifyNewArcRead(arc)); } } @@ -285,8 +289,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader { this.dis.close(); return new Graph(mapId, mapName, nodes, - new GraphStatistics(new BoundingBox(new Point(minLongitude, maxLatitude), - new Point(maxLongitude, minLatitude)), maxSpeed, maxLength)); + new GraphStatistics( + new BoundingBox(new Point(minLongitude, maxLatitude), + new Point(maxLongitude, minLatitude)), + nbOneWayRoad, nbTotalSuccessors - nbOneWayRoad, maxSpeed, maxLength)); } /** diff --git a/src/main/org/insa/graphics/MainWindow.java b/src/main/org/insa/graphics/MainWindow.java index 46e6ef7..9d99c10 100644 --- a/src/main/org/insa/graphics/MainWindow.java +++ b/src/main/org/insa/graphics/MainWindow.java @@ -593,7 +593,8 @@ public class MainWindow extends JFrame { // name that are right-to-left (e.g. arabic names). info += " - " + graph.getMapName() + "\u200e"; } - info += ", " + graph.getNodes().size() + " nodes"; + info += ", " + graph.getNodes().size() + " nodes, " + + graph.getGraphInformation().getArcCount() + " arcs."; graphInfoPanel.setText(info); drawGraph();