org.matsim.api.core.v01.population.Person Java Examples
The following examples show how to use
org.matsim.api.core.v01.population.Person.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardMATSimScenarioTest.java From amodeus with GNU General Public License v2.0 | 6 votes |
private static void fixInvalidActivityLocations(Network network, Population population) { // In the test fixture there are agents who start and end activities on non-car links. This should not be happen and is fixed here. Network roadNetwork = NetworkUtils.createNetwork(); new TransportModeNetworkFilter(network).filter(roadNetwork, Collections.singleton("car")); for (Person person : population.getPersons().values()) for (Plan plan : person.getPlans()) for (PlanElement element : plan.getPlanElements()) if (element instanceof Activity) { Activity activity = (Activity) element; Link link = network.getLinks().get(activity.getLinkId()); if (!link.getAllowedModes().contains("car")) { link = NetworkUtils.getNearestLink(roadNetwork, link.getCoord()); activity.setLinkId(link.getId()); } } }
Example #2
Source File: PassengerAnalysisListener.java From amodeus with GNU General Public License v2.0 | 6 votes |
@Override public void handleEvent(LinkEnterEvent event) { if (AmodeusIdentifiers.isValid(event.getVehicleId())) { double distance = linkFinder.getDistance(event.getLinkId()); for (Id<Person> passengerId : passengers.getPassengerIds(event.getVehicleId())) { PassengerRideItem ride = currentRides.get(passengerId); if (ride == null) { throw new IllegalStateException("Found vehicle enter link without departure"); } ride.distance += distance; } } }
Example #3
Source File: TheApocalypse.java From amodeus with GNU General Public License v2.0 | 5 votes |
public TheApocalypse toNoMoreThan(int maxPrs, long seed) { List<Id<Person>> list = new ArrayList<>(population.getPersons().keySet()); Collections.shuffle(list, new Random(seed)); final int sizeAnte = list.size(); list.stream() // .limit(Math.max(0, sizeAnte - maxPrs)) // .forEach(population::removePerson); final int sizePost = population.getPersons().size(); GlobalAssert.that(sizePost <= maxPrs); return this; }
Example #4
Source File: WaitingTimeTest.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Test public void testConstantWaitingTime() { AmodeusConfigGroup config = createConfig(); AmodeusModeConfig operatorConfig = config.getModes().get(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getWaitingTimeEstimationConfig().setDefaultWaitingTime(123.0); Controler controller = createController(config); controller.run(); Population population = controller.getScenario().getPopulation(); int numberOfRoutes = 0; for (Person person : population.getPersons().values()) { Plan plan = person.getSelectedPlan(); for (PlanElement element : plan.getPlanElements()) { if (element instanceof Leg) { Leg leg = (Leg) element; AmodeusRoute route = (AmodeusRoute) leg.getRoute(); Assert.assertEquals(route.getWaitingTime().seconds(), 123.0, 1e-2); numberOfRoutes++; } } } Assert.assertEquals(100, numberOfRoutes); }
Example #5
Source File: TestScenarioGenerator.java From amodeus with GNU General Public License v2.0 | 5 votes |
static private void generatePopulation(Population population, Network network, Random random) { PopulationFactory populationFactory = population.getFactory(); List<Id<Link>> linkIds = network.getLinks().values().stream().map(link -> link.getId()).collect(Collectors.toList()); for (int k = 0; k < populationSize; k++) { Person person = populationFactory.createPerson(Id.createPersonId(k)); population.addPerson(person); Id<Link> originId = linkIds.get(random.nextInt(linkIds.size())); Id<Link> destinationId = linkIds.get(random.nextInt(linkIds.size())); double departureTime = random.nextDouble() * duration * 0.5; Plan plan = populationFactory.createPlan(); person.addPlan(plan); Activity originActivity = populationFactory.createActivityFromLinkId("activity", originId); originActivity.setEndTime(departureTime); originActivity.setCoord(network.getLinks().get(originId).getCoord()); plan.addActivity(originActivity); plan.addLeg(populationFactory.createLeg(defaultMode)); Activity destinationActivity = populationFactory.createActivityFromLinkId("activity", destinationId); destinationActivity.setCoord(network.getLinks().get(destinationId).getCoord()); plan.addActivity(destinationActivity); } }
Example #6
Source File: RunTest.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Test public void testStuckScoring() { AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup(); AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getGeneratorConfig().setNumberOfVehicles(0); avConfigGroup.addMode(operatorConfig); AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null); scoringParams.setMarginalUtilityOfWaitingTime(-0.84); Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup()); Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config); config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av Controler controler = new Controler(scenario); controler.addOverridingModule(new DvrpModule()); controler.addOverridingModule(new AmodeusModule()); controler.addOverridingQSimModule(new AmodeusQSimModule()); controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup)); controler.run(); for (Person person : scenario.getPopulation().getPersons().values()) { Assert.assertEquals(-1000.0, person.getSelectedPlan().getScore(), 1e-6); } }
Example #7
Source File: AmodeusRequest.java From amodeus with GNU General Public License v2.0 | 5 votes |
public AmodeusRequest(Id<Request> id, Id<Person> passengerId, Link pickupLink, Link dropoffLink, double submissionTime, String mode, AmodeusRoute route) { this.id = id; this.passengerId = passengerId; this.pickupLink = pickupLink; this.dropoffLink = dropoffLink; this.submissionTime = submissionTime; this.mode = mode; this.route = route; }
Example #8
Source File: AmodeusRequestEvent.java From amodeus with GNU General Public License v2.0 | 5 votes |
private AmodeusRequestEvent(double time, Id<Person> personId, String mode, Optional<Double> expectedDistance, OptionalTime expectedTravelTime, Optional<Double> expectedPrice, OptionalTime expectedWaitingTime) { super(time); this.personId = personId; this.mode = mode; this.expectedDistance = expectedDistance; this.expectedTravelTime = expectedTravelTime; this.expectedPrice = expectedPrice; this.expectedWaitingTime = expectedWaitingTime; }
Example #9
Source File: AmodeusScoringParametersForPerson.java From amodeus with GNU General Public License v2.0 | 5 votes |
public AmodeusModalScoringParameters getScoringParameters(Person person) { String subpopulation = PopulationUtils.getSubpopulation(person); ScoringParameters scoringParameters = delegate.getScoringParameters(person); if (!parameters.containsKey(subpopulation)) { parameters.put(subpopulation, new AmodeusModalScoringParameters(subpopulation, amodeusConfig, scoringParameters)); } return parameters.get(subpopulation); }
Example #10
Source File: PassengerTracker.java From amodeus with GNU General Public License v2.0 | 5 votes |
public void removePassenger(Id<Vehicle> vehicleId, Id<Person> passengerId) { ensurePassengers(vehicleId); if (!passengers.get(vehicleId).remove(passengerId)) { throw new IllegalStateException(String.format("Passenger '%s' is not in vehicle '%s'", passengerId, vehicleId)); } }
Example #11
Source File: PassengerTracker.java From amodeus with GNU General Public License v2.0 | 5 votes |
public void addPassenger(Id<Vehicle> vehicleId, Id<Person> passengerId) { ensurePassengers(vehicleId); if (!passengers.get(vehicleId).add(passengerId)) { throw new IllegalStateException(String.format("Passenger '%s' is already in vehicle '%s'", passengerId, vehicleId)); } }
Example #12
Source File: NetworkCreatorUtils.java From amodeus with GNU General Public License v2.0 | 5 votes |
/** @param population * @param network * @return double of length m,2 with m datapoints and their x,y coordinate where datapoits represent all * Activities of agents in population. */ public static double[][] fromPopulation(Population population, Network network) { // FOR ALL activities find positions, record in list and store in array List<double[]> dataList = new ArrayList<>(); for (Person person : population.getPersons().values()) for (Plan plan : person.getPlans()) for (PlanElement planElement : plan.getPlanElements()) if (planElement instanceof Activity) { Activity activity = (Activity) planElement; if (!TripStructureUtils.isStageActivityType(activity.getType())) { Link link = network.getLinks().getOrDefault(activity.getLinkId(), null); if (Objects.nonNull(link)) { double x = link.getCoord().getX(); double y = link.getCoord().getY(); dataList.add(new double[] { x, y }); } else { LOGGER.warn(String.format("Link '%s' not found for agent '%s'. Either the link does not exist or has invalid modes?", activity.getLinkId().toString(), person.getId().toString())); } } } // final double data[][] = new double[dataList.size()][2]; // for (int i = 0; i < dataList.size(); ++i) { // data[i][0] = dataList.get(i)[0]; // data[i][1] = dataList.get(i)[1]; // } // return data; return dataList.toArray(new double[dataList.size()][2]); }
Example #13
Source File: TheRequestApocalypse.java From amodeus with GNU General Public License v2.0 | 5 votes |
public TheRequestApocalypse toNoMoreThan(int maxRequests, long seed) { final long legCount = LegCount.of(population, AmodeusModeConfig.DEFAULT_MODE); GlobalAssert.that(maxRequests <= legCount); if (legCount == maxRequests) return this; /** shuffle list of {@link Person}s */ List<Person> list = new ArrayList<>(population.getPersons().values()); Collections.shuffle(list, new Random(seed)); Iterator<Person> iterator = list.iterator(); // skip all persons that should completely remain in the population Person person = iterator.next(); int totReq = 0; long req = LegCount.of(person, AmodeusModeConfig.DEFAULT_MODE); while (totReq + req <= maxRequests) { totReq += req; person = iterator.next(); req = LegCount.of(person, AmodeusModeConfig.DEFAULT_MODE); } // create new person if needed to fill requests int split = maxRequests - totReq; if (split != 0) { Person splitPerson = SplitUp.of(population, person, split, AmodeusModeConfig.DEFAULT_MODE); req = LegCount.of(splitPerson, AmodeusModeConfig.DEFAULT_MODE); totReq += req; GlobalAssert.that(totReq == maxRequests); population.addPerson(splitPerson); } // remove all remaining persons iterator.forEachRemaining(p -> population.removePerson(p.getId())); population.removePerson(person.getId()); GlobalAssert.that(LegCount.of(population, AmodeusModeConfig.DEFAULT_MODE) == maxRequests); return this; }
Example #14
Source File: ParkingCapacityUniformRandomPopulationZone.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Override protected Collection<? extends Link> getLinks(Network network, Population population) { HashSet<Link> populatedLinks = new HashSet<>(); for (Person person : population.getPersons().values()) for (Plan plan : person.getPlans()) for (PlanElement planElement : plan.getPlanElements()) if (planElement instanceof Activity) { Activity activity = (Activity) planElement; populatedLinks.add(network.getLinks().get(activity.getLinkId())); } return populatedLinks; }
Example #15
Source File: DefaultParallelLeastCostPathCalculator.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Override public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) { Future<Path> future = executor.submit(() -> { LeastCostPathCalculator calculator = calculators.take(); Path path = calculator.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle); calculators.put(calculator); return path; }); // futures.add(future); return future; }
Example #16
Source File: LSDataTravelTime.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) { double speed = link.getFreespeed(); LinkSpeedTimeSeries timeSeries = lsData.get(link); if (Objects.nonNull(timeSeries)) speed = timeSeries.getSpeedsFloor((int) time); return link.getLength() / speed; }
Example #17
Source File: IDGenerator.java From amodeus with GNU General Public License v2.0 | 5 votes |
/** @return new ID which is not yet in set usedIDs */ public Id<Person> generateUnusedID() { largestInteger++; String newIDs = idName + String.format(format, largestInteger); Id<Person> newId = Id.create(newIDs, Person.class); usedIDs.add(newId); return newId; }
Example #18
Source File: CompatibilityModule.java From amodeus with GNU General Public License v2.0 | 5 votes |
@Override public void notifyStartup(StartupEvent event) { boolean anyWarnings = false; for (Person person : event.getServices().getScenario().getPopulation().getPersons().values()) { boolean skip = false; for (Plan plan : person.getPlans()) { if (skip) break; for (PlanElement element : plan.getPlanElements()) { if (skip) break; if (element instanceof Activity) { Activity activity = (Activity) element; if (activity.getCoord() == null) { logger.error(String.format("Agent '%s' has activity without coordiantes", person.getId())); anyWarnings = true; skip = true; } } } } } if (anyWarnings) throw new RuntimeException(// "Since the last update of Amodeus it is necessary that each activity in a MATSim popuatlion" // + " has a coordinate and not only a link ID to determine its location. You can either modify the way" // + " you generate your population or use the AddCoordinatesToActivities tool to automatically " // + "assign to each activity the coordinate of the currently associated link."); }
Example #19
Source File: CustomRouter.java From amod with GNU General Public License v2.0 | 4 votes |
@Override public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) { /** here a path neets to be computed and returned accordign to your custom logic */ throw new RuntimeException("This CustomRouter is not functional."); }
Example #20
Source File: RunTest.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Test public void testAVExampleWithAccessEgress() { AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup(); AmodeusModeConfig operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getGeneratorConfig().setNumberOfVehicles(100); operatorConfig.getPricingConfig().setPricePerKm(0.48); operatorConfig.getPricingConfig().setSpatialBillingInterval(1000.0); avConfigGroup.addMode(operatorConfig); AmodeusScoringConfig scoringParams = operatorConfig.getScoringParameters(null); scoringParams.setMarginalUtilityOfWaitingTime(-0.84); operatorConfig.setUseAccessAgress(true); Config config = ConfigUtils.createConfig(avConfigGroup, new DvrpConfigGroup()); Scenario scenario = TestScenarioGenerator.generateWithAVLegs(config); Iterator<? extends Person> iterator = scenario.getPopulation().getPersons().values().iterator(); for (int i = 0; i < 3; i++) { Person person = iterator.next(); for (PlanElement element : person.getSelectedPlan().getPlanElements()) { if (element instanceof Activity) { Activity activity = (Activity) element; activity.setCoord(CoordUtils.plus(activity.getCoord(), new Coord(5.0, 5.0))); } } } ActivityParams activityParams = new ActivityParams("amodeus interaction"); activityParams.setTypicalDuration(1.0); config.planCalcScore().addActivityParams(activityParams); PlanCalcScoreConfigGroup.ModeParams modeParams = config.planCalcScore().getOrCreateModeParams(AmodeusModeConfig.DEFAULT_MODE); // Refactor av modeParams.setMonetaryDistanceRate(0.0); modeParams.setMarginalUtilityOfTraveling(8.86); modeParams.setConstant(0.0); Controler controler = new Controler(scenario); controler.addOverridingModule(new DvrpModule()); controler.addOverridingModule(new AmodeusModule()); controler.addOverridingQSimModule(new AmodeusQSimModule()); controler.configureQSimComponents(AmodeusQSimModule.activateModes(avConfigGroup)); TestScenarioAnalyzer analyzer = new TestScenarioAnalyzer(); controler.addOverridingModule(analyzer); controler.run(); Assert.assertEquals(0, analyzer.numberOfDepartures - analyzer.numberOfArrivals); Assert.assertEquals(6, analyzer.numberOfInteractionActivities); }
Example #21
Source File: WaitingTimeTest.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Test public void testAttributeWaitingTime() { AmodeusConfigGroup config = createConfig(); AmodeusModeConfig operatorConfig = config.getModes().get(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getWaitingTimeEstimationConfig().setDefaultWaitingTime(123.0); operatorConfig.getWaitingTimeEstimationConfig().setConstantWaitingTimeLinkAttribute("avWaitingTime"); Controler controller = createController(config); Link link = controller.getScenario().getNetwork().getLinks().get(Id.createLinkId("8:9_9:9")); link.getAttributes().putAttribute("avWaitingTime", 456.0); controller.run(); Population population = controller.getScenario().getPopulation(); int numberOfRoutes = 0; int numberOfSpecialRoutes = 0; for (Person person : population.getPersons().values()) { Plan plan = person.getSelectedPlan(); for (PlanElement element : plan.getPlanElements()) { if (element instanceof Leg) { Leg leg = (Leg) element; AmodeusRoute route = (AmodeusRoute) leg.getRoute(); if (Id.createLinkId("8:9_9:9").equals(route.getStartLinkId())) { Assert.assertEquals(route.getWaitingTime().seconds(), 456.0, 1e-2); numberOfSpecialRoutes++; } else { Assert.assertEquals(route.getWaitingTime().seconds(), 123.0, 1e-2); } numberOfRoutes++; } } } Assert.assertEquals(100, numberOfRoutes); Assert.assertEquals(2, numberOfSpecialRoutes); }
Example #22
Source File: WaitingTimeTest.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Test public void testDynamicWaitingTime() { AmodeusConfigGroup config = createConfig(); AmodeusModeConfig operatorConfig = config.getModes().get(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getWaitingTimeEstimationConfig().setDefaultWaitingTime(123.0); operatorConfig.getWaitingTimeEstimationConfig().setConstantWaitingTimeLinkAttribute("avWaitingTime"); operatorConfig.getWaitingTimeEstimationConfig().setEstimationLinkAttribute("avGroup"); operatorConfig.getWaitingTimeEstimationConfig().setEstimationAlpha(0.7); Controler controller = createController(config); Link link = controller.getScenario().getNetwork().getLinks().get(Id.createLinkId("8:9_9:9")); link.getAttributes().putAttribute("avWaitingTime", 456.0); int index = 0; for (Link _link : controller.getScenario().getNetwork().getLinks().values()) { _link.getAttributes().putAttribute("avGroup", index++); } controller.getConfig().controler().setLastIteration(2); StrategySettings strategy = new StrategySettings(); strategy.setStrategyName("ReRoute"); strategy.setWeight(1.0); controller.getConfig().strategy().addStrategySettings(strategy); List<Double> waitingTimes = new LinkedList<>(); controller.addControlerListener(new IterationEndsListener() { @Override public void notifyIterationEnds(IterationEndsEvent event) { Population population = event.getServices().getScenario().getPopulation(); Person person = population.getPersons().get(Id.createPersonId(17)); Plan plan = person.getSelectedPlan(); for (PlanElement element : plan.getPlanElements()) { if (element instanceof Leg) { Leg leg = (Leg) element; AmodeusRoute route = (AmodeusRoute) leg.getRoute(); if (Id.createLinkId("8:9_9:9").equals(route.getStartLinkId())) { waitingTimes.add(route.getWaitingTime().seconds()); } } } } }); controller.run(); Assert.assertEquals(456.0, waitingTimes.get(0), 1e-3); Assert.assertEquals(144.5, waitingTimes.get(1), 1e-3); Assert.assertEquals(51.05, waitingTimes.get(2), 1e-3); }
Example #23
Source File: WaitingTimeTest.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Test public void testDynamicWaitingTimeWithoutConstantAttribute() { AmodeusConfigGroup config = createConfig(); AmodeusModeConfig operatorConfig = config.getModes().get(AmodeusModeConfig.DEFAULT_MODE); operatorConfig.getWaitingTimeEstimationConfig().setDefaultWaitingTime(123.0); operatorConfig.getWaitingTimeEstimationConfig().setEstimationLinkAttribute("avGroup"); operatorConfig.getWaitingTimeEstimationConfig().setEstimationAlpha(0.7); Controler controller = createController(config); Link link = controller.getScenario().getNetwork().getLinks().get(Id.createLinkId("8:9_9:9")); link.getAttributes().putAttribute("avWaitingTime", 456.0); int index = 0; for (Link _link : controller.getScenario().getNetwork().getLinks().values()) { _link.getAttributes().putAttribute("avGroup", index++); } controller.getConfig().controler().setLastIteration(2); StrategySettings strategy = new StrategySettings(); strategy.setStrategyName("ReRoute"); strategy.setWeight(1.0); controller.getConfig().strategy().addStrategySettings(strategy); List<Double> waitingTimes = new LinkedList<>(); controller.addControlerListener(new IterationEndsListener() { @Override public void notifyIterationEnds(IterationEndsEvent event) { Population population = event.getServices().getScenario().getPopulation(); Person person = population.getPersons().get(Id.createPersonId(17)); Plan plan = person.getSelectedPlan(); for (PlanElement element : plan.getPlanElements()) { if (element instanceof Leg) { Leg leg = (Leg) element; AmodeusRoute route = (AmodeusRoute) leg.getRoute(); if (Id.createLinkId("8:9_9:9").equals(route.getStartLinkId())) { waitingTimes.add(route.getWaitingTime().seconds()); } } } } }); controller.run(); Assert.assertEquals(123.0, waitingTimes.get(0), 1e-3); Assert.assertEquals(44.6, waitingTimes.get(1), 1e-3); Assert.assertEquals(21.08, waitingTimes.get(2), 1e-3); }
Example #24
Source File: DefaultAmodeusRouter.java From amodeus with GNU General Public License v2.0 | 4 votes |
@Override public Future<Path> calcLeastCostPath(Node fromNode, Node toNode, double starttime, Person person, Vehicle vehicle) { return delegate.calcLeastCostPath(fromNode, toNode, starttime, person, vehicle); }
Example #25
Source File: ScheduleRoutersGtfsShapes.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { return this.calcLinkTravelCost(link); }
Example #26
Source File: ScheduleRoutersGtfsShapes.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) { return link.getLength() / link.getFreespeed(); }
Example #27
Source File: ScheduleRoutersStandard.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { return this.getLinkMinimumTravelDisutility(link); }
Example #28
Source File: ScheduleRoutersStandard.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) { return link.getLength() / link.getFreespeed(); }
Example #29
Source File: ScheduleRoutersOsmAttributes.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) { return calcLinkTravelCost(link); }
Example #30
Source File: ScheduleRoutersOsmAttributes.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
@Override public double getLinkTravelTime(Link link, double time, Person person, Vehicle vehicle) { return link.getLength() / link.getFreespeed(); }