diff options
| author | Dante Niewenhuis <d.niewenhuis@hotmail.com> | 2024-12-06 09:21:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-06 09:21:19 +0100 |
| commit | b4f694d9083e28f67e1746a37f4761cda6699263 (patch) | |
| tree | 540a3b54f18c26068010b77c63b0c0f1a47c0c5c /opendc-simulator/opendc-simulator-flow/src/main/java/org | |
| parent | a49a3878758438fe8d04bf4c4d3e3ffc5873aace (diff) | |
Added 9 new tests specifically testing the Multiplexer. This assumes the Multiplexer is using MaxMinFairness given that this is currently the default and only fairness available in OpenDC. (#280)
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src/main/java/org')
| -rw-r--r-- | opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java index ece90c20..48177412 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/Multiplexer.java @@ -40,7 +40,7 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer private double totalDemand; // The total demand of all the consumers private double totalSupply; // The total supply from the supplier - private boolean overProvisioned = false; + private boolean overLoaded = false; private int currentConsumerIdx = -1; private double capacity; // What is the max capacity @@ -68,11 +68,10 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer private void distributeSupply() { // if supply >= demand -> push supplies to all tasks - // TODO: possible optimization -> Only has to be done for the specific consumer that changed demand - if (this.totalSupply >= this.totalDemand) { + if (this.totalSupply > this.totalDemand) { // If this came from a state of over provisioning, provide all consumers with their demand - if (this.overProvisioned) { + if (this.overLoaded) { for (int idx = 0; idx < this.consumerEdges.size(); idx++) { this.pushSupply(this.consumerEdges.get(idx), this.demands.get(idx)); } @@ -84,12 +83,12 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer this.currentConsumerIdx = -1; } - this.overProvisioned = false; + this.overLoaded = false; } // if supply < demand -> distribute the supply over all consumers else { - this.overProvisioned = true; + this.overLoaded = true; double[] supplies = redistributeSupply(this.demands, this.totalSupply); for (int idx = 0; idx < this.consumerEdges.size(); idx++) { @@ -178,6 +177,10 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer this.currentConsumerIdx = -1; + if (this.overLoaded) { + this.distributeSupply(); + } + this.pushDemand(this.supplierEdge, this.totalDemand); } @@ -205,7 +208,7 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer demands.set(idx, newDemand); this.totalDemand += (newDemand - prevDemand); - if (overProvisioned) { + if (overLoaded) { distributeSupply(); } @@ -216,7 +219,7 @@ public class Multiplexer extends FlowNode implements FlowSupplier, FlowConsumer @Override public void handleSupply(FlowEdge supplierEdge, double newSupply) { - this.totalSupply = newSupply; // Currently this is from a single supply, might turn into multiple suppliers + this.totalSupply = newSupply; this.distributeSupply(); } |
