|
| 1 | +package org.matsim.contrib.parking.parkingproxy; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.BeforeEach; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 6 | +import org.junit.jupiter.params.ParameterizedTest; |
| 7 | +import org.junit.jupiter.params.provider.ValueSource; |
| 8 | +import org.matsim.api.core.v01.Coord; |
| 9 | +import org.matsim.api.core.v01.Id; |
| 10 | +import org.matsim.api.core.v01.Scenario; |
| 11 | +import org.matsim.api.core.v01.population.Person; |
| 12 | +import org.matsim.api.core.v01.population.Plan; |
| 13 | +import org.matsim.core.config.ConfigUtils; |
| 14 | +import org.matsim.core.gbl.MatsimRandom; |
| 15 | +import org.matsim.core.population.PersonUtils; |
| 16 | +import org.matsim.core.population.PopulationUtils; |
| 17 | +import org.matsim.core.population.PopulationUtilsTest; |
| 18 | +import org.matsim.core.scenario.ScenarioUtils; |
| 19 | +import org.matsim.core.utils.collections.Tuple; |
| 20 | +import org.matsim.testcases.MatsimTestUtils; |
| 21 | + |
| 22 | +import java.util.Collection; |
| 23 | + |
| 24 | +import static org.junit.jupiter.api.Assertions.*; |
| 25 | + |
| 26 | +class InitialLoadGeneratorWithConstantShareTest { |
| 27 | + |
| 28 | + @RegisterExtension |
| 29 | + MatsimTestUtils testUtils = new MatsimTestUtils(); |
| 30 | + |
| 31 | + @BeforeEach |
| 32 | + void setUp() { |
| 33 | + MatsimRandom.reset(); |
| 34 | + } |
| 35 | + |
| 36 | + @ParameterizedTest |
| 37 | + @ValueSource(ints = {0, 1, 10}) |
| 38 | + void initialPositionsHalf(int scale) { |
| 39 | + Collection<? extends Person> people = getPeople(); |
| 40 | + |
| 41 | + InitialLoadGeneratorWithConstantShare initialLoadGenerator = new InitialLoadGeneratorWithConstantShare(people, scale, 500); |
| 42 | + Collection<Tuple<Coord, Integer>> tuples = initialLoadGenerator.calculateInitialCarPositions(); |
| 43 | + |
| 44 | + //with the matsim random seed, the result is deterministic 52 |
| 45 | + assertEquals(52, tuples.size()); |
| 46 | + tuples.stream().map(Tuple::getSecond).forEach(weight -> assertEquals(scale, weight)); |
| 47 | + } |
| 48 | + |
| 49 | + @ParameterizedTest |
| 50 | + @ValueSource(ints = {0, 1, 10}) |
| 51 | + void initialPositionsFull(int scale) { |
| 52 | + Collection<? extends Person> people = getPeople(); |
| 53 | + |
| 54 | + InitialLoadGeneratorWithConstantShare initialLoadGenerator = new InitialLoadGeneratorWithConstantShare(people, scale, 1000); |
| 55 | + Collection<Tuple<Coord, Integer>> tuples = initialLoadGenerator.calculateInitialCarPositions(); |
| 56 | + |
| 57 | + assertEquals(100, tuples.size()); |
| 58 | + tuples.stream().map(Tuple::getSecond).forEach(weight -> assertEquals(scale, weight)); |
| 59 | + } |
| 60 | + |
| 61 | + private static Collection<? extends Person> getPeople() { |
| 62 | + // create population with 100 persons at 0,i |
| 63 | + Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); |
| 64 | + for (int i = 0; i < 100; i++) { |
| 65 | + Person person = PopulationUtils.getFactory().createPerson(Id.createPersonId(i)); |
| 66 | + Plan plan = PopulationUtils.createPlan(person); |
| 67 | + plan.addActivity(PopulationUtils.getFactory().createActivityFromCoord("home", new Coord(0, i))); |
| 68 | + person.addPlan(plan); |
| 69 | + person.setSelectedPlan(plan); |
| 70 | + scenario.getPopulation().addPerson(person); |
| 71 | + } |
| 72 | + return scenario.getPopulation().getPersons().values(); |
| 73 | + } |
| 74 | +} |
0 commit comments