|
@@ -5,6 +5,7 @@ import java.awt.Component;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.FlowLayout;
|
|
|
import java.awt.Font;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.BufferedWriter;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
@@ -19,12 +20,14 @@ import java.util.Locale;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
|
+import javax.swing.ImageIcon;
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JCheckBox;
|
|
|
import javax.swing.JFileChooser;
|
|
|
import javax.swing.JFormattedTextField;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JSplitPane;
|
|
@@ -34,6 +37,7 @@ import javax.swing.text.NumberFormatter;
|
|
|
|
|
|
import api.Algorithm;
|
|
|
import classes.AbstractCpsObject;
|
|
|
+import classes.CpsEdge;
|
|
|
import classes.CpsUpperNode;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
@@ -42,17 +46,26 @@ import classes.HolonSwitch;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
import ui.model.DecoratedHolonObject.HolonObjectState;
|
|
|
+import ui.model.DecoratedGroupNode;
|
|
|
import ui.model.DecoratedNetwork;
|
|
|
import ui.model.DecoratedState;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public class PSOAlgotihm implements Algorithm {
|
|
|
//Parameter for Algo with default Values:
|
|
|
private int swarmSize = 20;
|
|
|
private int maxIterations = 100;
|
|
|
- private double limit = 0.3;
|
|
|
+ private double limit = 0.01;
|
|
|
private double dependency = 2.07;
|
|
|
private int rounds = 20;
|
|
|
+
|
|
|
+ //Settings For GroupNode using and plotting
|
|
|
private boolean append = false;
|
|
|
+ private boolean useGroupNode = false;
|
|
|
+ private DecoratedGroupNode dGroupNode = null;
|
|
|
|
|
|
//Parameter defined by Algo
|
|
|
private HashMap<Integer, AccessWrapper> access;
|
|
@@ -113,17 +126,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
JLabel swarmSizeLabel = new JLabel("Swarm Size:");
|
|
|
swarmSizeLabel.setBounds(20, 60, 100, 20);
|
|
|
parameterPanel.add(swarmSizeLabel);
|
|
|
-
|
|
|
- JLabel showDiagnosticsLabel = new JLabel("Append Plott on existing File:");
|
|
|
- showDiagnosticsLabel.setBounds(200, 60, 170, 20);
|
|
|
- parameterPanel.add(showDiagnosticsLabel);
|
|
|
-
|
|
|
- JLabel cautionLabel = new JLabel(
|
|
|
- "Caution: High values in the fields of 'Swarm Size' and 'Max. Iteration' may take some time to calculate.");
|
|
|
- cautionLabel.setFont(new Font("Serif", Font.ITALIC, 12));
|
|
|
- cautionLabel.setBounds(10, 210, 500, 15);
|
|
|
- parameterPanel.add(cautionLabel);
|
|
|
-
|
|
|
+
|
|
|
JLabel maxIterLabel = new JLabel("Max. Iterations:");
|
|
|
maxIterLabel.setBounds(20, 85, 100, 20);
|
|
|
parameterPanel.add(maxIterLabel);
|
|
@@ -140,6 +143,41 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
roundsLabel.setBounds(20, 160, 100, 20);
|
|
|
parameterPanel.add(roundsLabel);
|
|
|
|
|
|
+ JLabel cautionLabel = new JLabel(
|
|
|
+ "Caution: High values in the fields of 'Swarm Size' and 'Max. Iteration' may take some time to calculate.");
|
|
|
+ cautionLabel.setFont(new Font("Serif", Font.ITALIC, 12));
|
|
|
+
|
|
|
+ JLabel showDiagnosticsLabel = new JLabel("Append Plott on existing File:");
|
|
|
+ showDiagnosticsLabel.setBounds(200, 60, 170, 20);
|
|
|
+ parameterPanel.add(showDiagnosticsLabel);
|
|
|
+
|
|
|
+ JPanel borderPanel = new JPanel(null);
|
|
|
+ borderPanel.setBounds(200, 85, 185, 50);
|
|
|
+ borderPanel.setBorder(BorderFactory.createTitledBorder(""));
|
|
|
+ parameterPanel.add(borderPanel);
|
|
|
+
|
|
|
+ JLabel showGroupNodeLabel = new JLabel("Use Group Node:");
|
|
|
+ showGroupNodeLabel.setBounds(10, 1, 170, 20);
|
|
|
+ borderPanel.add(showGroupNodeLabel);
|
|
|
+
|
|
|
+ JButton selectGroupNodeButton = new JButton("Select GroupNode");
|
|
|
+ selectGroupNodeButton.setEnabled(false);
|
|
|
+ selectGroupNodeButton.setBounds(10, 25, 165, 20);
|
|
|
+ selectGroupNodeButton.addActionListener(actionEvent -> selectGroupNode());
|
|
|
+ borderPanel.add(selectGroupNodeButton);
|
|
|
+
|
|
|
+ JCheckBox useGroupNodeCheckBox = new JCheckBox();
|
|
|
+ useGroupNodeCheckBox.setSelected(false);
|
|
|
+ useGroupNodeCheckBox.setBounds(155, 1, 25, 20);
|
|
|
+ useGroupNodeCheckBox.addPropertyChangeListener(propertyChange -> {
|
|
|
+ useGroupNode = useGroupNodeCheckBox.isSelected();
|
|
|
+ selectGroupNodeButton.setEnabled(useGroupNode);
|
|
|
+ });
|
|
|
+ borderPanel.add(useGroupNodeCheckBox);
|
|
|
+
|
|
|
+
|
|
|
+ cautionLabel.setBounds(10, 210, 500, 15);
|
|
|
+ parameterPanel.add(cautionLabel);
|
|
|
|
|
|
JCheckBox diagnosticsCheckBox = new JCheckBox();
|
|
|
diagnosticsCheckBox.setSelected(false);
|
|
@@ -147,6 +185,8 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
diagnosticsCheckBox.addPropertyChangeListener(propertyChange -> append = diagnosticsCheckBox.isSelected());
|
|
|
parameterPanel.add(diagnosticsCheckBox);
|
|
|
|
|
|
+
|
|
|
+
|
|
|
//Integer formatter
|
|
|
NumberFormat format = NumberFormat.getIntegerInstance();
|
|
|
format.setGroupingUsed(false);
|
|
@@ -281,6 +321,15 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
private void println(String message) {
|
|
|
textArea.append(message + "\n");
|
|
|
}
|
|
|
+ private void selectGroupNode() {
|
|
|
+ Object[] possibilities = control.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
|
|
|
+ if(selected != null) {
|
|
|
+ println("Selected: " + selected);
|
|
|
+ dGroupNode = selected.object;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -584,7 +633,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
private List<Boolean> extractPositionAndAccess(Model model) {
|
|
|
initialState = new ArrayList<Boolean>();
|
|
|
access= new HashMap<Integer, AccessWrapper>();
|
|
|
- rollOutNodes(model.getObjectsOnCanvas(), initialState, model.getCurIteration());
|
|
|
+ rollOutNodes((useGroupNode && (dGroupNode != null))? dGroupNode.getModel().getNodes() :model.getObjectsOnCanvas(), initialState, model.getCurIteration());
|
|
|
return initialState;
|
|
|
}
|
|
|
/**
|
|
@@ -804,4 +853,15 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private class Handle<T>{
|
|
|
+ public T object;
|
|
|
+ Handle(T object){
|
|
|
+ this.object = object;
|
|
|
+ }
|
|
|
+ public String toString() {
|
|
|
+ return object.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|