|
@@ -338,155 +338,6 @@ public class SimulationManager {
|
|
|
flexPane.recalculate();
|
|
|
}
|
|
|
|
|
|
- private void calculation(int x, SubNet singleSubNet, float production, float consumption, float energySurplus,
|
|
|
- float currentProduction, ArrayList<HolonObject> partiallySuppliedList,
|
|
|
- ArrayList<HolonObject> notSuppliedList, float energyPerHolonObject) {
|
|
|
- long numberOfConsumers;
|
|
|
- if (model.getFairnessModel() == fairnessMininumDemandFirst) {
|
|
|
- /**
|
|
|
- * supply Buildings with minimal Energy first, if conflicts
|
|
|
- * happen
|
|
|
- */
|
|
|
- singleSubNet.getObjects().sort(new MinEnergyComparator(x));
|
|
|
- } else if (model.getFairnessModel() == fairnessAllEqual) {
|
|
|
- /*
|
|
|
- * give every building (just consumer) the same energy
|
|
|
- */
|
|
|
- numberOfConsumers = singleSubNet
|
|
|
- .getObjects()
|
|
|
- .stream()
|
|
|
- .filter(hl -> (hl.getState() != HolonObject.NO_ENERGY
|
|
|
- && hl.getState() != HolonObject.PRODUCER && hl
|
|
|
- .getConnectedTo().stream()
|
|
|
- .filter(e -> (e.getFlow() > 0)).count() > 0))
|
|
|
- .count();
|
|
|
- if (numberOfConsumers != 0)
|
|
|
- energyPerHolonObject = currentProduction / numberOfConsumers;
|
|
|
- }
|
|
|
- for (HolonObject hl : singleSubNet.getObjects()) {
|
|
|
- hl.setCurrentSupply(0);
|
|
|
- if (hl.getState() != HolonObject.NO_ENERGY
|
|
|
- && hl.getState() != HolonObject.PRODUCER) {
|
|
|
- for (int i = 0; i < hl.getConnections().size(); i++) {
|
|
|
- CpsEdge edge = hl.getConnectedTo().get(i);
|
|
|
- if (edge.isWorking()
|
|
|
- && edge.getFlow() > 0
|
|
|
- || edge.getCapacity() == CpsEdge.CAPACITY_INFINITE) {
|
|
|
-
|
|
|
- if (model.getFairnessModel() == fairnessAllEqual) {
|
|
|
- /* fairness: everyone receives the Same Energy */
|
|
|
- float neededEnergy = hl
|
|
|
- .getCurrentEnergyAtTimeStep(x);
|
|
|
- if (neededEnergy > 0) {
|
|
|
- hl.setState(HolonObject.PRODUCER);
|
|
|
- } else if (energyPerHolonObject > -neededEnergy) {
|
|
|
- hl.setState(HolonObject.OVER_SUPPLIED);
|
|
|
- } else if (energyPerHolonObject == -neededEnergy) {
|
|
|
- hl.setState(HolonObject.SUPPLIED);
|
|
|
- } else if (energyPerHolonObject >= -hl
|
|
|
- .getMinEnergy(x)) {
|
|
|
- hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- } else {
|
|
|
- hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
- }
|
|
|
- hl.setCurrentSupply(energyPerHolonObject);
|
|
|
- } else if (model.getFairnessModel() == fairnessMininumDemandFirst) {
|
|
|
- /* fairness: minimum demand gets Energy first */
|
|
|
- if ((production + consumption) >= 0) {
|
|
|
- if (energySurplus > 0) {
|
|
|
- hl.setState(HolonObject.OVER_SUPPLIED);
|
|
|
- hl.setCurrentSupply((-energySurplus
|
|
|
- / consumption + 1)
|
|
|
- * hl.getCurrentEnergyAtTimeStep(x));
|
|
|
- } else {
|
|
|
- hl.setState(HolonObject.SUPPLIED);
|
|
|
- hl.setCurrentSupply(-hl
|
|
|
- .getCurrentEnergyAtTimeStep(x));
|
|
|
- }
|
|
|
- } else {
|
|
|
- float minEnergy = hl.getMinEnergy(x);
|
|
|
- if (hl.checkIfPartiallySupplied(timeStep)) {
|
|
|
- hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- currentProduction += minEnergy;
|
|
|
- hl.setCurrentSupply(-minEnergy);
|
|
|
- partiallySuppliedList.add(hl);
|
|
|
- } else {
|
|
|
- /**
|
|
|
- * Case that only some HolonObjects can
|
|
|
- * be supplied
|
|
|
- */
|
|
|
- if (-hl.getCurrentEnergyAtTimeStep(x) <= currentProduction) {
|
|
|
- hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- currentProduction += minEnergy;
|
|
|
- hl.setCurrentSupply(-minEnergy);
|
|
|
- partiallySuppliedList.add(hl);
|
|
|
- } else if (-hl.getMinEnergy(x) <= currentProduction) {
|
|
|
- hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- currentProduction += minEnergy;
|
|
|
- hl.setCurrentSupply(-minEnergy);
|
|
|
- partiallySuppliedList.add(hl);
|
|
|
- } else {
|
|
|
- hl.setState(HolonObject.NOT_SUPPLIED);
|
|
|
- hl.setCurrentSupply(0.0f);
|
|
|
- notSuppliedList.add(hl);
|
|
|
- // currentProduction +=
|
|
|
- // hl.getCurrentEnergyAtTimeStep(x);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- 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) {
|
|
|
- hl.setState(HolonObject.PARTIALLY_SUPPLIED);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (model.getFairnessModel() == fairnessMininumDemandFirst) {
|
|
|
- /**
|
|
|
- * check if some partially supplied building might be fully
|
|
|
- * supplied.
|
|
|
- */
|
|
|
- partiallySuppliedList.sort(new EnergyMinToMaxComparator(x));
|
|
|
- for (HolonObject hl : partiallySuppliedList) {
|
|
|
- float minEnergy = hl.getMinEnergy(x);
|
|
|
- currentProduction -= minEnergy;
|
|
|
- /*
|
|
|
- * if possible, supply fully
|
|
|
- */
|
|
|
- float currentEnergyAtTimeStep = hl
|
|
|
- .getCurrentEnergyAtTimeStep(x);
|
|
|
- if (-currentEnergyAtTimeStep <= currentProduction) {
|
|
|
- hl.setState(HolonObject.SUPPLIED);
|
|
|
- currentProduction += currentEnergyAtTimeStep;
|
|
|
- hl.setCurrentSupply(-currentEnergyAtTimeStep);
|
|
|
- hl.getCurrentEnergyAtTimeStep(x);
|
|
|
- } else {
|
|
|
- currentProduction += minEnergy;
|
|
|
- notSuppliedList.add(hl);
|
|
|
- }
|
|
|
- }
|
|
|
- if (!notSuppliedList.isEmpty() && currentProduction > 0) {
|
|
|
- float energyPerHolon = currentProduction
|
|
|
- / notSuppliedList.size();
|
|
|
- for (HolonObject hl : notSuppliedList) {
|
|
|
- hl.setCurrentSupply(hl.getCurrentSupply()
|
|
|
- + energyPerHolon);
|
|
|
- hl.getCurrentEnergyAtTimeStep(x);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
/**
|
|
|
* add all battries.getOut() from a list of battries and return them
|
|
|
* @param aL a List of HolonBattries likely from subnet.getBatteries()
|