DynamicSpeeds { public static Builder builder() { return new Builder(); } private  DynamicSpeeds(); static List<DynamicSpeedGenerator> zeroEvents(); static Builder builder();  }
@SuppressWarnings("unchecked") @Test public void straightLineShockwaveTest() { Point A, B, C, D, E; A = new Point(0, 0); B = new Point(0, 250); C = new Point(0, 500); D = new Point(0, 750); E = new Point(0, 1000); Connection<MultiAttributeData> connA, connB, connC, connD; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB, connC, connD)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connD)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(10 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(HALF)) .shockwaveExpandingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .shockwaveRecedingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(8, events.size()); 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)}; final double[] factors = new double[] {0.5, 0.5, 0.5, 0.5, 2, 2, 2, 2}; final List<Connection<MultiAttributeData>> conns = new LinkedList<>(); conns.add(connD); conns.add(connC); conns.add(connB); conns.add(connA); conns.add(connD); conns.add(connC); conns.add(connB); conns.add(connA); for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(timings[i], event.getTime()); assertEquals(factors[i], event.getFactor(), DELTA); } }
@SuppressWarnings("unchecked") @Test public void behaviourDistanceTest() { Point A, B, C, D, E, F; A = new Point(0, 0); B = new Point(0, 250); C = new Point(0, 500); D = new Point(0, 750); E = new Point(0, 1000); F = new Point(0, 1250); Connection<MultiAttributeData> connA, connB, connC, connD, connE; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); connE = Connection.create(E, F, MultiAttributeData.builder().setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB, connC, connD, connE)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connE)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(10 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(LINEAR_DESCENDING)) .shockwaveExpandingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .shockwaveRecedingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(8, events.size()); final double[] factors = new double[] {0.3, 0.5, 0.7, 0.9, 3.333333333, 2, 1.428571429, 1.111111}; final List<Connection<MultiAttributeData>> conns = new LinkedList<>(); conns.add(connE); conns.add(connD); conns.add(connC); conns.add(connB); conns.add(connE); conns.add(connD); conns.add(connC); conns.add(connB); for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(factors[i], event.getFactor(), DELTA); } }
@SuppressWarnings("unchecked") @Test public void shockwaveSpeedTest() { Point A, B, C, D, E; A = new Point(0, 0); B = new Point(0, 250); C = new Point(0, 500); D = new Point(0, 750); E = new Point(0, 1000); Connection<MultiAttributeData> connA, connB, connC, connD; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB, connC, connD)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connD)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(10 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(HALF)) .shockwaveExpandingSpeed( StochasticSuppliers.constant(FROM_TEN_KM_H_DESCENDING)) .shockwaveRecedingSpeed( StochasticSuppliers.constant(FROM_FIVE_KM_H_DESCENDING)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(5, events.size()); final long[] timings = new long[] {(long) (0.75 * MINUTE), (long) (2.5 * MINUTE), (long) (5.3 * MINUTE), (long) (11.5 * MINUTE), 16 * MINUTE}; final List<Connection<MultiAttributeData>> conns = new LinkedList<>(); conns.add(connD); conns.add(connC); conns.add(connB); conns.add(connD); conns.add(connC); for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(timings[i], event.getTime()); } }
@SuppressWarnings("unchecked") @Test public void shockwaveBoundaryTest() { Point A, B, C, D, E; A = new Point(0, 0); B = new Point(0, 250); C = new Point(0, 500); D = new Point(0, 750); E = new Point(0, 1000); Connection<MultiAttributeData> connA, connB, connC, connD; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB, connC, connD)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connD)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(5 * MINUTE)) .shockwaveEventDurations(StochasticSuppliers.constant(5 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(HALF)) .shockwaveExpandingSpeed( StochasticSuppliers.constant(TEN_KM_H)) .shockwaveRecedingSpeed( StochasticSuppliers.constant(TEN_KM_H)) .build(); scenarioLength = 10 * MINUTE; final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(6, events.size()); 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)}; final List<Connection<MultiAttributeData>> conns = new LinkedList<>(); conns.add(connD); conns.add(connC); conns.add(connB); conns.add(connD); conns.add(connC); conns.add(connB); for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(timings[i], event.getTime()); } }
@SuppressWarnings("unchecked") @Test public void shockwaveCycleTest() { Point A, B, C, D, E, Cprime, Dprime; A = new Point(0, 0); B = new Point(0, 250); C = new Point(0, 500); D = new Point(0, 750); E = new Point(0, 1000); Cprime = new Point(1, 500); Dprime = new Point(1, 750); Connection<MultiAttributeData> connA, connB, connC, connD; Connection<MultiAttributeData> connCprime, connDprime, connDD; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, C, MultiAttributeData.builder().setMaxSpeed(100).build()); connC = Connection.create(C, D, MultiAttributeData.builder().setMaxSpeed(100).build()); connD = Connection.create(D, E, MultiAttributeData.builder().setMaxSpeed(100).build()); connCprime = Connection.create(Cprime, D, MultiAttributeData.builder().setLength(250).setMaxSpeed(100).build()); connDprime = Connection.create(Dprime, Cprime, MultiAttributeData.builder().setLength(250).setMaxSpeed(100).build()); connDD = Connection.create(D, Dprime, MultiAttributeData.builder().setLength(250).setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB, connC, connD)); graph.addConnections(Lists.newArrayList(connCprime, connDprime, connDD)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connD)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(10 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(HALF)) .shockwaveExpandingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .shockwaveRecedingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(14, events.size()); final long[] timings = 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)}; final double[] factors = new double[] {0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 2, 2, 2, 2, 2, 2, 2}; for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(timings[i], event.getTime()); assertEquals(factors[i], event.getFactor(), DELTA); } }
@SuppressWarnings("unchecked") @Test public void shockwaveBidirectionalTest() { Point A, B; A = new Point(0, 0); B = new Point(0, 250); Connection<MultiAttributeData> connA, connB; connA = Connection.create(A, B, MultiAttributeData.builder().setMaxSpeed(100).build()); connB = Connection.create(B, A, MultiAttributeData.builder().setMaxSpeed(100).build()); graph.addConnections(Lists.newArrayList(connA, connB)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connA)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(10 * MINUTE)) .shockwaveBehaviour(StochasticSuppliers.constant(HALF)) .shockwaveExpandingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .shockwaveRecedingSpeed(StochasticSuppliers.constant(TEN_KM_H)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(2, events.size()); final long[] timings = new long[] {(long) (0.75 * MINUTE), (long) (10.75 * MINUTE)}; final double[] factors = new double[] {0.5, 2}; final List<Connection<MultiAttributeData>> conns = new LinkedList<>(); conns.add(connA); conns.add(connA); for (int i = 0; i < events.size(); i++) { final ChangeConnectionSpeedEvent event = events.get(i); assertEquals(conns.get(i).from(), event.getFrom()); assertEquals(conns.get(i).to(), event.getTo()); assertEquals(timings[i], event.getTime()); assertEquals(factors[i], event.getFactor(), DELTA); } }
@Test public void shockwaveTrafficLightTest() { Point a, A, B, C, D, E, F, f; a = new Point(-50, 0); A = new Point(0, 0); B = new Point(50, 0); C = new Point(100, 0); D = new Point(150, 0); E = new Point(200, 0); F = new Point(250, 0); f = new Point(300, 0); Connection<MultiAttributeData> conna, connA, connB, connC, connD, connE, connF; conna = Connection.create(A, a, MultiAttributeData.builder().setMaxSpeed(50).build()); connA = Connection.create(B, A, MultiAttributeData.builder().setMaxSpeed(50).build()); connB = Connection.create(C, B, MultiAttributeData.builder().setMaxSpeed(50).build()); connC = Connection.create(D, C, MultiAttributeData.builder().setMaxSpeed(50).build()); connD = Connection.create(E, D, MultiAttributeData.builder().setMaxSpeed(50).build()); connE = Connection.create(F, E, MultiAttributeData.builder().setMaxSpeed(50).build()); connF = Connection.create(f, F, MultiAttributeData.builder().setMaxSpeed(50).build()); final Function<Long, Double> twentySomethingKmH = new Function<Long, Double>() { @Override public Double apply(@SuppressWarnings("null") Long input) { return 2.093 * TEN_KM_H_IN_M_MILLIS; } }; graph.addConnections( Lists.newArrayList(conna, connA, connB, connC, connD, connE, connF)); final DynamicSpeedGenerator gen = builder.withGraph(graph) .startConnections(StochasticSuppliers.constant(connA)) .shockwaveWaitForRecedeDurations( StochasticSuppliers.constant(17 * SECOND)) .shockwaveBehaviour(StochasticSuppliers.constant(ZERO)) .shockwaveExpandingSpeed(StochasticSuppliers.constant(FIFTEEN_KM_H)) .shockwaveRecedingSpeed(StochasticSuppliers.constant(twentySomethingKmH)) .build(); final List<ChangeConnectionSpeedEvent> events = Lists.newArrayList( gen.generate(123, scenarioLength)); Collections.sort(events, EVENT_COMPARATOR); assertEquals(10, events.size()); final long[] timings = 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()); } }