|
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|
|
import classes.CpsEdge;
|
|
|
import classes.CpsNode;
|
|
|
import classes.CpsObject;
|
|
|
+import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
import classes.subNet;
|
|
@@ -35,6 +36,7 @@ public class SimulationManager {
|
|
|
for(subNet singleSubNet: subNets){
|
|
|
float production = calculateEnergy("prod", singleSubNet, x);
|
|
|
float consumption = calculateEnergy("cons", singleSubNet, x);
|
|
|
+ float minConsumption = calculateMinimumEnergy( singleSubNet, x);
|
|
|
for(CpsEdge e: singleSubNet.getEdges()){
|
|
|
e.setFlow(production);
|
|
|
}
|
|
@@ -48,7 +50,13 @@ public class SimulationManager {
|
|
|
hl.setState(2);
|
|
|
}
|
|
|
if((production + consumption) < 0){
|
|
|
- hl.setState(1);
|
|
|
+ if((production + minConsumption) >= 0){
|
|
|
+ hl.setState(4);
|
|
|
+ System.out.println("yellow");
|
|
|
+ }else{
|
|
|
+ hl.setState(1);
|
|
|
+ System.out.println("orange");
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -89,6 +97,24 @@ public class SimulationManager {
|
|
|
return energy;
|
|
|
}
|
|
|
|
|
|
+ public float calculateMinimumEnergy(subNet sN, int x){
|
|
|
+ float min = 0;
|
|
|
+ float minElement = 0;
|
|
|
+ for(HolonObject hl: sN.getObjects()){
|
|
|
+ if(hl.getElements().size() > 0 && hl.getElements().get(0).getTotalEnergyAtTimeStep(x) < 0 ){
|
|
|
+ minElement = hl.getElements().get(0).getTotalEnergyAtTimeStep(x);
|
|
|
+ }
|
|
|
+ for(HolonElement he: hl.getElements()){
|
|
|
+ if(minElement < he.getTotalEnergyAtTimeStep(x) && he.getTotalEnergyAtTimeStep(x) < 0){
|
|
|
+ minElement = he.getTotalEnergyAtTimeStep(x);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println(minElement);
|
|
|
+ min = min + minElement;
|
|
|
+ }
|
|
|
+ return min;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* generates all subNets from all objectsToHandle
|
|
|
*/
|