Browse Source

Nodes are no longer comparable (confusion with Label comparison). Predefined ArcInspectors easier to get.

Le Botlan Didier 5 months ago
parent
commit
32f99dba49

+ 136
- 159
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/ArcInspectorFactory.java View File

@@ -12,6 +12,137 @@ import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
12 12
 
13 13
 public class ArcInspectorFactory {
14 14
 
15
+
16
+    // No filter (all arcs allowed):
17
+    static ArcInspector allArcsL = new ArcInspector() {
18
+        @Override
19
+        public boolean isAllowed(Arc arc) {
20
+            return true;
21
+        }
22
+
23
+        @Override
24
+        public double getCost(Arc arc) {
25
+            return arc.getLength();
26
+        }
27
+
28
+        /*
29
+        @Override
30
+        public int getMaximumSpeed() {
31
+            return GraphStatistics.NO_MAXIMUM_SPEED;
32
+        }
33
+        */
34
+
35
+        @Override
36
+        public Mode getMode() {
37
+            return Mode.LENGTH;
38
+        }
39
+
40
+        @Override
41
+        public String toString() {
42
+            return "Shortest path, all roads allowed";
43
+        }
44
+    } ;
45
+
46
+     // Only road allowed for cars and length:
47
+     static ArcInspector forCarsL = new ArcInspector() {
48
+      
49
+        @Override
50
+        public boolean isAllowed(Arc arc) {
51
+            return arc.getRoadInformation().getAccessRestrictions()
52
+                    .isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
53
+                            .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
54
+        }
55
+
56
+        @Override
57
+        public double getCost(Arc arc) {
58
+            return arc.getLength();
59
+        }
60
+
61
+        /*
62
+        @Override
63
+        public int getMaximumSpeed() {
64
+            return GraphStatistics.NO_MAXIMUM_SPEED;
65
+        }
66
+        */
67
+
68
+        @Override
69
+        public Mode getMode() {
70
+            return Mode.LENGTH;
71
+        }
72
+
73
+        @Override
74
+        public String toString() {
75
+            return "Shortest path, only roads open for cars";
76
+        }
77
+     } ;
78
+
79
+     // Only road allowed for cars and time:
80
+     static ArcInspector forCarsT = new ArcInspector() {
81
+
82
+        @Override
83
+        public boolean isAllowed(Arc arc) {
84
+            return true;
85
+        }
86
+
87
+        @Override
88
+        public double getCost(Arc arc) {
89
+            return arc.getMinimumTravelTime() ;
90
+        }
91
+
92
+        /*
93
+        @Override
94
+        public int getMaximumSpeed() {
95
+            return GraphStatistics.NO_MAXIMUM_SPEED;
96
+        }
97
+        */
98
+
99
+        @Override
100
+        public Mode getMode() {
101
+            return Mode.TIME ;
102
+        }
103
+
104
+        @Override
105
+        public String toString() {
106
+            return "Fastest path, all roads allowed";
107
+        }
108
+    } ;
109
+
110
+     // Non-private roads for pedestrian and bicycle:
111
+    static ArcInspector forBicyclesT = new ArcInspector() {
112
+        
113
+        static final int maxPedestrianSpeed = 5 ;
114
+        
115
+        @Override
116
+        public boolean isAllowed(Arc arc) {
117
+            return arc.getRoadInformation().getAccessRestrictions()
118
+                    .isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
119
+                            .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
120
+        }
121
+
122
+        @Override
123
+        public double getCost(Arc arc) {
124
+            return arc.getTravelTime(
125
+                    Math.min(maxPedestrianSpeed, arc.getRoadInformation().getMaximumSpeed()));
126
+        }
127
+
128
+        @Override
129
+        public String toString() {
130
+            return "Fastest path for pedestrian";
131
+        }
132
+
133
+        /*
134
+        @Override
135
+        public int getMaximumSpeed() {
136
+            return 5;
137
+        }
138
+        */
139
+        
140
+        @Override
141
+        public Mode getMode() {
142
+            return Mode.TIME;
143
+        }
144
+    } ;
145
+
15 146
     /**
16 147
      * @return List of all arc filters in this factory.
17 148
      */
@@ -20,165 +151,11 @@ public class ArcInspectorFactory {
20 151
 
21 152
         // Common filters:
22 153
 
23
-        // No filter (all arcs allowed):
24
-        filters.add(new ArcInspector() {
25
-            @Override
26
-            public boolean isAllowed(Arc arc) {
27
-                return true;
28
-            }
29
-
30
-            @Override
31
-            public double getCost(Arc arc) {
32
-                return arc.getLength();
33
-            }
34
-
35
-            /*
36
-            @Override
37
-            public int getMaximumSpeed() {
38
-                return GraphStatistics.NO_MAXIMUM_SPEED;
39
-            }
40
-            */
41
-
42
-            @Override
43
-            public Mode getMode() {
44
-                return Mode.LENGTH;
45
-            }
46
-
47
-            @Override
48
-            public String toString() {
49
-                return "Shortest path, all roads allowed";
50
-            }
51
-        });
52
-
53
-        // Only road allowed for cars and length:
54
-        filters.add(new ArcInspector() {
55
-            @Override
56
-            public boolean isAllowed(Arc arc) {
57
-                return arc.getRoadInformation().getAccessRestrictions()
58
-                        .isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
59
-                                .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
60
-            }
61
-
62
-            @Override
63
-            public double getCost(Arc arc) {
64
-                return arc.getLength();
65
-            }
66
-
67
-            /*
68
-            @Override
69
-            public int getMaximumSpeed() {
70
-                return GraphStatistics.NO_MAXIMUM_SPEED;
71
-            }
72
-            */
73
-
74
-            @Override
75
-            public Mode getMode() {
76
-                return Mode.LENGTH;
77
-            }
78
-
79
-            @Override
80
-            public String toString() {
81
-                return "Shortest path, only roads open for cars";
82
-            }
83
-        });
84
-
85
-        // Only road allowed for cars and time:
86
-
87
-        filters.add(new ArcInspector() {
88
-            @Override
89
-            public boolean isAllowed(Arc arc) {
90
-                return true;
91
-            }
92
-
93
-            @Override
94
-            public double getCost(Arc arc) {
95
-                return arc.getMinimumTravelTime();
96
-            }
97
-
98
-            /*
99
-            @Override
100
-            public int getMaximumSpeed() {
101
-                return GraphStatistics.NO_MAXIMUM_SPEED;
102
-            }
103
-            */
104
-
105
-            @Override
106
-            public Mode getMode() {
107
-                return Mode.TIME;
108
-            }
109
-
110
-            @Override
111
-            public String toString() {
112
-                return "Fastest path, all roads allowed";
113
-            }
114
-        });
115
-
116
-        filters.add(new ArcInspector() {
117
-            @Override
118
-            public boolean isAllowed(Arc arc) {
119
-                return arc.getRoadInformation().getAccessRestrictions()
120
-                        .isAllowedForAny(AccessMode.MOTORCAR, EnumSet.complementOf(EnumSet
121
-                                .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
122
-            }
123
-
124
-            @Override
125
-            public double getCost(Arc arc) {
126
-                return arc.getMinimumTravelTime();
127
-            }
128
-
129
-            /*
130
-            @Override
131
-            public int getMaximumSpeed() {
132
-                return GraphStatistics.NO_MAXIMUM_SPEED;
133
-            }
134
-            */
135
-            
136
-            @Override
137
-            public Mode getMode() {
138
-                return Mode.TIME;
139
-            }
140
-
141
-            @Override
142
-            public String toString() {
143
-                return "Fastest path, only roads open for cars";
144
-            }
145
-        });
146
-
147
-        // Non-private roads for pedestrian and bicycle:
148
-        filters.add(new ArcInspector() {
149
-
150
-            static final int maxPedestrianSpeed = 5 ;
151
-        	
152
-            @Override
153
-            public boolean isAllowed(Arc arc) {
154
-                return arc.getRoadInformation().getAccessRestrictions()
155
-                        .isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
156
-                                .of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));
157
-            }
158
-
159
-            @Override
160
-            public double getCost(Arc arc) {
161
-                return arc.getTravelTime(
162
-                        Math.min(maxPedestrianSpeed, arc.getRoadInformation().getMaximumSpeed()));
163
-            }
164
-
165
-            @Override
166
-            public String toString() {
167
-                return "Fastest path for pedestrian";
168
-            }
169
-
170
-            /*
171
-            @Override
172
-            public int getMaximumSpeed() {
173
-                return 5;
174
-            }
175
-            */
176
-            
177
-            @Override
178
-            public Mode getMode() {
179
-                return Mode.TIME;
180
-            }
181
-        });
154
+        
155
+        filters.add(allArcsL) ;
156
+        filters.add(forCarsL) ;
157
+        filters.add(forCarsT) ;
158
+        filters.add(forBicyclesT);
182 159
 
183 160
         // Add your own filters here (do not forget to implement toString()
184 161
         // to get an understandable output!):

+ 1
- 1
be-graphes-algos/src/main/java/org/insa/graphs/algorithm/utils/BinaryHeap.java View File

@@ -16,7 +16,7 @@ public class BinaryHeap<E extends Comparable<E>> implements PriorityQueue<E> {
16 16
     // Number of elements in heap.
17 17
     private int currentSize;
18 18
 
19
-    // The heap array.
19
+    // The heap array, which can be larger than currentSize.
20 20
     protected final ArrayList<E> array;
21 21
 
22 22
     /**

+ 1
- 1
be-graphes-gui/src/main/java/org/insa/graphs/gui/drawing/components/BasicDrawing.java View File

@@ -684,7 +684,7 @@ public class BasicDrawing extends JPanel implements Drawing {
684 684
                 // Draw arcs only if there are one-way arcs or if origin is lower than
685 685
                 // destination, avoid drawing two-ways arc twice.
686 686
                 if (arc.getRoadInformation().isOneWay()
687
-                        || arc.getOrigin().compareTo(arc.getDestination()) < 0) {
687
+                        || arc.getOrigin().getId() < arc.getDestination().getId()) {
688 688
                     drawArc(arc, palette, false);
689 689
                 }
690 690
             }

+ 6
- 5
be-graphes-model/src/main/java/org/insa/graphs/model/Node.java View File

@@ -19,7 +19,7 @@ import java.util.List;
19 19
  * </p>
20 20
  *
21 21
  */
22
-public final class Node implements Comparable<Node> {
22
+public final class Node { //implements Comparable<Node> {
23 23
 
24 24
     /**
25 25
      * <p>
@@ -144,6 +144,7 @@ public final class Node implements Comparable<Node> {
144 144
         return false;
145 145
     }
146 146
 
147
+    // Do we really need to compare nodes ? Confusion with Label comparisons.
147 148
     /**
148 149
      * Compare the ID of this node with the ID of the given node.
149 150
      * 
@@ -151,9 +152,9 @@ public final class Node implements Comparable<Node> {
151 152
      * 
152 153
      * @see java.lang.Comparable#compareTo(java.lang.Object)
153 154
      */
154
-    @Override
155
-    public int compareTo(Node other) {
156
-        return Integer.compare(getId(), other.getId());
157
-    }
155
+    // @Override
156
+    // public int compareTo(Node other) {
157
+    //     return Integer.compare(getId(), other.getId());
158
+    // }
158 159
 
159 160
 }

Loading…
Cancel
Save