|
@@ -60,7 +60,8 @@ public class PSOAlgotihm implements Algorithm {
|
|
private int maxIterations = 100;
|
|
private int maxIterations = 100;
|
|
private double limit = 0.01;
|
|
private double limit = 0.01;
|
|
private double dependency = 2.07;
|
|
private double dependency = 2.07;
|
|
- private int rounds = 20;
|
|
|
|
|
|
+ private int rounds = 20;
|
|
|
|
+ private int mutationInterval = 0;
|
|
|
|
|
|
//Settings For GroupNode using and plotting
|
|
//Settings For GroupNode using and plotting
|
|
private boolean append = false;
|
|
private boolean append = false;
|
|
@@ -151,6 +152,10 @@ public class PSOAlgotihm implements Algorithm {
|
|
roundsLabel.setBounds(20, 160, 100, 20);
|
|
roundsLabel.setBounds(20, 160, 100, 20);
|
|
parameterPanel.add(roundsLabel);
|
|
parameterPanel.add(roundsLabel);
|
|
|
|
|
|
|
|
+ JLabel mutationIntervalLabel = new JLabel("Mutation Interval");
|
|
|
|
+ mutationIntervalLabel.setBounds(20, 185, 100, 20);
|
|
|
|
+ parameterPanel.add(mutationIntervalLabel);
|
|
|
|
+
|
|
JLabel cautionLabel = new JLabel(
|
|
JLabel cautionLabel = new JLabel(
|
|
"Caution: High values in the fields of 'Swarm Size' and 'Max. Iteration' may take some time to calculate.");
|
|
"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.setFont(new Font("Serif", Font.ITALIC, 12));
|
|
@@ -262,10 +267,24 @@ public class PSOAlgotihm implements Algorithm {
|
|
|
|
|
|
JFormattedTextField roundsTextField = new JFormattedTextField(roundsFormatter);
|
|
JFormattedTextField roundsTextField = new JFormattedTextField(roundsFormatter);
|
|
roundsTextField.setValue(rounds);
|
|
roundsTextField.setValue(rounds);
|
|
- roundsTextField.setToolTipText("Amount of rounds to be runed with the same starting ");
|
|
|
|
|
|
+ roundsTextField.setToolTipText("Number of algorithm repetitions for the same starting situation ");
|
|
roundsTextField.addPropertyChangeListener(propertyChange -> rounds = Integer.parseInt((roundsTextField.getValue().toString())));
|
|
roundsTextField.addPropertyChangeListener(propertyChange -> rounds = Integer.parseInt((roundsTextField.getValue().toString())));
|
|
roundsTextField.setBounds(125, 160, 50, 20);
|
|
roundsTextField.setBounds(125, 160, 50, 20);
|
|
parameterPanel.add(roundsTextField);
|
|
parameterPanel.add(roundsTextField);
|
|
|
|
+ //--- subsequently Rolf Did stuff ------------------------------------------------------------------------------------------
|
|
|
|
+ /*NumberFormatter mutationIntervalFormatter = new NumberFormatter(inte);
|
|
|
|
+ mutationIntervalFormatter.setMinimum(0);
|
|
|
|
+ mutationIntervalFormatter.setMaximum(maxIterations);
|
|
|
|
+ mutationIntervalFormatter.setCommitsOnValidEdit(true);*/
|
|
|
|
+
|
|
|
|
+ JFormattedTextField mutationIntervalTextfield = new JFormattedTextField(integerFormatter);
|
|
|
|
+ mutationIntervalTextfield.setValue(mutationInterval);
|
|
|
|
+ mutationIntervalTextfield.setToolTipText("The number of Iterations after which one mutation iteration is conducted");
|
|
|
|
+ mutationIntervalTextfield.addPropertyChangeListener(propertyChange -> mutationInterval = Integer.parseInt((mutationIntervalTextfield.getValue().toString())));
|
|
|
|
+ mutationIntervalTextfield.setBounds(125, 185, 50, 20);
|
|
|
|
+ parameterPanel.add(mutationIntervalTextfield);
|
|
|
|
+ //--- previously Rolf Did stuff ------------------------------------------------------------------------------------------
|
|
|
|
+
|
|
return parameterPanel;
|
|
return parameterPanel;
|
|
}
|
|
}
|
|
public JPanel createButtonPanel() {
|
|
public JPanel createButtonPanel() {
|
|
@@ -485,11 +504,14 @@ public class PSOAlgotihm implements Algorithm {
|
|
evaluation(globalBest, swarm);
|
|
evaluation(globalBest, swarm);
|
|
runList.add(globalBest.value);
|
|
runList.add(globalBest.value);
|
|
for (int iteration = 0; iteration < maxIterations ; iteration++) {
|
|
for (int iteration = 0; iteration < maxIterations ; iteration++) {
|
|
|
|
+ int mutationAllowed = iteration % mutationInterval;
|
|
for (int particleNumber = 0; particleNumber < swarmSize; particleNumber++) {
|
|
for (int particleNumber = 0; particleNumber < swarmSize; particleNumber++) {
|
|
Particle particle = swarm.get(particleNumber);
|
|
Particle particle = swarm.get(particleNumber);
|
|
for(int index = 0; index < dimensions; index++) {
|
|
for(int index = 0; index < dimensions; index++) {
|
|
updateVelocity(particle, index, globalBest);
|
|
updateVelocity(particle, index, globalBest);
|
|
updateGenotype(particle, index);
|
|
updateGenotype(particle, index);
|
|
|
|
+ //-------Rolf changes below------------------------
|
|
|
|
+ if(mutationAllowed == 0 && iteration != 0)
|
|
mutation(particle, index);
|
|
mutation(particle, index);
|
|
decode(particle, index);
|
|
decode(particle, index);
|
|
}
|
|
}
|
|
@@ -614,7 +636,7 @@ public class PSOAlgotihm implements Algorithm {
|
|
for(DecoratedNetwork net : state.getNetworkList()) {
|
|
for(DecoratedNetwork net : state.getNetworkList()) {
|
|
float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
|
|
float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
|
|
float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
|
|
float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
|
|
- nw_fitness += Math.abs(production - consumption); //Energy is now everywhere positive
|
|
|
|
|
|
+ nw_fitness += Math.abs((production - consumption)/100); //Energy is now everywhere positive
|
|
}
|
|
}
|
|
|
|
|
|
// calculate object_fitness
|
|
// calculate object_fitness
|
|
@@ -623,7 +645,8 @@ public class PSOAlgotihm implements Algorithm {
|
|
//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.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.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));
|
|
object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
|
|
}
|
|
}
|
|
@@ -688,11 +711,11 @@ public class PSOAlgotihm implements Algorithm {
|
|
private double StateToDouble(HolonObjectState state) {
|
|
private double StateToDouble(HolonObjectState state) {
|
|
switch (state) {
|
|
switch (state) {
|
|
case NOT_SUPPLIED:
|
|
case NOT_SUPPLIED:
|
|
- return 300.0;
|
|
|
|
|
|
+ return 150.0;
|
|
case NO_ENERGY:
|
|
case NO_ENERGY:
|
|
- return 100.0;
|
|
|
|
|
|
+ return 150.0;
|
|
case OVER_SUPPLIED:
|
|
case OVER_SUPPLIED:
|
|
- return 200.0;
|
|
|
|
|
|
+ return 100.0;
|
|
case PARTIALLY_SUPPLIED:
|
|
case PARTIALLY_SUPPLIED:
|
|
return 100.0;
|
|
return 100.0;
|
|
case PRODUCER:
|
|
case PRODUCER:
|