|
@@ -1,6 +1,9 @@
|
|
|
package ui.controller;
|
|
|
|
|
|
import classes.*;
|
|
|
+import classes.comparator.EnergyMinToMaxComparator;
|
|
|
+import classes.comparator.MinEnergyComparator;
|
|
|
+import classes.comparator.TotalEnergyComparator;
|
|
|
import ui.model.Model;
|
|
|
import ui.view.FlexiblePane;
|
|
|
import ui.view.MyCanvas;
|
|
@@ -78,6 +81,20 @@ public class SimulationManager {
|
|
|
setFlowSimulation(singleSubNet);
|
|
|
|
|
|
// --------------- visualise graph ---------------
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * production of subnets, that might be partially turned on/off
|
|
|
+ */
|
|
|
+ float currentProduction = production;
|
|
|
+ /**
|
|
|
+ * HolonObjects that can be partially Supplied but might be fully Supplied
|
|
|
+ */
|
|
|
+ ArrayList<HolonObject> partiallySuppliedList = new ArrayList<HolonObject>();
|
|
|
+ /**
|
|
|
+ * supply Buildings with minimal Energy first, if conflicts happen
|
|
|
+ */
|
|
|
+ singleSubNet.getObjects().sort(new MinEnergyComparator(x));
|
|
|
for (HolonObject hl : singleSubNet.getObjects()) {
|
|
|
if (hl.getState() != HolonObject.NO_ENERGY
|
|
|
&& hl.getState() != HolonObject.PRODUCER) {
|
|
@@ -97,12 +114,32 @@ public class SimulationManager {
|
|
|
} else if (hl.checkIfPartiallySupplied(timeStep)) {
|
|
|
hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
} else {
|
|
|
- hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
+ /**
|
|
|
+ * Case that only some HolonObjects can be supplied
|
|
|
+ */
|
|
|
+ if(-hl.getCurrentEnergyAtTimeStep(x)<=currentProduction){
|
|
|
+ hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
+ currentProduction += hl.getMinEnergy(x);
|
|
|
+ partiallySuppliedList.add(hl);
|
|
|
+ }else if(-hl.getMinEnergy(x)<=currentProduction){
|
|
|
+ hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
+ currentProduction += hl.getMinEnergy(x);
|
|
|
+ partiallySuppliedList.add(hl);
|
|
|
+ }else{
|
|
|
+ hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
+ //currentProduction += hl.getCurrentEnergyAtTimeStep(x);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * check if some object cn self supply itself
|
|
|
+ */
|
|
|
if (hl.checkIfPartiallySupplied(timeStep)
|
|
|
&& hl.getState() != HolonObject.SUPPLIED
|
|
|
&& hl.getState() != HolonObject.OVER_SUPPLIED) {
|
|
@@ -110,6 +147,23 @@ public class SimulationManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * check if some partially supplied building might be fully supplied.
|
|
|
+ */
|
|
|
+ partiallySuppliedList.sort(new EnergyMinToMaxComparator(x));
|
|
|
+ for(HolonObject part: partiallySuppliedList){
|
|
|
+ currentProduction -= part.getMinEnergy(x);
|
|
|
+ /*
|
|
|
+ * if possible, supply fully
|
|
|
+ */
|
|
|
+ if(-part.getCurrentEnergyAtTimeStep(x)<=currentProduction){
|
|
|
+ part.setState(HolonObject.SUPPLIED);
|
|
|
+ currentProduction += part.getCurrentEnergyAtTimeStep(x);
|
|
|
+ }else{
|
|
|
+ currentProduction += part.getMinEnergy(x);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
canvas.repaint();
|
|
|
flexPane.recalculate();
|