Skip to content

Commit

Permalink
Shifted Shock Wave Events to 50% of Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentVanGestel committed Apr 18, 2017
1 parent 6eb1fb2 commit 75cf255
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@ private List<ChangeConnectionSpeedEvent> 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)
Expand All @@ -505,7 +510,8 @@ private List<ChangeConnectionSpeedEvent> 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);
Expand All @@ -514,7 +520,7 @@ private List<ChangeConnectionSpeedEvent> simulateForwardRecedingShockwave() {

// Add conn
final ChangeConnectionSpeedEvent newExEvent =
ChangeConnectionSpeedEvent.create(nextActualExTimestamp,
ChangeConnectionSpeedEvent.create(actualExpandingTimestamp + exJump,
conn, factor);
events.add(newExEvent);

Expand All @@ -538,7 +544,8 @@ private List<ChangeConnectionSpeedEvent> simulateForwardRecedingShockwave() {
if (recedingSpeed != 0) {
// Remove conn
final ChangeConnectionSpeedEvent newReEvent =
ChangeConnectionSpeedEvent.create(nextActualReTimestamp,
ChangeConnectionSpeedEvent.create(
actualRecedingTimestamp + reJump,
conn, factorInverse);
events.add(newReEvent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 75cf255

Please sign in to comment.