|
@@ -45,6 +45,7 @@ import classes.HolonObject;
|
|
import classes.HolonSwitch;
|
|
import classes.HolonSwitch;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
+import ui.view.Console;
|
|
import ui.model.DecoratedHolonObject.HolonObjectState;
|
|
import ui.model.DecoratedHolonObject.HolonObjectState;
|
|
import ui.model.DecoratedGroupNode;
|
|
import ui.model.DecoratedGroupNode;
|
|
import ui.model.DecoratedNetwork;
|
|
import ui.model.DecoratedNetwork;
|
|
@@ -81,7 +82,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
|
|
|
|
//Gui Part:
|
|
//Gui Part:
|
|
private Control control;
|
|
private Control control;
|
|
- private JTextArea textArea;
|
|
|
|
|
|
+ private Console console = new Console();
|
|
private JPanel content = new JPanel();
|
|
private JPanel content = new JPanel();
|
|
//ProgressBar
|
|
//ProgressBar
|
|
private JProgressBar progressBar = new JProgressBar();
|
|
private JProgressBar progressBar = new JProgressBar();
|
|
@@ -102,10 +103,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
}
|
|
}
|
|
public PSOAlgorithm() {
|
|
public PSOAlgorithm() {
|
|
content.setLayout(new BorderLayout());
|
|
content.setLayout(new BorderLayout());
|
|
-
|
|
|
|
- textArea = new JTextArea();
|
|
|
|
- textArea.setEditable(false);
|
|
|
|
- JScrollPane scrollPane = new JScrollPane(textArea);
|
|
|
|
|
|
+ JScrollPane scrollPane = new JScrollPane(console);
|
|
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
|
|
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
|
|
createOptionPanel() , scrollPane);
|
|
createOptionPanel() , scrollPane);
|
|
splitPane.setResizeWeight(0.0);
|
|
splitPane.setResizeWeight(0.0);
|
|
@@ -296,9 +294,6 @@ public class PSOAlgorithm implements Algorithm {
|
|
JButton cancelButton = new JButton("Cancel Run");
|
|
JButton cancelButton = new JButton("Cancel Run");
|
|
cancelButton.addActionListener(actionEvent -> cancel());
|
|
cancelButton.addActionListener(actionEvent -> cancel());
|
|
buttonPanel.add(cancelButton);
|
|
buttonPanel.add(cancelButton);
|
|
- JButton clearButton = new JButton("Clear Console");
|
|
|
|
- clearButton.addActionListener(actionEvent -> clear());
|
|
|
|
- buttonPanel.add(clearButton);
|
|
|
|
JButton folderButton = new JButton("Change Plott-File");
|
|
JButton folderButton = new JButton("Change Plott-File");
|
|
folderButton.addActionListener(actionEvent -> setSaveFile());
|
|
folderButton.addActionListener(actionEvent -> setSaveFile());
|
|
buttonPanel.add(folderButton);
|
|
buttonPanel.add(folderButton);
|
|
@@ -340,47 +335,47 @@ public class PSOAlgorithm implements Algorithm {
|
|
|
|
|
|
private void cancel() {
|
|
private void cancel() {
|
|
if(runThread.isAlive()) {
|
|
if(runThread.isAlive()) {
|
|
- println("");
|
|
|
|
- println("Cancel run.");
|
|
|
|
|
|
+ console.println("");
|
|
|
|
+ console.println("Cancel run.");
|
|
cancel = true;
|
|
cancel = true;
|
|
progressBar.setValue(0);
|
|
progressBar.setValue(0);
|
|
} else {
|
|
} else {
|
|
- println("Nothing to cancel.");
|
|
|
|
|
|
+ console.println("Nothing to cancel.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void fitness() {
|
|
private void fitness() {
|
|
initDependentParameter();
|
|
initDependentParameter();
|
|
double currentFitness = evaluatePosition(extractPositionAndAccess(control.getModel()), false);
|
|
double currentFitness = evaluatePosition(extractPositionAndAccess(control.getModel()), false);
|
|
- println("Actual Fitnessvalue: " + currentFitness);
|
|
|
|
|
|
+ console.println("Actual Fitnessvalue: " + currentFitness);
|
|
}
|
|
}
|
|
private void setSaveFile() {
|
|
private void setSaveFile() {
|
|
fileChooser.setFileFilter(new FileNameExtensionFilter("File", "txt"));
|
|
fileChooser.setFileFilter(new FileNameExtensionFilter("File", "txt"));
|
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
|
int result = fileChooser.showSaveDialog(content);
|
|
int result = fileChooser.showSaveDialog(content);
|
|
if(result == JFileChooser.APPROVE_OPTION) {
|
|
if(result == JFileChooser.APPROVE_OPTION) {
|
|
- println("Set save File to:" + fileChooser.getSelectedFile().getAbsolutePath());
|
|
|
|
|
|
+ console.println("Set save File to:" + fileChooser.getSelectedFile().getAbsolutePath());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
private void plott() {
|
|
private void plott() {
|
|
if(db!=null) {
|
|
if(db!=null) {
|
|
- println("Plott..");
|
|
|
|
|
|
+ console.println("Plott..");
|
|
db.initFileStream();
|
|
db.initFileStream();
|
|
}else {
|
|
}else {
|
|
- println("No run inistialized.");
|
|
|
|
|
|
+ console.println("No run inistialized.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void reset() {
|
|
private void reset() {
|
|
if(initialState != null) {
|
|
if(initialState != null) {
|
|
- println("Resetting..");
|
|
|
|
|
|
+ console.println("Resetting..");
|
|
resetState();
|
|
resetState();
|
|
updateVisual();
|
|
updateVisual();
|
|
}else {
|
|
}else {
|
|
- println("No run inistialized.");
|
|
|
|
|
|
+ console.println("No run inistialized.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void printParameter() {
|
|
private void printParameter() {
|
|
- println("SwarmSize:" + swarmSize + ", MaxIter:" + maxIterations + ", Limit:" + limit + ", Dependency:" + dependency + ", Rounds:" + rounds +", DependentParameter: w:"+ w + ", c1:" + c1 + ", c2:" + c2 );
|
|
|
|
|
|
+ console.println("SwarmSize:" + swarmSize + ", MaxIter:" + maxIterations + ", Limit:" + limit + ", Dependency:" + dependency + ", Rounds:" + rounds +", DependentParameter: w:"+ w + ", c1:" + c1 + ", c2:" + c2 );
|
|
}
|
|
}
|
|
@Override
|
|
@Override
|
|
public JPanel getAlgorithmPanel() {
|
|
public JPanel getAlgorithmPanel() {
|
|
@@ -391,21 +386,13 @@ public class PSOAlgorithm implements Algorithm {
|
|
this.control = control;
|
|
this.control = control;
|
|
|
|
|
|
}
|
|
}
|
|
- private void clear() {
|
|
|
|
- textArea.setText("");
|
|
|
|
- }
|
|
|
|
- private void print(String message) {
|
|
|
|
- textArea.append(message);
|
|
|
|
- }
|
|
|
|
- private void println(String message) {
|
|
|
|
- textArea.append(message + "\n");
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
private void selectGroupNode() {
|
|
private void selectGroupNode() {
|
|
Object[] possibilities = control.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
|
|
Object[] possibilities = control.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
|
|
@SuppressWarnings("unchecked")
|
|
@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, "");
|
|
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) {
|
|
if(selected != null) {
|
|
- println("Selected: " + selected);
|
|
|
|
|
|
+ console.println("Selected: " + selected);
|
|
dGroupNode = selected.object;
|
|
dGroupNode = selected.object;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -424,7 +411,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
}
|
|
}
|
|
private void printElapsedTime(){
|
|
private void printElapsedTime(){
|
|
long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
|
|
long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
|
|
- println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
|
|
|
|
|
|
+ console.println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -450,8 +437,8 @@ public class PSOAlgorithm implements Algorithm {
|
|
resetState();
|
|
resetState();
|
|
if(lastRunBest.value < runBest.value) runBest = lastRunBest;
|
|
if(lastRunBest.value < runBest.value) runBest = lastRunBest;
|
|
}
|
|
}
|
|
- println("AlgoResult:" + runBest.value);
|
|
|
|
- //println("[" + lastRunBest.position.stream().map(Object::toString).collect(Collectors.joining(", ")) + "]");
|
|
|
|
|
|
+ console.println("AlgoResult:" + runBest.value);
|
|
|
|
+ //console.println("[" + lastRunBest.position.stream().map(Object::toString).collect(Collectors.joining(", ")) + "]");
|
|
setState(runBest.position);
|
|
setState(runBest.position);
|
|
updateVisual();
|
|
updateVisual();
|
|
}
|
|
}
|
|
@@ -500,7 +487,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
Best globalBest = new Best();
|
|
Best globalBest = new Best();
|
|
globalBest.position = extractPositionAndAccess(control.getModel());
|
|
globalBest.position = extractPositionAndAccess(control.getModel());
|
|
globalBest.value = evaluatePosition(globalBest.position, true);
|
|
globalBest.value = evaluatePosition(globalBest.position, true);
|
|
- print("Start Value:" + globalBest.value);
|
|
|
|
|
|
+ console.println("Start Value:" + globalBest.value);
|
|
int dimensions = globalBest.position.size();
|
|
int dimensions = globalBest.position.size();
|
|
List<Particle> swarm= initializeParticles(dimensions);
|
|
List<Particle> swarm= initializeParticles(dimensions);
|
|
runList.add(globalBest.value);
|
|
runList.add(globalBest.value);
|
|
@@ -523,7 +510,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
evaluation(globalBest, swarm);
|
|
evaluation(globalBest, swarm);
|
|
runList.add(globalBest.value);
|
|
runList.add(globalBest.value);
|
|
}
|
|
}
|
|
- println(" End Value:" + globalBest.value);
|
|
|
|
|
|
+ console.println(" End Value:" + globalBest.value);
|
|
return globalBest;
|
|
return globalBest;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -647,7 +634,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) + inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) + inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
//warum war das im network fitness und nicht hier im Object fitness??
|
|
//warum war das im network fitness und nicht hier im Object fitness??
|
|
object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).reduce(0.0, (a,b) -> (a+b));
|
|
object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).reduce(0.0, (a,b) -> (a+b));
|
|
- //System.out.println("objectfitness for statestuff: " + object_fitness);
|
|
|
|
|
|
+ //System.out.console.println("objectfitness for statestuff: " + object_fitness);
|
|
//object_fitness += net.getPassivNoEnergyList().stream().map(con -> 1000.0).reduce(0.0, (a, b) -> (a + b));
|
|
//object_fitness += net.getPassivNoEnergyList().stream().map(con -> 1000.0).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
@@ -671,7 +658,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
|
|
|
|
//result = (float) Math.pow((maxElements -activeElements),2)*10;
|
|
//result = (float) Math.pow((maxElements -activeElements),2)*10;
|
|
result = (float) Math.pow(5, 4* ( (float) maxElements - (float) activeElements)/ (float) maxElements) - 1;
|
|
result = (float) Math.pow(5, 4* ( (float) maxElements - (float) activeElements)/ (float) maxElements) - 1;
|
|
- //System.out.println("max: " + maxElements + " active: " + activeElements + " results in penalty: " + result);
|
|
|
|
|
|
+ //System.out.console.println("max: " + maxElements + " active: " + activeElements + " results in penalty: " + result);
|
|
return result;
|
|
return result;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -813,7 +800,7 @@ public class PSOAlgorithm implements Algorithm {
|
|
printToStream(out);
|
|
printToStream(out);
|
|
out.close();
|
|
out.close();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- println(e.getMessage());
|
|
|
|
|
|
+ console.println(e.getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -831,14 +818,14 @@ public class PSOAlgorithm implements Algorithm {
|
|
|
|
|
|
}
|
|
}
|
|
catch(IOException e) {
|
|
catch(IOException e) {
|
|
- println(e.getMessage());
|
|
|
|
|
|
+ console.println(e.getMessage());
|
|
}
|
|
}
|
|
allRuns.forEach(run -> {
|
|
allRuns.forEach(run -> {
|
|
try {
|
|
try {
|
|
out.write( run.stream().map(Object::toString).collect(Collectors.joining(", ")));
|
|
out.write( run.stream().map(Object::toString).collect(Collectors.joining(", ")));
|
|
out.newLine();
|
|
out.newLine();
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
- println(e.getMessage());
|
|
|
|
|
|
+ console.println(e.getMessage());
|
|
}
|
|
}
|
|
} );
|
|
} );
|
|
/* out.write("AverageRun:");
|
|
/* out.write("AverageRun:");
|