summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-power/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-power/src')
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt14
-rw-r--r--opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt14
2 files changed, 6 insertions, 22 deletions
diff --git a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt
index 3ce85d02..e8839496 100644
--- a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt
+++ b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimPdu.kt
@@ -47,21 +47,13 @@ public class SimPdu(
public fun newOutlet(): Outlet = Outlet(distributor.newOutput())
override fun createConsumer(): SimResourceConsumer = object : SimResourceConsumer by distributor {
- override fun onNext(ctx: SimResourceContext): SimResourceCommand {
- return when (val cmd = distributor.onNext(ctx)) {
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
+ return when (val cmd = distributor.onNext(ctx, now, delta)) {
is SimResourceCommand.Consume -> {
- val duration = cmd.work / cmd.limit
val loss = computePowerLoss(cmd.limit)
val newLimit = cmd.limit + loss
- SimResourceCommand.Consume(duration * newLimit, newLimit, cmd.deadline)
- }
- is SimResourceCommand.Idle -> {
- val loss = computePowerLoss(0.0)
- if (loss > 0.0)
- SimResourceCommand.Consume(Double.POSITIVE_INFINITY, loss, cmd.deadline)
- else
- cmd
+ SimResourceCommand.Consume(newLimit, cmd.duration)
}
else -> cmd
}
diff --git a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
index f9431d21..4c2beb68 100644
--- a/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
+++ b/opendc-simulator/opendc-simulator-power/src/main/kotlin/org/opendc/simulator/power/SimUps.kt
@@ -55,21 +55,13 @@ public class SimUps(
override fun onConnect(inlet: SimPowerInlet) {
val consumer = inlet.createConsumer()
aggregator.startConsumer(object : SimResourceConsumer by consumer {
- override fun onNext(ctx: SimResourceContext): SimResourceCommand {
- return when (val cmd = consumer.onNext(ctx)) {
+ override fun onNext(ctx: SimResourceContext, now: Long, delta: Long): SimResourceCommand {
+ return when (val cmd = consumer.onNext(ctx, now, delta)) {
is SimResourceCommand.Consume -> {
- val duration = cmd.work / cmd.limit
val loss = computePowerLoss(cmd.limit)
val newLimit = cmd.limit + loss
- SimResourceCommand.Consume(duration * newLimit, newLimit, cmd.deadline)
- }
- is SimResourceCommand.Idle -> {
- val loss = computePowerLoss(0.0)
- if (loss > 0.0)
- SimResourceCommand.Consume(Double.POSITIVE_INFINITY, loss, cmd.deadline)
- else
- cmd
+ SimResourceCommand.Consume(newLimit, cmd.duration)
}
else -> cmd
}