From 75cf2552302dd2e02cf5ead107e3f0323bb0fa5b Mon Sep 17 00:00:00 2001 From: Vincent Van Gestel Date: Tue, 18 Apr 2017 13:45:09 +0200 Subject: [PATCH] Shifted Shock Wave Events to 50% of Connection --- .../scenario/generator/DynamicSpeeds.java | 13 +++-- .../scenario/generator/DynamicSpeedsTest.java | 52 +++++++++++-------- 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/scenario-util/src/main/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeeds.java b/scenario-util/src/main/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeeds.java index 041884220..ba9b9db9e 100644 --- a/scenario-util/src/main/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeeds.java +++ b/scenario-util/src/main/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeeds.java @@ -496,6 +496,11 @@ private List simulateForwardRecedingShockwave() { (long) (actualRecedingTimestamp + conn.getLength() / recedingSpeed); } + final long exJump = + (nextActualExTimestamp - actualExpandingTimestamp) / 2; + final long reJump = + (nextActualReTimestamp - actualRecedingTimestamp) / 2; + // Check Stop conditions // Stop if shockwave has no effect (factor == 1) // OR if shockwave burned out (speed == 0) @@ -505,7 +510,8 @@ private List simulateForwardRecedingShockwave() { if (factor == 1 || forwardSpeed == 0 || nextRelExTimestamp >= eventDurationSupplier .get(rng.nextLong()) - || nextActualExTimestamp >= nextActualReTimestamp + || actualExpandingTimestamp + exJump >= actualRecedingTimestamp + + reJump || expansionMap.containsKey(conn)) { // Origin was last affected node leafNodes.add(origin); @@ -514,7 +520,7 @@ private List simulateForwardRecedingShockwave() { // Add conn final ChangeConnectionSpeedEvent newExEvent = - ChangeConnectionSpeedEvent.create(nextActualExTimestamp, + ChangeConnectionSpeedEvent.create(actualExpandingTimestamp + exJump, conn, factor); events.add(newExEvent); @@ -538,7 +544,8 @@ private List simulateForwardRecedingShockwave() { if (recedingSpeed != 0) { // Remove conn final ChangeConnectionSpeedEvent newReEvent = - ChangeConnectionSpeedEvent.create(nextActualReTimestamp, + ChangeConnectionSpeedEvent.create( + actualRecedingTimestamp + reJump, conn, factorInverse); events.add(newReEvent); } diff --git a/scenario-util/src/test/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeedsTest.java b/scenario-util/src/test/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeedsTest.java index 990a7cb1d..e83e65685 100644 --- a/scenario-util/src/test/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeedsTest.java +++ b/scenario-util/src/test/java/com/github/rinde/rinsim/scenario/generator/DynamicSpeedsTest.java @@ -183,12 +183,15 @@ public void straightLineShockwaveTest() { assertEquals(8, events.size()); /** - * Shockwave travels at 10 Km/h, the total distance if 1 Km. every 1.5 - * minute, a connection is crossed + * Shockwave travels at 10 Km/h, the total distance if 1 Km. First + * connection is crossed at 0.75 minute. every 1.5 minute later, the next + * connection is crossed */ - final long[] timings = new long[] {(long) (1.5 * MINUTE), 3 * MINUTE, - (long) (4.5 * MINUTE), 6 * MINUTE, - (long) (11.5 * MINUTE), 13 * MINUTE, (long) (14.5 * MINUTE), 16 * MINUTE}; + final long[] timings = + new long[] {(long) (0.75 * MINUTE), (long) (2.25 * MINUTE), + (long) (3.75 * MINUTE), (long) (5.25 * MINUTE), + (long) (10.75 * MINUTE), (long) (12.25 * MINUTE), + (long) (13.75 * MINUTE), (long) (15.25 * MINUTE)}; /** * Expanding shockwave halves the speed, receding shockwave doubles */ @@ -338,9 +341,9 @@ public void shockwaveSpeedTest() { * can. */ final long[] timings = - new long[] {(long) (1.5 * MINUTE), (long) (3.5 * MINUTE), - (long) (7.1 * MINUTE), - 13 * MINUTE, 19 * MINUTE}; + new long[] {(long) (0.75 * MINUTE), (long) (2.5 * MINUTE), + (long) (5.3 * MINUTE), + (long) (11.5 * MINUTE), 16 * MINUTE}; /** * Shockwave moves from connD -> connA */ @@ -409,9 +412,10 @@ public void shockwaveBoundaryTest() { * Shockwave speed remains at 10 Km/h, but duration limits shockwave to 5 * minutes */ - final long[] timings = new long[] {(long) (1.5 * MINUTE), 3 * MINUTE, - (long) (4.5 * MINUTE), - (long) (6.5 * MINUTE), 8 * MINUTE, (long) (9.5 * MINUTE)}; + final long[] timings = + new long[] {(long) (0.75 * MINUTE), (long) (2.25 * MINUTE), + (long) (3.75 * MINUTE), + (long) (5.75 * MINUTE), (long) (7.25 * MINUTE), (long) (8.75 * MINUTE)}; /** * Shockwave moves from connD -> connA */ @@ -484,15 +488,20 @@ public void shockwaveCycleTest() { /** * Shockwave travels at 10 Km/h, the total distance if 1 Km. every 1.5 - * minute, a connection is crossed. After connD, it branches into a cycle + * minute, a connection is crossed (starting at 0.75). After connD, it + * branches into a cycle */ final long[] timings = - new long[] {(long) (1.5 * MINUTE), 3 * MINUTE, 3 * MINUTE, - (long) (4.5 * MINUTE), (long) (4.5 * MINUTE), 6 * MINUTE, 6 * MINUTE, - - (long) (11.5 * MINUTE), 13 * MINUTE, 13 * MINUTE, - (long) (14.5 * MINUTE), (long) (14.5 * MINUTE), 16 * MINUTE, - 16 * MINUTE}; + new long[] {(long) (0.75 * MINUTE), (long) (2.25 * MINUTE), + (long) (2.25 * MINUTE), + (long) (3.75 * MINUTE), (long) (3.75 * MINUTE), (long) (5.25 * MINUTE), + (long) (5.25 * MINUTE), + + (long) (10.75 * MINUTE), (long) (12.25 * MINUTE), + (long) (12.25 * MINUTE), + (long) (13.75 * MINUTE), (long) (13.75 * MINUTE), + (long) (15.25 * MINUTE), + (long) (15.25 * MINUTE)}; /** * Expanding shockwave halves the speed, receding shockwave doubles */ @@ -539,7 +548,7 @@ public void shockwaveBidirectionalTest() { assertEquals(2, events.size()); final long[] timings = - new long[] {(long) (1.5 * MINUTE), (long) (11.5 * MINUTE)}; + new long[] {(long) (0.75 * MINUTE), (long) (10.75 * MINUTE)}; /** * Expanding shockwave halves the speed, receding shockwave doubles */ @@ -621,14 +630,15 @@ public Double apply(@SuppressWarnings("null") Long input) { gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); - assertEquals(8, events.size()); + assertEquals(10, events.size()); /** * expansion = 4,16667 meters per second recession = 5,8138889 meters per * second */ final long[] timings = - new long[] {12000, 24000, 25600, 34200, 36000, 42800, 48000, 51400}; + new long[] {6000, 18000, 21300, 29900, 30000, 38500, 42000, 47100, 54000, + 55700}; for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(timings[i], event.getTime());