-
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.
add initializer and change to injection during tests
- Loading branch information
Showing
12 changed files
with
311 additions
and
39 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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/org/matsim/run/OpenBerlinParkingScenario.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,39 @@ | ||
package org.matsim.run; | ||
|
||
import org.matsim.core.config.Config; | ||
import org.matsim.core.controler.AbstractModule; | ||
import org.matsim.core.controler.Controler; | ||
import org.matsim.run.scoring.parking.*; | ||
|
||
|
||
/** | ||
* This class extends the Berlin scenario by parking search times. Currently, only one iteration is run based on that, scoring is performed. | ||
* By default, it uses the Belloche parking search model with a kernel of 500m distance. | ||
*/ | ||
public class OpenBerlinParkingScenario extends OpenBerlinScenario { | ||
@Override | ||
protected Config prepareConfig(Config config) { | ||
super.prepareConfig(config); | ||
|
||
config.controller().setLastIteration(1); | ||
config.network().setInputFile("with-parking"); | ||
config.controller().setOutputDirectory(config.controller().getOutputDirectory() + "-parking"); | ||
config.controller().setRunId(config.controller().getRunId() + "-parking"); | ||
|
||
return config; | ||
} | ||
|
||
@Override | ||
protected void prepareControler(Controler controler) { | ||
super.prepareControler(controler); | ||
|
||
controler.addOverridingModule(new AbstractModule() { | ||
@Override | ||
public void install() { | ||
bind(KernelFunction.class).to(ConstantKernelFunction.class); | ||
bind(PenaltyFunction.class).toInstance(new BellochePenaltyFunction(0.4, -6)); | ||
addEventHandlerBinding().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
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
13 changes: 13 additions & 0 deletions
13
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.network.Link; | ||
|
||
import java.util.Map; | ||
|
||
public interface ParkingCapacityInitializer { | ||
Map<Id<Link>, InitialParkingCapacity> initialize(); | ||
|
||
record InitialParkingCapacity(int capacity, int initial) { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
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; | ||
|
||
public class ParkingEventsHandler implements VehicleEntersTrafficEventHandler, VehicleLeavesTrafficEventHandler, TransitDriverStartsEventHandler { | ||
|
||
|
||
@Override | ||
public void handleEvent(TransitDriverStartsEvent event) { | ||
|
||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleEntersTrafficEvent event) { | ||
|
||
} | ||
|
||
@Override | ||
public void handleEvent(VehicleLeavesTrafficEvent event) { | ||
|
||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
src/main/java/org/matsim/run/scoring/parking/PlanBasedParkingCapacityInitializer.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,53 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import com.google.inject.Inject; | ||
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.Population; | ||
import org.matsim.core.router.TripStructureUtils; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
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 PlanBasedParkingCapacityInitializer implements ParkingCapacityInitializer { | ||
private Network network; | ||
private Population population; | ||
|
||
@Inject | ||
PlanBasedParkingCapacityInitializer(Network network, Population population) { | ||
this.network = network; | ||
this.population = population; | ||
} | ||
|
||
@Override | ||
public Map<Id<Link>, InitialParkingCapacity> initialize() { | ||
Map<Id<Link>, Long> initialParkingByPlans = getInitialParkingByPlans(); | ||
|
||
Map<Id<Link>, InitialParkingCapacity> 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 InitialParkingCapacity(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() { | ||
return population.getPersons().values().stream().map(p -> p.getSelectedPlan()) | ||
.map(p -> TripStructureUtils.findAccessWalksWithPreviousActivity(p, TransportMode.car).stream().findFirst()) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.map(lap -> lap.act.getLinkId()) | ||
.collect(Collectors.groupingBy(l -> l, Collectors.counting())); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/matsim/run/scoring/parking/ZeroParkingCapacityInitializer.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,33 @@ | ||
package org.matsim.run.scoring.parking; | ||
|
||
import com.google.inject.Inject; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.network.Link; | ||
import org.matsim.api.core.v01.network.Network; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
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 ZeroParkingCapacityInitializer implements ParkingCapacityInitializer { | ||
private Network network; | ||
|
||
@Inject | ||
ZeroParkingCapacityInitializer(Network network) { | ||
this.network = network; | ||
} | ||
|
||
@Override | ||
public Map<Id<Link>, InitialParkingCapacity> initialize() { | ||
Map<Id<Link>, InitialParkingCapacity> 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); | ||
res.put(link.getId(), new InitialParkingCapacity(onStreet + offStreet, 0)); | ||
} | ||
return res; | ||
} | ||
} |
Oops, something went wrong.