Browse Source

add information regarding number of arcs in graph.

Holt59 6 years ago
parent
commit
97775a9714

+ 33
- 1
src/main/org/insa/graph/GraphStatistics.java View File

@@ -86,6 +86,9 @@ public class GraphStatistics {
86 86
     // Bounding box for this graph.
87 87
     private final BoundingBox boundingBox;
88 88
 
89
+    // Number of roads
90
+    private final int nbRoadOneWay, nbRoadTwoWays;
91
+
89 92
     // Maximum speed on this graph (in kmph).
90 93
     private final int maximumSpeed;
91 94
 
@@ -96,13 +99,18 @@ public class GraphStatistics {
96 99
      * Create a new GraphStatistics instance with the given value.
97 100
      * 
98 101
      * @param boundingBox Bounding-box for the graph.
102
+     * @param nbRoadOneWay Number of one-way roads in the graph.
103
+     * @param nbRoadTwoTayws Number of two-ways roads in the graph.
99 104
      * @param maximumSpeed Maximum speed of any road of the graph. You can use
100 105
      *        {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
101 106
      *        speed limit.
102 107
      * @param maximumLength Maximum length of any arc of the graph.
103 108
      */
104
-    public GraphStatistics(BoundingBox boundingBox, int maximumSpeed, float maximumLength) {
109
+    public GraphStatistics(BoundingBox boundingBox, int nbRoadOneWay, int nbRoadTwoWays,
110
+            int maximumSpeed, float maximumLength) {
105 111
         this.boundingBox = boundingBox;
112
+        this.nbRoadOneWay = nbRoadOneWay;
113
+        this.nbRoadTwoWays = nbRoadTwoWays;
106 114
         this.maximumLength = maximumLength;
107 115
         this.maximumSpeed = maximumSpeed;
108 116
     }
@@ -115,6 +123,30 @@ public class GraphStatistics {
115 123
     }
116 124
 
117 125
     /**
126
+     * @return Amount of one-way roads in this graph.
127
+     */
128
+    public int getOneWayRoadCount() {
129
+        return this.nbRoadOneWay;
130
+    }
131
+
132
+    /**
133
+     * @return Amount of two-ways roads in this graph.
134
+     */
135
+    public int getTwoWaysRoadCount() {
136
+        return this.nbRoadTwoWays;
137
+    }
138
+
139
+    /**
140
+     * @return Number of arcs in this graph.
141
+     * 
142
+     * @see #getOneWayRoadCount()
143
+     * @see #getTwoWaysRoadCount()
144
+     */
145
+    public int getArcCount() {
146
+        return getOneWayRoadCount() + 2 * getTwoWaysRoadCount();
147
+    }
148
+
149
+    /**
118 150
      * @return true if this graph has a maximum speed limit, false otherwise.
119 151
      */
120 152
     public boolean hasMaximumSpeed() {

+ 8
- 2
src/main/org/insa/graph/io/BinaryGraphReader.java View File

@@ -228,6 +228,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
228 228
         // Read successors and convert to arcs.
229 229
         float maxLength = 0;
230 230
         final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
231
+        int nbOneWayRoad = 0;
231 232
         observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
232 233
         for (int node = 0; node < nbNodes; ++node) {
233 234
             for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
@@ -273,6 +274,9 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
273 274
 
274 275
                 // Add successor to initial arc.
275 276
                 Arc arc = Node.linkNodes(orig, dest, length, info, points);
277
+                if (info.isOneWay()) {
278
+                    nbOneWayRoad++;
279
+                }
276 280
                 observers.forEach((observer) -> observer.notifyNewArcRead(arc));
277 281
             }
278 282
         }
@@ -285,8 +289,10 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
285 289
         this.dis.close();
286 290
 
287 291
         return new Graph(mapId, mapName, nodes,
288
-                new GraphStatistics(new BoundingBox(new Point(minLongitude, maxLatitude),
289
-                        new Point(maxLongitude, minLatitude)), maxSpeed, maxLength));
292
+                new GraphStatistics(
293
+                        new BoundingBox(new Point(minLongitude, maxLatitude),
294
+                                new Point(maxLongitude, minLatitude)),
295
+                        nbOneWayRoad, nbTotalSuccessors - nbOneWayRoad, maxSpeed, maxLength));
290 296
     }
291 297
 
292 298
     /**

+ 2
- 1
src/main/org/insa/graphics/MainWindow.java View File

@@ -593,7 +593,8 @@ public class MainWindow extends JFrame {
593 593
                     // name that are right-to-left (e.g. arabic names).
594 594
                     info += " - " + graph.getMapName() + "\u200e";
595 595
                 }
596
-                info += ", " + graph.getNodes().size() + " nodes";
596
+                info += ", " + graph.getNodes().size() + " nodes, "
597
+                        + graph.getGraphInformation().getArcCount() + " arcs.";
597 598
                 graphInfoPanel.setText(info);
598 599
 
599 600
                 drawGraph();

Loading…
Cancel
Save