diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-09-06 14:53:01 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2017-09-06 15:20:32 +0200 |
| commit | 823bb2d217e6b35b1811b5f52016d8d9de09435d (patch) | |
| tree | 20f05d965f13bde7dfcbc7a7e744a367d2442588 | |
| parent | 36b36970623a503228c80b7148a83ca95e338334 (diff) | |
Implement time jumps to next event
This change implements a time jump to the next event in the queue if
there are no events scheduled for the current tick.
| -rw-r--r-- | opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt | 10 | ||||
| -rw-r--r-- | opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt | 2 |
2 files changed, 7 insertions, 5 deletions
diff --git a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt index 6b7407e5..764134e5 100644 --- a/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt +++ b/opendc-core/src/main/kotlin/nl/atlarge/opendc/simulator/omega/OmegaSimulator.kt @@ -121,13 +121,15 @@ class OmegaSimulator(override val topology: Topology): Simulator, Iterator<Unit> while (true) { val (tick, block) = clock.queue.peek() ?: return - if (tick > clock.tick) + if (tick > clock.tick) { // Tick has yet to occur + // Jump in time to next event + clock.tick = tick - 1 break - else if (tick < clock.tick) + } else if (tick < clock.tick) { // Tick has already occurred - logger.warn {"tick was not handled correctly"} - + logger.warn { "tick was not handled correctly" } + } clock.queue.poll() block() } diff --git a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt index 7d3c317e..50e22734 100644 --- a/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt +++ b/opendc-core/src/test/kotlin/nl/atlarge/opendc/SmokeTest.kt @@ -37,7 +37,7 @@ internal class SmokeTest { val builder = AdjacencyListTopologyBuilder() val topology = builder.build().apply { val rack = node(Rack()) - val n = 1000000 + val n = 100 // Create n machines in the rack repeat(n) { val machine = node(Machine()) |
