Add algorithms for CarPooling and PackageSwitch.
This commit is contained in:
parent
f1d74d8040
commit
bcdaf54a63
24
src/main/org/insa/algo/carpooling/CarPoolingAlgorithm.java
Normal file
24
src/main/org/insa/algo/carpooling/CarPoolingAlgorithm.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
12
src/main/org/insa/algo/carpooling/CarPoolingData.java
Normal file
12
src/main/org/insa/algo/carpooling/CarPoolingData.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.carpooling;
|
||||
|
||||
public class CarPoolingGraphicObserver implements CarPoolingObserver {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.carpooling;
|
||||
|
||||
public interface CarPoolingObserver {
|
||||
|
||||
}
|
11
src/main/org/insa/algo/carpooling/CarPoolingSolution.java
Normal file
11
src/main/org/insa/algo/carpooling/CarPoolingSolution.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.carpooling;
|
||||
|
||||
public class CarPoolingTextObserver implements CarPoolingObserver {
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
12
src/main/org/insa/algo/packageswitch/PackageSwitchData.java
Normal file
12
src/main/org/insa/algo/packageswitch/PackageSwitchData.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.packageswitch;
|
||||
|
||||
public class PackageSwitchGraphicObserver implements PackageSwitchObserver {
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.packageswitch;
|
||||
|
||||
public interface PackageSwitchObserver {
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package org.insa.algo.packageswitch;
|
||||
|
||||
public class PackageSwitchTextObserver implements PackageSwitchObserver {
|
||||
|
||||
}
|
@ -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;
|
||||
@ -161,7 +163,7 @@ public class MainWindow extends JFrame {
|
||||
this.currentPalette = this.basicPalette;
|
||||
|
||||
wccPanel = new AlgorithmPanel(this, WeaklyConnectedComponentsAlgorithm.class,
|
||||
"Weakly-Connected Components", new String[] {}, false, false);
|
||||
"Weakly-Connected Components", new String[]{}, false, false);
|
||||
wccPanel.addStartActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
@ -206,7 +208,7 @@ public class MainWindow extends JFrame {
|
||||
});
|
||||
|
||||
spPanel = new AlgorithmPanel(this, ShortestPathAlgorithm.class, "Shortest-Path",
|
||||
new String[] { "Origin", "Destination" }, true, true);
|
||||
new String[]{ "Origin", "Destination" }, true, true);
|
||||
spPanel.addStartActionListener(new ActionListener() {
|
||||
@Override
|
||||
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
|
||||
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();
|
||||
|
@ -59,7 +59,7 @@ public class NodesInputPanel extends JPanel
|
||||
* @param point
|
||||
*
|
||||
* @return the closest node to the given point, or null if no node is "close
|
||||
* enough".
|
||||
* enough".
|
||||
*/
|
||||
public Node findClosestNode(Point point) {
|
||||
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
|
||||
* field is invalid.
|
||||
* field is invalid.
|
||||
*/
|
||||
protected Node getNodeForInput(JTextField textfield) {
|
||||
try {
|
||||
@ -307,7 +307,7 @@ public class NodesInputPanel extends JPanel
|
||||
|
||||
/**
|
||||
* @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() {
|
||||
List<Node> nodes = new ArrayList<>(nodeInputs.size());
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user