Add algorithms for CarPooling and PackageSwitch.

This commit is contained in:
Mikael Capelle 2018-03-07 14:47:22 +01:00
parent f1d74d8040
commit bcdaf54a63
15 changed files with 181 additions and 17 deletions

View File

@ -0,0 +1,24 @@
package org.insa.algo.carpooling;
import org.insa.algo.AbstractAlgorithm;
public abstract class CarPoolingAlgorithm extends AbstractAlgorithm<CarPoolingObserver> {
protected CarPoolingAlgorithm(CarPoolingData data) {
super(data);
}
@Override
public CarPoolingSolution run() {
return (CarPoolingSolution) super.run();
}
@Override
protected abstract CarPoolingSolution doRun();
@Override
public CarPoolingData getInputData() {
return (CarPoolingData) super.getInputData();
}
}

View File

@ -0,0 +1,12 @@
package org.insa.algo.carpooling;
import org.insa.algo.AbstractInputData;
import org.insa.graph.Graph;
public class CarPoolingData extends AbstractInputData {
protected CarPoolingData(Graph graph, Mode mode, ArcFilter arcFilter) {
super(graph, mode, arcFilter);
}
}

View File

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

View File

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

View File

@ -0,0 +1,11 @@
package org.insa.algo.carpooling;
import org.insa.algo.AbstractSolution;
public class CarPoolingSolution extends AbstractSolution {
protected CarPoolingSolution(CarPoolingData data, Status status) {
super(data, status);
}
}

View File

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

View File

@ -0,0 +1,29 @@
package org.insa.algo.packageswitch;
import org.insa.algo.AbstractAlgorithm;
public abstract class PackageSwitchAlgorithm extends AbstractAlgorithm<PackageSwitchObserver> {
/**
* Create a new PackageSwitchAlgorithm with the given data.
*
* @param data
*/
protected PackageSwitchAlgorithm(PackageSwitchData data) {
super(data);
}
@Override
public PackageSwitchSolution run() {
return (PackageSwitchSolution) super.run();
}
@Override
protected abstract PackageSwitchSolution doRun();
@Override
public PackageSwitchData getInputData() {
return (PackageSwitchData) super.getInputData();
}
}

View File

@ -0,0 +1,12 @@
package org.insa.algo.packageswitch;
import org.insa.algo.AbstractInputData;
import org.insa.graph.Graph;
public class PackageSwitchData extends AbstractInputData {
protected PackageSwitchData(Graph graph, Mode mode, ArcFilter arcFilter) {
super(graph, mode, arcFilter);
}
}

View File

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

View File

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

View File

@ -0,0 +1,11 @@
package org.insa.algo.packageswitch;
import org.insa.algo.AbstractSolution;
public class PackageSwitchSolution extends AbstractSolution {
protected PackageSwitchSolution(PackageSwitchData data, Status status) {
super(data, status);
}
}

View File

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

View File

@ -44,6 +44,8 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import org.insa.algo.AbstractSolution;
import org.insa.algo.AlgorithmFactory;
import org.insa.algo.carpooling.CarPoolingAlgorithm;
import org.insa.algo.packageswitch.PackageSwitchAlgorithm;
import org.insa.algo.shortestpath.ShortestPathAlgorithm;
import org.insa.algo.shortestpath.ShortestPathData;
import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
@ -112,7 +114,7 @@ public class MainWindow extends JFrame {
// Algorithm panels
private final List<AlgorithmPanel> algoPanels = new ArrayList<>();
private final AlgorithmPanel wccPanel, spPanel;
private final AlgorithmPanel wccPanel, spPanel, cpPanel, psPanel;
// Path panel
private final PathsPanel pathPanel;
@ -258,21 +260,35 @@ public class MainWindow extends JFrame {
}
});
cpPanel = new AlgorithmPanel(
this, CarPoolingAlgorithm.class, "Car-Pooling", new String[]{ "Origin Car",
"Origin Pedestrian", "Destination Car", "Destination Pedestrian" },
true, true);
psPanel = new AlgorithmPanel(this, PackageSwitchAlgorithm.class, "Car-Pooling",
new String[]{ "Oribin A", "Origin B", "Destination A", "Destination B" }, true,
true);
// add algorithm panels
algoPanels.add(wccPanel);
algoPanels.add(spPanel);
algoPanels.add(cpPanel);
algoPanels.add(psPanel);
this.pathPanel = new PathsPanel(this);
// Add click listeners to both drawing.
basicDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
mapViewDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
this.graphChangeListeneres.add(spPanel.nodesInputPanel);
this.graphChangeListeneres.add(spPanel.solutionPanel);
for (AlgorithmPanel panel: algoPanels) {
this.basicDrawing.addDrawingClickListener(panel.nodesInputPanel);
this.mapViewDrawing.addDrawingClickListener(panel.nodesInputPanel);
this.graphChangeListeneres.add(panel.nodesInputPanel);
this.graphChangeListeneres.add(panel.solutionPanel);
this.drawingChangeListeners.add(panel.nodesInputPanel);
this.drawingChangeListeners.add(panel.solutionPanel);
}
this.graphChangeListeneres.add(pathPanel);
this.drawingChangeListeners.add(spPanel.nodesInputPanel);
this.drawingChangeListeners.add(spPanel.solutionPanel);
this.drawingChangeListeners.add(pathPanel);
// Create action factory.
@ -738,19 +754,42 @@ public class MainWindow extends JFrame {
}));
// Shortest path
JMenuItem spItem = new JMenuItem("Shortest Path");
JMenuItem spItem = new JMenuItem("Shortest-Path");
spItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableAlgorithmPanel(spPanel);
}
}));
// Car pooling
JMenuItem cpItem = new JMenuItem("Car Pooling");
cpItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableAlgorithmPanel(cpPanel);
}
}));
// Car pooling
JMenuItem psItem = new JMenuItem("Package Switch");
psItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableAlgorithmPanel(psPanel);
}
}));
graphLockItems.add(wccItem);
graphLockItems.add(spItem);
graphLockItems.add(cpItem);
graphLockItems.add(psItem);
algoMenu.add(wccItem);
algoMenu.addSeparator();
algoMenu.add(spItem);
algoMenu.add(cpItem);
algoMenu.add(psItem);
// Create the menu bar.
JMenuBar menuBar = new JMenuBar();

View File

@ -162,7 +162,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
colorButton = new JButton(icon);
colorButton.setFocusable(false);
colorButton.setFocusPainted(false);
colorButton.setBorderPainted(false);
colorButton.setMinimumSize(size);
colorButton.setPreferredSize(size);
colorButton.setMaximumSize(size);
@ -211,7 +210,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
JButton saveButton = new JButton(UIManager.getIcon("FileView.floppyDriveIcon"));
saveButton.setFocusPainted(false);
saveButton.setFocusable(false);
saveButton.setBorderPainted(false);
saveButton.setMinimumSize(size);
saveButton.setPreferredSize(size);
saveButton.setMaximumSize(size);
@ -249,7 +247,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
JButton deleteButton = new JButton(new ImageIcon(newimg));
deleteButton.setFocusPainted(false);
deleteButton.setFocusable(false);
deleteButton.setBorderPainted(false);
deleteButton.setMinimumSize(size);
deleteButton.setPreferredSize(size);
deleteButton.setMaximumSize(size);
@ -287,7 +284,6 @@ public class PathsPanel extends JPanel implements DrawingChangeListener, GraphCh
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {