Browse Source

Add algorithms for CarPooling and PackageSwitch.

Mikael Capelle 6 years ago
parent
commit
bcdaf54a63

+ 24
- 0
src/main/org/insa/algo/carpooling/CarPoolingAlgorithm.java View File

@@ -0,0 +1,24 @@
1
+package org.insa.algo.carpooling;
2
+
3
+import org.insa.algo.AbstractAlgorithm;
4
+
5
+public abstract class CarPoolingAlgorithm extends AbstractAlgorithm<CarPoolingObserver> {
6
+
7
+    protected CarPoolingAlgorithm(CarPoolingData data) {
8
+        super(data);
9
+    }
10
+
11
+    @Override
12
+    public CarPoolingSolution run() {
13
+        return (CarPoolingSolution) super.run();
14
+    }
15
+
16
+    @Override
17
+    protected abstract CarPoolingSolution doRun();
18
+
19
+    @Override
20
+    public CarPoolingData getInputData() {
21
+        return (CarPoolingData) super.getInputData();
22
+    }
23
+
24
+}

+ 12
- 0
src/main/org/insa/algo/carpooling/CarPoolingData.java View File

@@ -0,0 +1,12 @@
1
+package org.insa.algo.carpooling;
2
+
3
+import org.insa.algo.AbstractInputData;
4
+import org.insa.graph.Graph;
5
+
6
+public class CarPoolingData extends AbstractInputData {
7
+
8
+    protected CarPoolingData(Graph graph, Mode mode, ArcFilter arcFilter) {
9
+        super(graph, mode, arcFilter);
10
+    }
11
+
12
+}

+ 5
- 0
src/main/org/insa/algo/carpooling/CarPoolingGraphicObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.carpooling;
2
+
3
+public class CarPoolingGraphicObserver implements CarPoolingObserver {
4
+
5
+}

+ 5
- 0
src/main/org/insa/algo/carpooling/CarPoolingObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.carpooling;
2
+
3
+public interface CarPoolingObserver {
4
+
5
+}

+ 11
- 0
src/main/org/insa/algo/carpooling/CarPoolingSolution.java View File

@@ -0,0 +1,11 @@
1
+package org.insa.algo.carpooling;
2
+
3
+import org.insa.algo.AbstractSolution;
4
+
5
+public class CarPoolingSolution extends AbstractSolution {
6
+
7
+    protected CarPoolingSolution(CarPoolingData data, Status status) {
8
+        super(data, status);
9
+    }
10
+
11
+}

+ 5
- 0
src/main/org/insa/algo/carpooling/CarPoolingTextObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.carpooling;
2
+
3
+public class CarPoolingTextObserver implements CarPoolingObserver {
4
+
5
+}

+ 29
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchAlgorithm.java View File

@@ -0,0 +1,29 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+import org.insa.algo.AbstractAlgorithm;
4
+
5
+public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm<PackageSwitchObserver> {
6
+
7
+    /**
8
+     * Create a new PackageSwitchAlgorithm with the given data.
9
+     * 
10
+     * @param data
11
+     */
12
+    protected PackageSwitchAlgorithm(PackageSwitchData data) {
13
+        super(data);
14
+    }
15
+
16
+    @Override
17
+    public PackageSwitchSolution run() {
18
+        return (PackageSwitchSolution) super.run();
19
+    }
20
+
21
+    @Override
22
+    protected abstract PackageSwitchSolution doRun();
23
+
24
+    @Override
25
+    public PackageSwitchData getInputData() {
26
+        return (PackageSwitchData) super.getInputData();
27
+    }
28
+
29
+}

+ 12
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchData.java View File

@@ -0,0 +1,12 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+import org.insa.algo.AbstractInputData;
4
+import org.insa.graph.Graph;
5
+
6
+public class PackageSwitchData extends AbstractInputData {
7
+
8
+    protected PackageSwitchData(Graph graph, Mode mode, ArcFilter arcFilter) {
9
+        super(graph, mode, arcFilter);
10
+    }
11
+
12
+}

+ 5
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchGraphicObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+public class PackageSwitchGraphicObserver implements PackageSwitchObserver {
4
+
5
+}

+ 5
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+public interface PackageSwitchObserver {
4
+
5
+}

+ 11
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchSolution.java View File

@@ -0,0 +1,11 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+import org.insa.algo.AbstractSolution;
4
+
5
+public class PackageSwitchSolution extends AbstractSolution {
6
+
7
+    protected PackageSwitchSolution(PackageSwitchData data, Status status) {
8
+        super(data, status);
9
+    }
10
+
11
+}

