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.AbstractSolution;
import org.insa.algo.AlgorithmFactory; 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.ShortestPathAlgorithm;
import org.insa.algo.shortestpath.ShortestPathData; import org.insa.algo.shortestpath.ShortestPathData;
import org.insa.algo.shortestpath.ShortestPathGraphicObserver; import org.insa.algo.shortestpath.ShortestPathGraphicObserver;
@ -112,7 +114,7 @@ public class MainWindow extends JFrame {
// Algorithm panels // Algorithm panels
private final List<AlgorithmPanel> algoPanels = new ArrayList<>(); private final List<AlgorithmPanel> algoPanels = new ArrayList<>();
private final AlgorithmPanel wccPanel, spPanel; private final AlgorithmPanel wccPanel, spPanel, cpPanel, psPanel;
// Path panel // Path panel
private final PathsPanel pathPanel; private final PathsPanel pathPanel;
@ -161,7 +163,7 @@ public class MainWindow extends JFrame {
this.currentPalette = this.basicPalette; this.currentPalette = this.basicPalette;
wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class, wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class,
"Weakly-Connected Components", new String[] {}, false, false); "Weakly-Connected Components", new String[]{}, false, false);
wccPanel.addStartActionListener(new ActionListener() { wccPanel.addStartActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -206,7 +208,7 @@ public class MainWindow extends JFrame {
}); });
spPanel = new AlgorithmPanel(this, ShortestPathAlgorithm.class, "Shortest-Path", spPanel = new AlgorithmPanel(this, ShortestPathAlgorithm.class, "Shortest-Path",
new String[] { "Origin", "Destination" }, true, true); new String[]{ "Origin", "Destination" }, true, true);
spPanel.addStartActionListener(new ActionListener() { spPanel.addStartActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
@ -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 // add algorithm panels
algoPanels.add(wccPanel); algoPanels.add(wccPanel);
algoPanels.add(spPanel); algoPanels.add(spPanel);
algoPanels.add(cpPanel);
algoPanels.add(psPanel);
this.pathPanel = new PathsPanel(this); this.pathPanel = new PathsPanel(this);
// Add click listeners to both drawing. // Add click listeners to both drawing.
basicDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
mapViewDrawing.addDrawingClickListener(spPanel.nodesInputPanel);
this.graphChangeListeneres.add(spPanel.nodesInputPanel); for (AlgorithmPanel panel: algoPanels) {
this.graphChangeListeneres.add(spPanel.solutionPanel); 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.graphChangeListeneres.add(pathPanel);
this.drawingChangeListeners.add(spPanel.nodesInputPanel);
this.drawingChangeListeners.add(spPanel.solutionPanel);
this.drawingChangeListeners.add(pathPanel); this.drawingChangeListeners.add(pathPanel);
// Create action factory. // Create action factory.
@ -738,19 +754,42 @@ public class MainWindow extends JFrame {
})); }));
// Shortest path // Shortest path
JMenuItem spItem = new JMenuItem("Shortest Path"); JMenuItem spItem = new JMenuItem("Shortest-Path");
spItem.addActionListener(baf.createBlockingAction(new ActionListener() { spItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
enableAlgorithmPanel(spPanel); 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(wccItem);
graphLockItems.add(spItem); graphLockItems.add(spItem);
graphLockItems.add(cpItem);
graphLockItems.add(psItem);
algoMenu.add(wccItem); algoMenu.add(wccItem);
algoMenu.addSeparator(); algoMenu.addSeparator();
algoMenu.add(spItem); algoMenu.add(spItem);
algoMenu.add(cpItem);
algoMenu.add(psItem);
// Create the menu bar. // Create the menu bar.
JMenuBar menuBar = new JMenuBar(); JMenuBar menuBar = new JMenuBar();

View File

@ -59,7 +59,7 @@ public class NodesInputPanel extends JPanel
* @param point * @param point
* *
* @return the closest node to the given point, or null if no node is "close * @return the closest node to the given point, or null if no node is "close
* enough". * enough".
*/ */
public Node findClosestNode(Point point) { public Node findClosestNode(Point point) {
Node minNode = null; Node minNode = null;
@ -293,7 +293,7 @@ public class NodesInputPanel extends JPanel
/** /**
* @return The node for the given text field, or null if the content of the text * @return The node for the given text field, or null if the content of the text
* field is invalid. * field is invalid.
*/ */
protected Node getNodeForInput(JTextField textfield) { protected Node getNodeForInput(JTextField textfield) {
try { try {
@ -307,7 +307,7 @@ public class NodesInputPanel extends JPanel
/** /**
* @return List of nodes associated with the input. Some nodes may be null if * @return List of nodes associated with the input. Some nodes may be null if
* their associated input is invalid. * their associated input is invalid.
*/ */
public List<Node> getNodeForInputs() { public List<Node> getNodeForInputs() {
List<Node> nodes = new ArrayList<>(nodeInputs.size()); List<Node> nodes = new ArrayList<>(nodeInputs.size());

View File

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