-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
340 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/main/java/org/matsim/run/scoring/parking/EventBasedParkingCapacityInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import com.google.inject.Inject; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; | ||
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Network; | ||
import org.matsim.api.core.v01.population.Person; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.matsim.run.scoring.parking.ParkingObserver.LINK_OFF_STREET_SPOTS; | ||
import static org.matsim.run.scoring.parking.ParkingObserver.LINK_ON_STREET_SPOTS; | ||
|
||
public class EventBasedParkingCapacityInitializer implements ParkingCapacityInitializer { | ||
@Inject | ||
private Network network; | ||
|
||
@Override | ||
public Map<Id<Link>, ParkingInitialCapacity> initialize(List<VehicleEntersTrafficEvent> vehicleEntersTrafficEvents, List<VehicleLeavesTrafficEvent> vehicleLeavesTrafficEvents) { | ||
Map<Id<Link>, Long> initialParkingByPlans = getInitialParkingByPlans(vehicleEntersTrafficEvents); | ||
|
||
Map<Id<Link>, ParkingInitialCapacity> res = new HashMap<>(network.getLinks().size()); | ||
for (Link link : network.getLinks().values()) { | ||
int onStreet = (int) Optional.ofNullable(link.getAttributes().getAttribute(LINK_ON_STREET_SPOTS)).orElse(0); | ||
int offStreet = (int) Optional.ofNullable(link.getAttributes().getAttribute(LINK_OFF_STREET_SPOTS)).orElse(0); | ||
|
||
int initialParking = initialParkingByPlans.getOrDefault(link.getId(), 0L).intValue(); | ||
res.put(link.getId(), new ParkingInitialCapacity(onStreet + offStreet, initialParking)); | ||
} | ||
return res; | ||
} | ||
|
||
// Returns the number of parking spots on the link where the first car trip starts | ||
private Map<Id<Link>, Long> getInitialParkingByPlans(List<VehicleEntersTrafficEvent> vehicleEntersTrafficEvents) { | ||
|
||
|
||
Set<Id<Person>> visitedPerson = new HashSet<>(); | ||
return vehicleEntersTrafficEvents.stream() | ||
.filter(e -> visitedPerson.add(e.getPersonId())) | ||
.collect(Collectors.groupingBy(VehicleEntersTrafficEvent::getLinkId, Collectors.counting())); | ||
} | ||
} |
7 changes: 5 additions & 2 deletions
7
src/main/java/org/matsim/run/scoring/parking/ParkingCapacityInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; | ||
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; | ||
import org.matsim.api.core.v01.network.Link; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public interface ParkingCapacityInitializer { | ||
Map<Id<Link>, InitialParkingCapacity> initialize(); | ||
Map<Id<Link>, ParkingInitialCapacity> initialize(List<VehicleEntersTrafficEvent> vehicleEntersTrafficEvents, List<VehicleLeavesTrafficEvent> vehicleLeavesTrafficEvents); | ||
|
||
record InitialParkingCapacity(int capacity, int initial) { | ||
record ParkingInitialCapacity(int capacity, int initial) { | ||
} | ||
} |
53 changes: 51 additions & 2 deletions
53
src/main/java/org/matsim/run/scoring/parking/ParkingEventsHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,76 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.TransportMode; | ||
import org.matsim.api.core.v01.events.TransitDriverStartsEvent; | ||
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent; | ||
import org.matsim.api.core.v01.events.VehicleLeavesTrafficEvent; | ||
import org.matsim.api.core.v01.events.handler.TransitDriverStartsEventHandler; | ||
import org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler; | ||
import org.matsim.api.core.v01.events.handler.VehicleLeavesTrafficEventHandler; | ||
import org.matsim.vehicles.Vehicle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
public class ParkingEventsHandler implements VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, TransitDriverStartsEventHandler { | ||
|
||
private List<VehicleEntersTrafficEvent> vehicleEntersTrafficEvents = new ArrayList<>(); | ||
private List<VehicleLeavesTrafficEvent> vehicleLeavesTrafficEvents = new ArrayList<>(); | ||
|
||
private boolean locked = false; | ||
private Set<Id<Vehicle>> knownPtVehicles = new HashSet<>(); | ||
|
||
@Override | ||
public void handleEvent(TransitDriverStartsEvent event) { | ||
|
||
checkLocked(); | ||
knownPtVehicles.add(event.getVehicleId()); | ||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleEntersTrafficEvent event) { | ||
checkLocked(); | ||
if (knownPtVehicles.contains(event.getVehicleId())) { | ||
return; | ||
} | ||
|
||
if (!event.getNetworkMode().equals(TransportMode.car)) { | ||
return; | ||
} | ||
|
||
vehicleEntersTrafficEvents.add(event); | ||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleLeavesTrafficEvent event) { | ||
checkLocked(); | ||
if (knownPtVehicles.contains(event.getVehicleId())) { | ||
return; | ||
} | ||
|
||
if (!event.getNetworkMode().equals(TransportMode.car)) { | ||
return; | ||
} | ||
|
||
vehicleLeavesTrafficEvents.add(event); | ||
} | ||
|
||
public List<VehicleEntersTrafficEvent> getVehicleEntersTrafficEvents() { | ||
return vehicleEntersTrafficEvents; | ||
} | ||
|
||
public List<VehicleLeavesTrafficEvent> getVehicleLeavesTrafficEvents() { | ||
return vehicleLeavesTrafficEvents; | ||
} | ||
|
||
public void lock() { | ||
locked = true; | ||
} | ||
|
||
private void checkLocked() { | ||
if (locked) { | ||
throw new IllegalStateException("This handler is locked. It is expected that it is only locked after processing all events."); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/matsim/run/scoring/parking/ParkingModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import com.google.inject.Singleton; | ||
import org.matsim.core.controler.AbstractModule; | ||
import org.matsim.modechoice.estimators.ActivityEstimator; | ||
import org.matsim.modechoice.estimators.DefaultActivityEstimator; | ||
import org.matsim.modechoice.estimators.DefaultLegScoreEstimator; | ||
import org.matsim.modechoice.estimators.LegEstimator; | ||
|
||
public class ParkingModule extends AbstractModule { | ||
@Override | ||
public void install() { | ||
// bind classes from informed mode choice explicitly | ||
bind(ActivityEstimator.class).to(DefaultActivityEstimator.class); | ||
bind(LegEstimator.class).to(DefaultLegScoreEstimator.class); | ||
|
||
// bind parking classes | ||
bind(KernelFunction.class).to(ConstantKernelFunction.class); | ||
bind(PenaltyFunction.class).toInstance(new BellochePenaltyFunction(0.4, -6)); | ||
bind(ParkingCapacityInitializer.class).to(ZeroParkingCapacityInitializer.class); | ||
|
||
bind(ParkingObserver.class).in(Singleton.class); | ||
bind(ParkingEventsHandler.class).in(Singleton.class); | ||
addEventHandlerBinding().to(ParkingEventsHandler.class); | ||
addControlerListenerBinding().to(ParkingObserver.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.