+ 5
- 0
src/main/org/insa/algo/packageswitch/PackageSwitchTextObserver.java View File

@@ -0,0 +1,5 @@
1
+package org.insa.algo.packageswitch;
2
+
3
+public class PackageSwitchTextObserver implements PackageSwitchObserver {
4
+
5
+}

+ 49
- 10
src/main/org/insa/graphics/MainWindow.java View File

@@ -44,6 +44,8 @@ import javax.swing.filechooser.FileNameExtensionFilter;
44 44
 
45 45
 import org.insa.algo.AbstractSolution;
46 46
 import org.insa.algo.AlgorithmFactory;
47
+import org.insa.algo.carpooling.CarPoolingAlgorithm;
48
+import org.insa.algo.packageswitch.PackageSwitchAlgorithm;
47 49
 import org.insa.algo.shortestpath.ShortestPathAlgorithm;
48 50
 import org.insa.algo.shortestpath.ShortestPathData;
49 51
 import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
@@ -112,7 +114,7 @@ public class MainWindow extends JFrame {
112 114
 
113 115
     // Algorithm panels
114 116
     private final List<AlgorithmPanel> algoPanels = new ArrayList<>();
115
-    private final AlgorithmPanel wccPanel, spPanel;
117
+    private final AlgorithmPanel wccPanel, spPanel, cpPanel, psPanel;
116 118
 
117 119
     // Path panel
118 120
     private final PathsPanel pathPanel;
@@ -161,7 +163,7 @@ public class MainWindow extends JFrame {
161 163
         this.currentPalette = this.basicPalette;
162 164
 
163 165
         wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class,
164
-                "Weakly-Connected Components", new String[] {}, false, false);
166
+                "Weakly-Connected Components", new String[]{}, false, false);
165 167
         wccPanel.addStartActionListener(new ActionListener() {
166 168
             @Override
167 169
             public void actionPerformed(ActionEvent e) {
@@ -206,7 +208,7 @@ public class MainWindow extends JFrame {
206 208
         });
207 209
 
208 210
         spPanel = new AlgorithmPanel(this, ShortestPathAlgorithm.class, "Shortest-Path",
209
-                new String[] { "Origin", "Destination" }, true, true);
211
+                new String[]{ "Origin", "Destination" }, true, true);
210 212
         spPanel.addStartActionListener(new ActionListener() {
211 213
             @Override
212 214
             public void actionPerformed(ActionEvent e) {
@@ -258,21 +260,35 @@ public class MainWindow extends JFrame {
258 260
             }
259 261
         });
260 262
 
263
+        cpPanel = new AlgorithmPanel(
264
+                this, CarPoolingAlgorithm.class, "Car-Pooling", new String[]{ "Origin Car",
265
+                        "Origin Pedestrian", "Destination Car", "Destination Pedestrian" },
266
+                true, true);
267
+
268
+        psPanel = new AlgorithmPanel(this, PackageSwitchAlgorithm.class, "Car-Pooling",
269
+                new String[]{ "Oribin A", "Origin B", "Destination A", "Destination B" }, true,
270
+                true);
271
+
261 272
         // add algorithm panels
262 273
         algoPanels.add(wccPanel);
263 274
         algoPanels.add(spPanel);
275
+        algoPanels.add(cpPanel);
276
+        algoPanels.add(psPanel);
264 277
 
265 278
         this.pathPanel = new PathsPanel(this);
266 279
 
267 280
         // Add click listeners to both drawing.
268
-        basicDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
269
-        mapViewDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
270 281
 
271
-        this.graphChangeListeneres.add(spPanel.nodesInputPanel);
272
-        this.graphChangeListeneres.add(spPanel.solutionPanel);
282
+        for (AlgorithmPanel panel: algoPanels) {
283
+            this.basicDrawing.addDrawingClickListener(panel.nodesInputPanel);
284
+            this.mapViewDrawing.addDrawingClickListener(panel.nodesInputPanel);
285
+            this.graphChangeListeneres.add(panel.nodesInputPanel);
286
+            this.graphChangeListeneres.add(panel.solutionPanel);
287
+            this.drawingChangeListeners.add(panel.nodesInputPanel);
288
+            this.drawingChangeListeners.add(panel.solutionPanel);
289
+        }
290
+
273 291
         this.graphChangeListeneres.add(pathPanel);
274
-        this.drawingChangeListeners.add(spPanel.nodesInputPanel);
275
-        this.drawingChangeListeners.add(spPanel.solutionPanel);
276 292
         this.drawingChangeListeners.add(pathPanel);
277 293
 
278 294
         // Create action factory.
@@ -738,19 +754,42 @@ public class MainWindow extends JFrame {
738 754
         }));
739 755
 
740 756
         // Shortest path
741
-        JMenuItem spItem = new JMenuItem("Shortest Path");
757
+        JMenuItem spItem = new JMenuItem("Shortest-Path");
742 758
         spItem.addActionListener(baf.createBlockingAction(new ActionListener() {
743 759
             @Override
744 760
             public void actionPerformed(ActionEvent e) {
745 761
                 enableAlgorithmPanel(spPanel);
746 762
             }
747 763
         }));
764
+
765
+        // Car pooling
766
+        JMenuItem cpItem = new JMenuItem("Car Pooling");
767
+        cpItem.addActionListener(baf.createBlockingAction(new ActionListener() {
768
+            @Override
769
+            public void actionPerformed(ActionEvent e) {
770
+                enableAlgorithmPanel(cpPanel);
771
+            }
772
+        }));
773
+
774
+        // Car pooling
775
+        JMenuItem psItem = new JMenuItem("Package Switch");
776
+        psItem.addActionListener(baf.createBlockingAction(new ActionListener() {
777
+            @Override
778
+            public void actionPerformed(ActionEvent e) {
779
+                enableAlgorithmPanel(psPanel);
780
+            }
781
+        }));
782
+
748 783
         graphLockItems.add(wccItem);
749 784
         graphLockItems.add(spItem);
785
+        graphLockItems.add(cpItem);
786
+        graphLockItems.add(psItem);
750 787
 
751 788
         algoMenu.add(wccItem);
752 789
         algoMenu.addSeparator();
753 790
         algoMenu.add(spItem);
791
+        algoMenu.add(cpItem);
792
+        algoMenu.add(psItem);
754 793
 
755 794
         // Create the menu bar.
756 795
         JMenuBar menuBar = new JMenuBar();

+ 3
- 3
src/main/org/insa/graphics/NodesInputPanel.java View File

@@ -59,7 +59,7 @@ public class NodesInputPanel extends JPanel
59 59
          * @param point
60 60
          * 
61 61
          * @return the closest node to the given point, or null if no node is "close
62
-         *         enough".
62
+         * enough".
63 63
          */
64 64
         public Node findClosestNode(Point point) {
65 65
             Node minNode = null;
@@ -293,7 +293,7 @@ public class NodesInputPanel extends JPanel
293 293
 
294 294
     /**
295 295
      * @return The node for the given text field, or null if the content of the text
296
-     *         field is invalid.
296
+     * field is invalid.
297 297
      */
298 298
     protected Node getNodeForInput(JTextField textfield) {
299 299
         try {
@@ -307,7 +307,7 @@ public class NodesInputPanel extends JPanel
307 307
 
308 308
     /**
309 309
      * @return List of nodes associated with the input. Some nodes may be null if
310
-     *         their associated input is invalid.
310
+     * their associated input is invalid.
311 311
      */
312 312
     public List<Node> getNodeForInputs() {
313 313
         List<Node> nodes = new ArrayList<>(nodeInputs.size());

+ 0
- 4
src/main/org/insa/graphics/PathsPanel.java View File

@@ -162,7 +162,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
162 162
             colorButton = new JButton(icon);
163 163
             colorButton.setFocusable(false);
164 164
             colorButton.setFocusPainted(false);
165
-            colorButton.setBorderPainted(false);
166 165
             colorButton.setMinimumSize(size);
167 166
             colorButton.setPreferredSize(size);
168 167
             colorButton.setMaximumSize(size);
@@ -211,7 +210,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
211 210
             JButton saveButton = new JButton(UIManager.getIcon("FileView.floppyDriveIcon"));
212 211
             saveButton.setFocusPainted(false);
213 212
             saveButton.setFocusable(false);
214
-            saveButton.setBorderPainted(false);
215 213
             saveButton.setMinimumSize(size);
216 214
             saveButton.setPreferredSize(size);
217 215
             saveButton.setMaximumSize(size);
@@ -249,7 +247,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
249 247
             JButton deleteButton = new JButton(new ImageIcon(newimg));
250 248
             deleteButton.setFocusPainted(false);
251 249
             deleteButton.setFocusable(false);
252
-            deleteButton.setBorderPainted(false);
253 250
             deleteButton.setMinimumSize(size);
254 251
             deleteButton.setPreferredSize(size);
255 252
             deleteButton.setMaximumSize(size);
@@ -287,7 +284,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
287 284
 
288 285
         /*
289 286
          * (non-Javadoc)
290
-         * 
291 287
          * @see java.lang.Object#toString()
292 288
          */
293 289
         public String toString() {

Loading…
Cancel
Save