diff options
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src/main/java')
5 files changed, 15 insertions, 5 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java index 501bbf10..5cfd16ba 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/FlowDistributor.java @@ -60,6 +60,7 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, protected Double totalIncomingSupply = 0.0; // The total supply provided by the suppliers protected boolean outgoingDemandUpdateNeeded = false; + protected boolean outgoingSupplyUpdateNeeded = false; protected Set<Integer> updatedDemands = new HashSet<>(); // Array of consumers that updated their demand in this cycle @@ -142,6 +143,9 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, } this.totalIncomingDemand -= consumerEdge.getDemand(); + if (this.totalIncomingDemand < 0) { + this.totalIncomingDemand = 0.0; + } // Remove idx from consumers that updated their demands this.updatedDemands.remove(idx); @@ -204,6 +208,9 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, incomingDemands.set(idx, newDemand); // only update the total supply if the new supply is different from the previous one this.totalIncomingDemand += (newDemand - prevDemand); + if (totalIncomingDemand < 0) { + this.totalIncomingDemand = 0.0; + } this.updatedDemands.add(idx); @@ -230,6 +237,7 @@ public abstract class FlowDistributor extends FlowNode implements FlowSupplier, // only update the total supply if the new supply is different from the previous one this.totalIncomingSupply += (newSupply - prevSupply); + this.outgoingSupplyUpdateNeeded = true; this.invalidate(); } diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/BestEffortFlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/BestEffortFlowDistributor.java index 4a13beb2..703aca35 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/BestEffortFlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/BestEffortFlowDistributor.java @@ -148,6 +148,7 @@ public class BestEffortFlowDistributor extends FlowDistributor { } } + this.outgoingSupplyUpdateNeeded = false; this.updatedDemands.clear(); } @@ -264,7 +265,7 @@ public class BestEffortFlowDistributor extends FlowDistributor { } // Update supplies if needed - if (!this.outgoingSupplies.isEmpty() || updateNeeded) { + if (this.outgoingSupplyUpdateNeeded || updateNeeded) { this.updateOutgoingSupplies(); } diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/EqualShareFlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/EqualShareFlowDistributor.java index f58164cf..87ed7ca2 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/EqualShareFlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/EqualShareFlowDistributor.java @@ -54,6 +54,8 @@ public class EqualShareFlowDistributor extends FlowDistributor { } this.outgoingDemandUpdateNeeded = false; + this.updatedDemands.clear(); + this.invalidate(); } /** diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FirstFitPolicyFlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FirstFitPolicyFlowDistributor.java index c0a8cd13..9ab24d9f 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FirstFitPolicyFlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FirstFitPolicyFlowDistributor.java @@ -74,6 +74,7 @@ public class FirstFitPolicyFlowDistributor extends FlowDistributor { } this.outgoingDemandUpdateNeeded = false; + this.invalidate(); } /** diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FixedShareFlowDistributor.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FixedShareFlowDistributor.java index 4c0a84d1..f22ea9fb 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FixedShareFlowDistributor.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/engine/graph/distributionPolicies/FixedShareFlowDistributor.java @@ -112,9 +112,6 @@ public class FixedShareFlowDistributor extends FlowDistributor { } else { double[] supplies = distributeSupply(this.incomingDemands, this.outgoingSupplies, this.totalIncomingSupply); for (FlowEdge consumerEdge : this.consumerEdges) { - if (supplies[consumerIndex] <= 0.0) { - continue; - } this.pushOutgoingSupply(consumerEdge, this.fixedShare); } } @@ -123,7 +120,8 @@ public class FixedShareFlowDistributor extends FlowDistributor { public double[] distributeSupply(ArrayList<Double> demands, ArrayList<Double> currentSupply, double totalSupply) { double[] supplies = new double[this.consumerEdges.size()]; - if (this.consumerEdges.size() < this.supplierEdges.size()) { + if (this.consumerEdges.size() < this.supplierEdges.size() + && this.fixedShare * this.consumerEdges.size() <= totalSupply) { for (FlowEdge consumerEdge : this.consumerEdges) { supplies[consumerEdge.getConsumerIndex()] = this.fixedShare; } |
