Commit 60060542 authored by Sebastian Hörl's avatar Sebastian Hörl
Browse files

Fix access/egress walk bug

parent 607f308e
......@@ -4,8 +4,10 @@ import java.net.URL;
import java.util.Collections;
import java.util.List;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.PopulationFactory;
import org.matsim.core.config.ConfigGroup;
......@@ -18,6 +20,7 @@ import org.matsim.core.router.RoutingModule;
import org.matsim.core.router.costcalculators.OnlyTimeDependentTravelDisutility;
import org.matsim.core.router.util.LeastCostPathCalculator;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.utils.collections.QuadTree;
import org.matsim.vehicles.VehicleType;
import com.google.inject.Key;
......@@ -78,27 +81,45 @@ public class SharedAVModule extends AbstractDiscreteModeChoiceExtension {
addControlerListenerBinding().to(WaitingTimeListener.class);
}
@Provides
@Singleton
@Named("service_area")
public QuadTree<Link> provideServiceAreaQuadTree(ServiceArea serviceArea, @Named(AVModule.AV_MODE) Network network) {
double[] bounds = NetworkUtils.getBoundingBox(network.getNodes().values());
QuadTree<Link> index = new QuadTree<>(bounds[0], bounds[1], bounds[2], bounds[3]);
for (Id<Link> linkId : serviceArea.getServedLinkIds()) {
Link link = network.getLinks().get(linkId);
if (link != null) {
index.put(link.getCoord().getX(), link.getCoord().getY(), link);
}
}
return index;
}
@Provides
@Named(AV_TAXI)
public RoutingModule provideAvTaxiRoutingModule(PopulationFactory populationFactory, AVRouteFactory routeFactory,
@Named(TransportMode.walk) RoutingModule walkRoutingModule, @Named(AVModule.AV_MODE) Network network,
AVWaitingTime waitingTime, @Named(AV_TAXI) TravelTime travelTime) {
AVWaitingTime waitingTime, @Named(AV_TAXI) TravelTime travelTime, @Named("service_area") QuadTree<Link> serviceAreaIndex) {
LeastCostPathCalculator router = new DijkstraFactory().createPathCalculator(network,
new OnlyTimeDependentTravelDisutility(travelTime), travelTime);
return new ASTRAAVRoutingModule(AV_TAXI, populationFactory, routeFactory, walkRoutingModule, router, network,
travelTime, waitingTime, false);
travelTime, waitingTime, false, serviceAreaIndex);
}
@Provides
@Named(AV_POOL)
public RoutingModule provideAvPoolRoutingModule(PopulationFactory populationFactory, AVRouteFactory routeFactory,
@Named(TransportMode.walk) RoutingModule walkRoutingModule, @Named(AVModule.AV_MODE) Network network,
AVWaitingTime waitingTime, @Named(AV_POOL) TravelTime travelTime) {
AVWaitingTime waitingTime, @Named(AV_POOL) TravelTime travelTime, @Named("service_area") QuadTree<Link> serviceAreaIndex) {
LeastCostPathCalculator router = new DijkstraFactory().createPathCalculator(network,
new OnlyTimeDependentTravelDisutility(travelTime), travelTime);
return new ASTRAAVRoutingModule(AV_POOL, populationFactory, routeFactory, walkRoutingModule, router, network,
travelTime, waitingTime, true);
travelTime, waitingTime, true, serviceAreaIndex);
}
@Provides
......@@ -110,7 +131,7 @@ public class SharedAVModule extends AbstractDiscreteModeChoiceExtension {
@Provides
@Singleton
public ServiceArea provideServiceArea(@Named(AVModule.AV_MODE) Network network, SharedAVConfigGroup astraConfig) {
public ServiceArea provideServiceArea(Network network, SharedAVConfigGroup astraConfig) {
ServiceAreaReader reader = new ServiceAreaReader(astraConfig.getServiceAreaAttribute(), network);
URL url = ConfigGroup.getInputFileURL(getConfig().getContext(), astraConfig.getServiceAreaShapefile());
return reader.read(astraConfig.getActiveServiceArea(), url);
......
......@@ -7,6 +7,7 @@ import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.PlanElement;
......@@ -20,6 +21,7 @@ import org.matsim.core.router.StageActivityTypes;
import org.matsim.core.router.StageActivityTypesImpl;
import org.matsim.core.router.util.LeastCostPathCalculator;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.utils.collections.QuadTree;
import org.matsim.facilities.Facility;
import ch.ethz.matsim.av.data.AVOperator;
......@@ -42,10 +44,12 @@ public class ASTRAAVRoutingModule implements RoutingModule {
private final String mode;
private final boolean isPooled;
private final QuadTree<Link> serviceAreaIndex;
public ASTRAAVRoutingModule(String mode, PopulationFactory populationFactory, AVRouteFactory routeFactory,
RoutingModule walkRoutingModule, LeastCostPathCalculator router, Network network, TravelTime travelTime,
AVWaitingTime waitingTime, boolean isPooled) {
AVWaitingTime waitingTime, boolean isPooled, QuadTree<Link> serviceAreaIndex) {
this.mode = mode;
this.populationFactory = populationFactory;
this.routeFactory = routeFactory;
......@@ -55,6 +59,7 @@ public class ASTRAAVRoutingModule implements RoutingModule {
this.travelTime = travelTime;
this.waitingTime = waitingTime;
this.isPooled = isPooled;
this.serviceAreaIndex = serviceAreaIndex;
}
@Override
......@@ -69,12 +74,14 @@ public class ASTRAAVRoutingModule implements RoutingModule {
Facility<?> dropoffFacility = destinationFacility;
if (pickupLink == null) {
pickupLink = NetworkUtils.getNearestLink(network, originFacility.getCoord());
//pickupLink = NetworkUtils.getNearestLink(network, originFacility.getCoord());
pickupLink = serviceAreaIndex.getClosest(originFacility.getCoord().getX(), destinationFacility.getCoord().getY());
pickupFacility = new LinkWrapperFacility(pickupLink);
}
if (dropoffLink == null) {
dropoffLink = NetworkUtils.getNearestLink(network, destinationFacility.getCoord());
//dropoffLink = NetworkUtils.getNearestLink(network, destinationFacility.getCoord());
dropoffLink = serviceAreaIndex.getClosest(destinationFacility.getCoord().getX(), destinationFacility.getCoord().getY());
dropoffFacility = new LinkWrapperFacility(dropoffLink);
}
......@@ -87,7 +94,10 @@ public class ASTRAAVRoutingModule implements RoutingModule {
elements.add(accessLeg);
departureTime += accessLeg.getTravelTime();
elements.add(populationFactory.createActivityFromLinkId(AV_INTERACTION_ACTIVITY_TYPE, pickupLink.getId()));
Activity interactionActivity = populationFactory.createActivityFromLinkId(AV_INTERACTION_ACTIVITY_TYPE,
pickupLink.getId());
interactionActivity.setMaximumDuration(0.0);
elements.add(interactionActivity);
}
double pickupWaitingTime = waitingTime.getWaitingTime(pickupLink, departureTime, isPooled);
......@@ -99,7 +109,7 @@ public class ASTRAAVRoutingModule implements RoutingModule {
avRoute.setDistance(VrpPaths.calcDistance(path));
avRoute.setTravelTime(path.getTravelTime());
ExtendedAVRoute extendedAvRoute = new ExtendedAVRoute(avRoute);
extendedAvRoute.setWaitingTime(pickupWaitingTime);
......@@ -116,7 +126,10 @@ public class ASTRAAVRoutingModule implements RoutingModule {
destinationFacility, departureTime, person);
Leg egressLeg = (Leg) egressElements.get(0);
elements.add(populationFactory.createActivityFromLinkId(AV_INTERACTION_ACTIVITY_TYPE, dropoffLink.getId()));
Activity interactionActivity = populationFactory.createActivityFromLinkId(AV_INTERACTION_ACTIVITY_TYPE,
dropoffLink.getId());
interactionActivity.setMaximumDuration(0.0);
elements.add(interactionActivity);
egressLeg.setMode(TransportMode.egress_walk);
elements.add(egressLeg);
......
......@@ -7,11 +7,9 @@ import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
public class ServiceArea {
private final Collection<Link> servedLinks;
private final Collection<Id<Link>> servedLinkIds;
public ServiceArea(Collection<Link> servedLinks) {
this.servedLinks = servedLinks;
this.servedLinkIds = servedLinks.stream().map(Link::getId).collect(Collectors.toSet());
}
......@@ -19,7 +17,7 @@ public class ServiceArea {
return servedLinkIds.contains(originId) && servedLinkIds.contains(destinationId);
}
public Collection<Link> getServedLinks() {
return servedLinks;
public Collection<Id<Link>> getServedLinkIds() {
return servedLinkIds;
}
}
......@@ -9,6 +9,7 @@ import java.util.stream.Collectors;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Person;
import org.matsim.api.core.v01.population.Plan;
......@@ -19,9 +20,11 @@ import org.matsim.core.config.groups.GlobalConfigGroup;
import org.matsim.core.utils.misc.Counter;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import ch.ethz.matsim.av.config.AVGeneratorConfig;
import ch.ethz.matsim.av.data.AVVehicle;
import ch.ethz.matsim.av.framework.AVModule;
import ch.ethz.matsim.av.generator.AVGenerator;
import ch.ethz.matsim.projects.astra_2018_002.shared_av.SharedAVConfigGroup;
import ch.ethz.matsim.projects.astra_2018_002.shared_av.SharedAVModule;
......@@ -79,6 +82,10 @@ public class ServiceAreaGenerator implements AVGenerator {
@Inject
GlobalConfigGroup globalConfig;
@Inject
@Named(AVModule.AV_MODE)
Network network;
@Override
public AVGenerator createGenerator(AVGeneratorConfig generatorConfig) {
String operator = generatorConfig.getParent().getId().toString();
......@@ -88,7 +95,17 @@ public class ServiceAreaGenerator implements AVGenerator {
Random random = new Random(globalConfig.getRandomSeed());
List<Link> links = new ArrayList<>(serviceArea.getServedLinks());
Set<Link> linkSet = new HashSet<>();
for (Id<Link> linkId : serviceArea.getServedLinkIds()) {
Link link = network.getLinks().get(linkId);
if (link != null) {
linkSet.add(link);
}
}
List<Link> links = new ArrayList<>(linkSet);
double[] cdf = calculateCDF(links);
return new ServiceAreaGenerator(prefix, numberOfVehicles, links, cdf, random);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment