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
     // Bounding box for this graph.
86
     // Bounding box for this graph.
87
     private final BoundingBox boundingBox;
87
     private final BoundingBox boundingBox;
88
 
88
 
89
+    // Number of roads
90
+    private final int nbRoadOneWay, nbRoadTwoWays;
91
+
89
     // Maximum speed on this graph (in kmph).
92
     // Maximum speed on this graph (in kmph).
90
     private final int maximumSpeed;
93
     private final int maximumSpeed;
91
 
94
 
96
      * Create a new GraphStatistics instance with the given value.
99
      * Create a new GraphStatistics instance with the given value.
97
      * 
100
      * 
98
      * @param boundingBox Bounding-box for the graph.
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
      * @param maximumSpeed Maximum speed of any road of the graph. You can use
104
      * @param maximumSpeed Maximum speed of any road of the graph. You can use
100
      *        {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
105
      *        {@link #NO_MAXIMUM_SPEED} to indicate that the graph has no maximum
101
      *        speed limit.
106
      *        speed limit.
102
      * @param maximumLength Maximum length of any arc of the graph.
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
         this.boundingBox = boundingBox;
111
         this.boundingBox = boundingBox;
112
+        this.nbRoadOneWay = nbRoadOneWay;
113
+        this.nbRoadTwoWays = nbRoadTwoWays;
106
         this.maximumLength = maximumLength;
114
         this.maximumLength = maximumLength;
107
         this.maximumSpeed = maximumSpeed;
115
         this.maximumSpeed = maximumSpeed;
108
     }
116
     }
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
      * @return true if this graph has a maximum speed limit, false otherwise.
150
      * @return true if this graph has a maximum speed limit, false otherwise.
119
      */
151
      */
120
     public boolean hasMaximumSpeed() {
152
     public boolean hasMaximumSpeed() {

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

228
         // Read successors and convert to arcs.
228
         // Read successors and convert to arcs.
229
         float maxLength = 0;
229
         float maxLength = 0;
230
         final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
230
         final int copyNbTotalSuccesors = nbTotalSuccessors; // Stupid Java...
231
+        int nbOneWayRoad = 0;
231
         observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
232
         observers.forEach((observer) -> observer.notifyStartReadingArcs(copyNbTotalSuccesors));
232
         for (int node = 0; node < nbNodes; ++node) {
233
         for (int node = 0; node < nbNodes; ++node) {
233
             for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
234
             for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
273
 
274
 
274
                 // Add successor to initial arc.
275
                 // Add successor to initial arc.
275
                 Arc arc = Node.linkNodes(orig, dest, length, info, points);
276
                 Arc arc = Node.linkNodes(orig, dest, length, info, points);
277
+                if (info.isOneWay()) {
278
+                    nbOneWayRoad++;
279
+                }
276
                 observers.forEach((observer) -> observer.notifyNewArcRead(arc));
280
                 observers.forEach((observer) -> observer.notifyNewArcRead(arc));
277
             }
281
             }
278
         }
282
         }
285
         this.dis.close();
289
         this.dis.close();
286
 
290
 
287
         return new Graph(mapId, mapName, nodes,
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
                     // name that are right-to-left (e.g. arabic names).
593
                     // name that are right-to-left (e.g. arabic names).
594
                     info += " - " + graph.getMapName() + "\u200e";
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
                 graphInfoPanel.setText(info);
598
                 graphInfoPanel.setText(info);
598
 
599
 
599
                 drawGraph();
600
                 drawGraph();

Loading…
Cancel
Save