|
@@ -79,6 +79,11 @@ public class FlexExample implements Algorithm {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
public static void main(String[] args)
|
|
public static void main(String[] args)
|
|
{
|
|
{
|
|
JFrame newFrame = new JFrame("exampleWindow");
|
|
JFrame newFrame = new JFrame("exampleWindow");
|
|
@@ -213,22 +218,26 @@ public class FlexExample implements Algorithm {
|
|
disableGuiInput(true);
|
|
disableGuiInput(true);
|
|
startTimer();
|
|
startTimer();
|
|
control.resetSimulation();
|
|
control.resetSimulation();
|
|
|
|
+ RunResult result= new RunResult();
|
|
for(int i = 0; i < 100; i++) {
|
|
for(int i = 0; i < 100; i++) {
|
|
control.setCurIteration(i);
|
|
control.setCurIteration(i);
|
|
- executeDemoAlgo();
|
|
|
|
|
|
+ executeDemoAlgo(result);
|
|
if(cancel) {
|
|
if(cancel) {
|
|
resetLast();
|
|
resetLast();
|
|
disableGuiInput(false);
|
|
disableGuiInput(false);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ updateVisual();
|
|
|
|
+ println("Amount of activatedFlex:" + result.activatedFlex + " Amount of deactivatedElements:"+ result.deactivatedElements + " TotalCost:"+result.totalCost);
|
|
printElapsedTime();
|
|
printElapsedTime();
|
|
disableGuiInput(false);
|
|
disableGuiInput(false);
|
|
}
|
|
}
|
|
private void run() {
|
|
private void run() {
|
|
disableGuiInput(true);
|
|
disableGuiInput(true);
|
|
startTimer();
|
|
startTimer();
|
|
- executeDemoAlgo();
|
|
|
|
|
|
+ executeDemoAlgo(new RunResult());
|
|
|
|
+ updateVisual();
|
|
printElapsedTime();
|
|
printElapsedTime();
|
|
disableGuiInput(false);
|
|
disableGuiInput(false);
|
|
}
|
|
}
|
|
@@ -342,11 +351,11 @@ public class FlexExample implements Algorithm {
|
|
* End
|
|
* End
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- private void executeDemoAlgo() {
|
|
|
|
|
|
+ private void executeDemoAlgo(RunResult result) {
|
|
extractPositionAndAccess();
|
|
extractPositionAndAccess();
|
|
int actualIteration = control.getModel().getCurIteration();
|
|
int actualIteration = control.getModel().getCurIteration();
|
|
- println("AlgoStart....");
|
|
|
|
- control.calculateStateAndVisualForCurrentTimeStep();
|
|
|
|
|
|
+ println("TimeStep:" + actualIteration);
|
|
|
|
+ control.calculateStateOnlyForCurrentTimeStep();
|
|
List<Priority> priorityListASC = createPriorityListASC();
|
|
List<Priority> priorityListASC = createPriorityListASC();
|
|
DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
DecoratedState actualstate = control.getSimManager().getActualDecorState();
|
|
for(DecoratedNetwork net : actualstate.getNetworkList()) {
|
|
for(DecoratedNetwork net : actualstate.getNetworkList()) {
|
|
@@ -356,6 +365,7 @@ public class FlexExample implements Algorithm {
|
|
println("production: " + production);
|
|
println("production: " + production);
|
|
println("consumption: " + consumption);
|
|
println("consumption: " + consumption);
|
|
println("difference: " + difference);
|
|
println("difference: " + difference);
|
|
|
|
+ if(production > consumption) continue;
|
|
if(difference == 0)continue;
|
|
if(difference == 0)continue;
|
|
Set<HolonElement> allHolonElemntsInThisNetwork = createListOfAllHolonElemnts(net);
|
|
Set<HolonElement> allHolonElemntsInThisNetwork = createListOfAllHolonElemnts(net);
|
|
FlexManager flexManager = control.getSimManager().getActualFlexManager();
|
|
FlexManager flexManager = control.getSimManager().getActualFlexManager();
|
|
@@ -364,18 +374,18 @@ public class FlexExample implements Algorithm {
|
|
List<FlexWrapper> allFlexThatGetMeEnergy = allOfferedFlex.stream().filter(flexWrapper -> (flexWrapper.getFlex().bringtmir() > 0)).collect(Collectors.toList());
|
|
List<FlexWrapper> allFlexThatGetMeEnergy = allOfferedFlex.stream().filter(flexWrapper -> (flexWrapper.getFlex().bringtmir() > 0)).collect(Collectors.toList());
|
|
float amountOfAllEnergyOffered = sumEnergyAvailable(allFlexThatGetMeEnergy);
|
|
float amountOfAllEnergyOffered = sumEnergyAvailable(allFlexThatGetMeEnergy);
|
|
println("amountOfAllFlexEnergyOffered:" + amountOfAllEnergyOffered);
|
|
println("amountOfAllFlexEnergyOffered:" + amountOfAllEnergyOffered);
|
|
- if(production > consumption) continue;
|
|
|
|
//ShuddownPriorities
|
|
//ShuddownPriorities
|
|
for(Priority emergencyShutDownPriority: priorityListASC) {
|
|
for(Priority emergencyShutDownPriority: priorityListASC) {
|
|
if(amountOfAllEnergyOffered >= difference) break;
|
|
if(amountOfAllEnergyOffered >= difference) break;
|
|
println("ShutDown: " + emergencyShutDownPriority);
|
|
println("ShutDown: " + emergencyShutDownPriority);
|
|
- difference -= shutDownAllConsumerElementsWithPriority(flexManager, allHolonElemntsInThisNetwork, emergencyShutDownPriority);
|
|
|
|
|
|
+ difference -= shutDownAllConsumerElementsWithPriority(flexManager, allHolonElemntsInThisNetwork, emergencyShutDownPriority, result);
|
|
}
|
|
}
|
|
|
|
|
|
//SortFlexes
|
|
//SortFlexes
|
|
allFlexThatGetMeEnergy.sort((flex1, flex2) -> Float.compare(flex1.getFlex().cost / flex1.getFlex().bringtmir(), flex2.getFlex().cost / flex2.getFlex().bringtmir()));
|
|
allFlexThatGetMeEnergy.sort((flex1, flex2) -> Float.compare(flex1.getFlex().cost / flex1.getFlex().bringtmir(), flex2.getFlex().cost / flex2.getFlex().bringtmir()));
|
|
//OrderFlexes
|
|
//OrderFlexes
|
|
float costForThisTimeStep = 0f;
|
|
float costForThisTimeStep = 0f;
|
|
|
|
+ int amountflexActivated = 0;
|
|
for(FlexWrapper flexWrapper : allFlexThatGetMeEnergy) {
|
|
for(FlexWrapper flexWrapper : allFlexThatGetMeEnergy) {
|
|
if(!flexWrapper.canOrder()) continue;
|
|
if(!flexWrapper.canOrder()) continue;
|
|
float energy = flexWrapper.getFlex().bringtmir();
|
|
float energy = flexWrapper.getFlex().bringtmir();
|
|
@@ -384,26 +394,26 @@ public class FlexExample implements Algorithm {
|
|
difference -= energy;
|
|
difference -= energy;
|
|
costForThisTimeStep += flexWrapper.getFlex().cost;
|
|
costForThisTimeStep += flexWrapper.getFlex().cost;
|
|
flexWrapper.order();
|
|
flexWrapper.order();
|
|
|
|
+ amountflexActivated++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- println("CostForThisTimeStep:" + costForThisTimeStep);
|
|
|
|
|
|
+ result.activatedFlex += amountflexActivated++;
|
|
|
|
|
|
- println("Ende");
|
|
|
|
-
|
|
|
|
|
|
+ println("Activated FlexThisTimeStep: "+ amountflexActivated+" CostForThisTimeStep:" + costForThisTimeStep);
|
|
|
|
+ result.totalCost += costForThisTimeStep;
|
|
|
|
|
|
}
|
|
}
|
|
- println("AlgoEnde....");
|
|
|
|
- updateVisual();
|
|
|
|
}
|
|
}
|
|
private float shutDownAllConsumerElementsWithPriority(FlexManager flexManager, Set<HolonElement> allHolonElemntsInThisNetwork,
|
|
private float shutDownAllConsumerElementsWithPriority(FlexManager flexManager, Set<HolonElement> allHolonElemntsInThisNetwork,
|
|
- Priority emergencyShutDownPriority) {
|
|
|
|
|
|
+ Priority emergencyShutDownPriority, RunResult result) {
|
|
|
|
|
|
List<HolonElement> elementsOfPriorityToShutdown = allHolonElemntsInThisNetwork.stream().filter(hElement -> hElement.isConsumer() && hElement.getPriority() == emergencyShutDownPriority && !hElement.isFlexActive(flexManager) && hElement.isActive()).collect(Collectors.toList());
|
|
List<HolonElement> elementsOfPriorityToShutdown = allHolonElemntsInThisNetwork.stream().filter(hElement -> hElement.isConsumer() && hElement.getPriority() == emergencyShutDownPriority && !hElement.isFlexActive(flexManager) && hElement.isActive()).collect(Collectors.toList());
|
|
//.forEach(hElement -> hElement.setActive(false));
|
|
//.forEach(hElement -> hElement.setActive(false));
|
|
float energyGained = elementsOfPriorityToShutdown.stream().map(hElement -> -hElement.getEnergyPerElement() * hElement.getAmount()).reduce(0.0f, (a, b) -> a + b);
|
|
float energyGained = elementsOfPriorityToShutdown.stream().map(hElement -> -hElement.getEnergyPerElement() * hElement.getAmount()).reduce(0.0f, (a, b) -> a + b);
|
|
elementsOfPriorityToShutdown.forEach(hElement -> hElement.setActive(false));
|
|
elementsOfPriorityToShutdown.forEach(hElement -> hElement.setActive(false));
|
|
int shutdownCount = elementsOfPriorityToShutdown.size();
|
|
int shutdownCount = elementsOfPriorityToShutdown.size();
|
|
|
|
+ result.deactivatedElements += shutdownCount;
|
|
println("Gained " + energyGained + "Energy from Shutdown with Priority:" + emergencyShutDownPriority + " AmountOfShutDowned HolonElements: " + shutdownCount);
|
|
println("Gained " + energyGained + "Energy from Shutdown with Priority:" + emergencyShutDownPriority + " AmountOfShutDowned HolonElements: " + shutdownCount);
|
|
return energyGained;
|
|
return energyGained;
|
|
}
|
|
}
|
|
@@ -477,8 +487,8 @@ public class FlexExample implements Algorithm {
|
|
*/
|
|
*/
|
|
private void updateVisual() {
|
|
private void updateVisual() {
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
control.calculateStateAndVisualForCurrentTimeStep();
|
|
- control.updateCanvas();
|
|
|
|
- control.getGui().triggerUpdateController(null);
|
|
|
|
|
|
+ //control.updateCanvas();
|
|
|
|
+ //control.getGui().triggerUpdateController(null);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* Sets the Model back to its original State before the LAST run.
|
|
* Sets the Model back to its original State before the LAST run.
|
|
@@ -547,7 +557,11 @@ public class FlexExample implements Algorithm {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
+ private class RunResult {
|
|
|
|
+ public int activatedFlex = 0;
|
|
|
|
+ public int deactivatedElements = 0;
|
|
|
|
+ public int totalCost = 0;
|
|
|
|
+ }
|
|
|
|
|
|
private class Handle<T>{
|
|
private class Handle<T>{
|
|
public T object;
|
|
public T object;
|