|
@@ -2,6 +2,7 @@ package exampleAlgorithms;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
|
import java.awt.Component;
|
|
|
+import java.awt.Cursor;
|
|
|
import java.awt.Dimension;
|
|
|
import java.awt.FlowLayout;
|
|
|
import java.awt.Font;
|
|
@@ -29,6 +30,7 @@ import javax.swing.JFrame;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
+import javax.swing.JProgressBar;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JSplitPane;
|
|
|
import javax.swing.JTextArea;
|
|
@@ -37,12 +39,10 @@ import javax.swing.text.NumberFormatter;
|
|
|
|
|
|
import api.Algorithm;
|
|
|
import classes.AbstractCpsObject;
|
|
|
-import classes.CpsEdge;
|
|
|
import classes.CpsUpperNode;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
-
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
import ui.model.DecoratedHolonObject.HolonObjectState;
|
|
@@ -82,6 +82,11 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
private Control control;
|
|
|
private JTextArea textArea;
|
|
|
private JPanel content = new JPanel();
|
|
|
+ //ProgressBar
|
|
|
+ private JProgressBar progressBar = new JProgressBar();
|
|
|
+ private int progressBarCount = 0;
|
|
|
+ private long startTime;
|
|
|
+
|
|
|
public static void main(String[] args)
|
|
|
{
|
|
|
JFrame newFrame = new JFrame("exampleWindow");
|
|
@@ -169,12 +174,21 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
JCheckBox useGroupNodeCheckBox = new JCheckBox();
|
|
|
useGroupNodeCheckBox.setSelected(false);
|
|
|
useGroupNodeCheckBox.setBounds(155, 1, 25, 20);
|
|
|
- useGroupNodeCheckBox.addPropertyChangeListener(propertyChange -> {
|
|
|
+ useGroupNodeCheckBox.addActionListener(actionEvent -> {
|
|
|
+
|
|
|
useGroupNode = useGroupNodeCheckBox.isSelected();
|
|
|
+ println("" + useGroupNode);
|
|
|
selectGroupNodeButton.setEnabled(useGroupNode);
|
|
|
});
|
|
|
borderPanel.add(useGroupNodeCheckBox);
|
|
|
|
|
|
+ JLabel progressLabel = new JLabel("Progress:");
|
|
|
+ progressLabel.setBounds(200, 135, 170, 20);
|
|
|
+ parameterPanel.add(progressLabel);
|
|
|
+
|
|
|
+ progressBar.setBounds(200, 155, 185, 20);
|
|
|
+ progressBar.setStringPainted(true);
|
|
|
+ parameterPanel.add(progressBar);
|
|
|
|
|
|
cautionLabel.setBounds(10, 210, 500, 15);
|
|
|
parameterPanel.add(cautionLabel);
|
|
@@ -182,7 +196,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
JCheckBox diagnosticsCheckBox = new JCheckBox();
|
|
|
diagnosticsCheckBox.setSelected(false);
|
|
|
diagnosticsCheckBox.setBounds(370, 60, 25, 20);
|
|
|
- diagnosticsCheckBox.addPropertyChangeListener(propertyChange -> append = diagnosticsCheckBox.isSelected());
|
|
|
+ diagnosticsCheckBox.addActionListener(actionEvent -> {append = diagnosticsCheckBox.isSelected();println("" + useGroupNode);});
|
|
|
parameterPanel.add(diagnosticsCheckBox);
|
|
|
|
|
|
|
|
@@ -199,7 +213,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
JFormattedTextField swarmSizeTextField = new JFormattedTextField(integerFormatter);
|
|
|
swarmSizeTextField.setValue(swarmSize);
|
|
|
swarmSizeTextField.setToolTipText("Only positive Integer.");
|
|
|
- swarmSizeTextField.addPropertyChangeListener(propertyChange -> swarmSize = Integer.parseInt(swarmSizeTextField.getValue().toString()));
|
|
|
+ swarmSizeTextField.addActionListener(actionEvent -> swarmSize = Integer.parseInt(swarmSizeTextField.getValue().toString()));
|
|
|
swarmSizeTextField.setBounds(125, 60, 50, 20);
|
|
|
parameterPanel.add(swarmSizeTextField);
|
|
|
|
|
@@ -261,6 +275,9 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
JButton folderButton = new JButton("Change Plott-File");
|
|
|
folderButton.addActionListener(actionEvent -> setSaveFile());
|
|
|
buttonPanel.add(folderButton);
|
|
|
+ JButton fitnessButton = new JButton("Actual Fitness");
|
|
|
+ fitnessButton.addActionListener(actionEvent -> fitness());
|
|
|
+ buttonPanel.add(fitnessButton);
|
|
|
JButton plottButton = new JButton("Plott");
|
|
|
plottButton.addActionListener(actionEvent -> plott());
|
|
|
buttonPanel.add(plottButton);
|
|
@@ -269,11 +286,24 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
resetButton.addActionListener(actionEvent -> reset());
|
|
|
buttonPanel.add(resetButton);
|
|
|
JButton runButton = new JButton("Run");
|
|
|
- runButton.addActionListener(actionEvent -> executePsoAlgoWithCurrentParameters());
|
|
|
+ runButton.addActionListener(actionEvent -> {
|
|
|
+ Runnable task = () -> {
|
|
|
+ startTimer();
|
|
|
+ executePsoAlgoWithCurrentParameters();
|
|
|
+ printElapsedTime();
|
|
|
+ };
|
|
|
+ Thread thread = new Thread(task);
|
|
|
+ thread.start();
|
|
|
+ });
|
|
|
buttonPanel.add(runButton);
|
|
|
return buttonPanel;
|
|
|
}
|
|
|
|
|
|
+ private void fitness() {
|
|
|
+ initDependentParameter();
|
|
|
+ double currentFitness = evaluatePosition(extractPositionAndAccess(control.getModel()));
|
|
|
+ println("Actual Fitnessvalue: " + currentFitness);
|
|
|
+ }
|
|
|
private void setSaveFile() {
|
|
|
fileChooser.setFileFilter(new FileNameExtensionFilter("File", "txt"));
|
|
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
@@ -330,10 +360,23 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
dGroupNode = selected.object;
|
|
|
}
|
|
|
}
|
|
|
+ private void progressBarStep(){
|
|
|
+ progressBar.setValue(++progressBarCount);
|
|
|
+ }
|
|
|
+ private void calculateProgressBarParameter() {
|
|
|
+ int max = swarmSize * (maxIterations + 1)* rounds + rounds;
|
|
|
+ progressBarCount = 0;
|
|
|
+ progressBar.setValue(0);
|
|
|
+ progressBar.setMaximum(max);
|
|
|
+ }
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ private void startTimer(){
|
|
|
+ startTime = System.currentTimeMillis();
|
|
|
+ }
|
|
|
+ private void printElapsedTime(){
|
|
|
+ long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
|
|
|
+ println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -344,6 +387,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
*/
|
|
|
private void executePsoAlgoWithCurrentParameters() {
|
|
|
initDependentParameter();
|
|
|
+ calculateProgressBarParameter();
|
|
|
printParameter();
|
|
|
Best runBest = new Best();
|
|
|
runBest.value = Double.MAX_VALUE;
|
|
@@ -521,6 +565,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
*/
|
|
|
private double evaluatePosition(List<Boolean> position) {
|
|
|
setState(position);
|
|
|
+ progressBarStep();
|
|
|
control.calculateStateForCurrentTimeStep();
|
|
|
DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
|
return getFitnessValueForState(actualstate);
|