Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: model update 2024 #266

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
eb692d8
activate epsilon by default
sebhoerl Sep 30, 2024
6649152
integrate transit routing parameters
sebhoerl Sep 30, 2024
d4a55d9
update crossing penalty
sebhoerl Sep 30, 2024
8ef5252
update choice model
sebhoerl Sep 30, 2024
748bac6
prepare for testing
sebhoerl Oct 1, 2024
757ea13
add fix for population routing
sebhoerl Oct 1, 2024
047bb4f
add modes for convergence
sebhoerl Oct 2, 2024
1ef466d
revert integration of motorbikes for no
sebhoerl Oct 3, 2024
0c8e288
further cleanup
sebhoerl Oct 3, 2024
9f95c51
fix
sebhoerl Oct 3, 2024
c1937f3
config
sebhoerl Oct 3, 2024
4d7f4c7
config
sebhoerl Oct 3, 2024
0938b21
reconfigure termination
sebhoerl Oct 3, 2024
9d5623f
revert termination configuration
sebhoerl Oct 3, 2024
18b3925
rename passenger -> car_passenger
sebhoerl Oct 3, 2024
a08a8bf
Merge branch 'develop' into feat/model-2024
sebhoerl Oct 3, 2024
a85e04f
update configurator
sebhoerl Oct 3, 2024
7c89534
update parameters without motorbike
sebhoerl Oct 3, 2024
8296a1c
add parking costs
sebhoerl Oct 7, 2024
a666bbb
update certain definitions in estimator
sebhoerl Oct 7, 2024
84a5e96
avoid circular dependency for predictor
sebhoerl Oct 7, 2024
65d1c10
fix error in cost model
sebhoerl Oct 7, 2024
ca57c26
idf pt estimator was not enabled
sebhoerl Oct 8, 2024
a57fa7d
fixes and forgot to add driving permit for car passenger
sebhoerl Oct 8, 2024
c064537
update passenger availability and some other parameters
sebhoerl Oct 9, 2024
c7a29a9
fix bug in cost model
sebhoerl Oct 9, 2024
a7e5984
test in pt model
sebhoerl Oct 10, 2024
64864b4
update model
sebhoerl Oct 10, 2024
361463a
add debugging output
sebhoerl Oct 12, 2024
db67327
revert debugging
sebhoerl Oct 12, 2024
b59c19b
formatting
sebhoerl Oct 12, 2024
f08ae29
rearranging some code
sebhoerl Oct 14, 2024
b685880
fix bug for pt variables
sebhoerl Oct 20, 2024
36b5aea
add vdf
sebhoerl Oct 21, 2024
3f1092a
fix vdf
sebhoerl Oct 21, 2024
2dd9a22
Merge branch 'develop' into feat/model-2024
sebhoerl Oct 21, 2024
ed09eea
update
sebhoerl Oct 21, 2024
a930864
fix capacity factor
sebhoerl Oct 23, 2024
511ff54
Merge branch 'develop' into feat/model-2024
sebhoerl Oct 29, 2024
3608c7d
Merge branch 'develop' into feat/model-2024
sebhoerl Nov 2, 2024
30f0372
fix
sebhoerl Nov 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ public EqasimRaptorConfigGroup() {
}

@Parameter
public double travelTimeRail_u_h = -7.0;
public double travelTimeRail_u_h = -1.4278139352278472;

@Parameter
public double travelTimeSubway_u_h = -7.0;
public double travelTimeSubway_u_h = -1.0;

@Parameter
public double travelTimeBus_u_h = -7.0;
public double travelTimeBus_u_h = -2.835025304050246;

@Parameter
public double travelTimeTram_u_h = -7.0;
public double travelTimeTram_u_h = -3.199594607188756;

@Parameter
public double travelTimeOther_u_h = -7.0;
public double travelTimeOther_u_h = -2.835025304050246;

@Parameter
public double perTransfer_u = -1.0;
public double perTransfer_u = -0.5441109013512305;

@Parameter
public double waitTime_u_h = -6.0;
public double waitTime_u_h = -0.497984826174775;

@Parameter
public double walkTime_u_h = -7.0;
public double walkTime_u_h = -3.8494071051697385;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.eqasim.core.components.traffic;

import org.matsim.api.core.v01.network.Link;

public interface CrossingPenalty {
double calculateCrossingPenalty(Link link);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.eqasim.core.components.traffic;

import org.matsim.api.core.v01.IdSet;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;

public class DefaultCrossingPenalty implements CrossingPenalty {
static public final String MAJOR_CROSSING_ATTRIBUTE = "eqasim:majorCrossing";

private final IdSet<Link> penalizedLinkIds;
private final double crossingPenalty;

DefaultCrossingPenalty(IdSet<Link> penalizedLinkIds, double crossingPenalty) {
this.penalizedLinkIds = penalizedLinkIds;
this.crossingPenalty = crossingPenalty;
}

@Override
public double calculateCrossingPenalty(Link link) {
if (penalizedLinkIds.contains(link.getId())) {
return crossingPenalty;
} else {
return 0.0;
}
}

static public DefaultCrossingPenalty build(Network network, double crossingPenalty) {
IdSet<Link> penalizedLinkIds = new IdSet<>(Link.class);

for (Link link : network.getLinks().values()) {
if (link.getAllowedModes().contains(TransportMode.car)) {
if (link.getToNode().getInLinks().size() > 1) { // otherwise straight road or diverge
double maximumCapacity = Double.NEGATIVE_INFINITY;
boolean foundLower = false;

for (Link inlink : link.getToNode().getInLinks().values()) {
if (inlink.getCapacity() > maximumCapacity) {
maximumCapacity = inlink.getCapacity();
}

foundLower |= inlink.getCapacity() < link.getCapacity();
}

if (link.getCapacity() == maximumCapacity && foundLower) {
penalizedLinkIds.add(link.getId());
}
}
}
}

return new DefaultCrossingPenalty(penalizedLinkIds, crossingPenalty);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,17 @@
import org.matsim.core.mobsim.qsim.qnetsimengine.QVehicle;

public class DefaultEqasimLinkSpeedCalculator implements EqasimLinkSpeedCalculator {
final private double crossingPenalty;
private final CrossingPenalty crossingPenalty;

public DefaultEqasimLinkSpeedCalculator(double crossingPenalty) {
public DefaultEqasimLinkSpeedCalculator(CrossingPenalty crossingPenalty) {
this.crossingPenalty = crossingPenalty;
}

@Override
public double getMaximumVelocity(QVehicle vehicle, Link link, double time) {
boolean isMajor = true;

for (Link other : link.getToNode().getInLinks().values()) {
if (other.getCapacity() >= link.getCapacity()) {
isMajor = false;
}
}

double maximumVelocity = Math.min(vehicle.getMaximumVelocity(), link.getFreespeed(time));

if (isMajor || link.getToNode().getInLinks().size() == 1) {
return maximumVelocity;
} else {
double travelTime = link.getLength() / maximumVelocity;
travelTime += crossingPenalty;
return link.getLength() / travelTime;
}
double travelTime = link.getLength() / maximumVelocity;
travelTime += crossingPenalty.calculateCrossingPenalty(link);
return link.getLength() / travelTime;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.eqasim.core.components.traffic;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.matsim.api.core.v01.network.Network;
import org.matsim.core.controler.AbstractModule;

import com.google.inject.Provides;
import com.google.inject.Singleton;

public class EqasimTrafficModule extends AbstractModule {
@Override
public void install() {
bind(CrossingPenalty.class).to(DefaultCrossingPenalty.class);
}

@Provides
@Singleton
public DefaultCrossingPenalty provideDefaultCrossingPenalty(Network network, EqasimConfigGroup eqasimConfig) {
return DefaultCrossingPenalty.build(network, eqasimConfig.getCrossingPenalty());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.eqasim.core.components.traffic;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.matsim.core.mobsim.qsim.AbstractQSimModule;

import com.google.inject.Provides;
Expand All @@ -15,7 +14,7 @@ protected void configureQSim() {

@Provides
@Singleton
public DefaultEqasimLinkSpeedCalculator provideDefaultEqasimLinkSpeedCalculator(EqasimConfigGroup eqasimConfig) {
return new DefaultEqasimLinkSpeedCalculator(eqasimConfig.getCrossingPenalty());
public DefaultEqasimLinkSpeedCalculator provideDefaultEqasimLinkSpeedCalculator(CrossingPenalty crossigPenalty) {
return new DefaultEqasimLinkSpeedCalculator(crossigPenalty);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.eqasim.core.scenario.preparation;

import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.CommandLine.ConfigurationException;

public class AdjustFreespeed {
static public final String INITIAL_FREESPEED = "eqasim:initialFreespeed";

static public void main(String[] args) throws ConfigurationException {
CommandLine commandLine = new CommandLine.Builder(args) //
.requireOptions("input-path", "output-path") //
.allowPrefixes("freespeed") //
.build();



}

static public void run(Network network) {

}

static public void validate(Scenario scenario) {
boolean valid = false;

for (Link link : scenario.getNetwork().getLinks().values()) {
if (link.getAttributes().getAttribute(INITIAL_FREESPEED) != null) {
valid = true;
break;
}
}

if (!valid) {
throw new IllegalStateException("Did not find initial freespeed. Did you call AdjustFreespeed?");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.matsim.api.core.v01.population.Population;
import org.matsim.core.router.TripStructureUtils;
import org.matsim.core.router.TripStructureUtils.StageActivityHandling;
import org.matsim.pt.transitSchedule.api.TransitSchedule;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;

public class ImputeSpatialAttribute {
private final Geometry geometry;
Expand All @@ -30,12 +32,17 @@ public void run(Population population) throws InterruptedException {

for (Person person : population.getPersons().values()) {
for (Plan plan : person.getPlans()) {
for (Activity activity : TripStructureUtils.getActivities(plan, StageActivityHandling.ExcludeStageActivities)) {
for (Activity activity : TripStructureUtils.getActivities(plan,
StageActivityHandling.ExcludeStageActivities)) {
Point point = factory
.createPoint(new Coordinate(activity.getCoord().getX(), activity.getCoord().getY()));

if (geometry.contains(point)) {
activity.getAttributes().putAttribute(attribute, true);

if (activity.getType().equals("home")) {
person.getAttributes().putAttribute(attribute, true);
}
}
}
}
Expand All @@ -62,4 +69,21 @@ public void run(Network network) throws InterruptedException {

progress.close();
}

public void run(TransitSchedule schedule) throws InterruptedException {
ParallelProgress progress = new ParallelProgress("Imputing spatial schedule attributes ...",
schedule.getFacilities().size());

for (TransitStopFacility facility : schedule.getFacilities().values()) {
Point point = factory.createPoint(new Coordinate(facility.getCoord().getX(), facility.getCoord().getY()));

if (geometry.covers(point)) {
facility.getAttributes().putAttribute(attribute, true);
}

progress.update();
}

progress.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
import org.matsim.core.population.io.PopulationReader;
import org.matsim.core.population.io.PopulationWriter;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.matsim.pt.transitSchedule.api.TransitScheduleWriter;

public class RunImputeSpatialAttribute {
static public void main(String[] args)
throws ConfigurationException, MalformedURLException, IOException, InterruptedException {
CommandLine cmd = new CommandLine.Builder(args) //
.allowOptions("input-population-path", "input-network-path", "output-population-path",
"output-network-path") //
"output-network-path", "input-schedule-path", "output-schedule-path") //
.requireOptions("shape-path", "shape-attribute", "shape-value", "attribute") //
.build();

Expand All @@ -36,6 +38,10 @@ static public void main(String[] args)
throw new IllegalStateException("Both input and output path must be given for the network.");
}

if (cmd.hasOption("input-schedule-path") ^ cmd.hasOption("output-schedule-path")) {
throw new IllegalStateException("Both input and output path must be given for the schedule.");
}

// Load shape
String shapeAttribute = cmd.getOptionStrict("shape-attribute");
String shapeValue = cmd.getOptionStrict("shape-value");
Expand Down Expand Up @@ -68,5 +74,14 @@ static public void main(String[] args)
algorithm.run(scenario.getPopulation());
new PopulationWriter(scenario.getPopulation()).write(cmd.getOptionStrict("output-population-path"));
}

// Load schedule
if (cmd.hasOption("input-schedule-path")) {
File populationPath = new File(cmd.getOptionStrict("input-schedule-path"));
new TransitScheduleReader(scenario).readFile(populationPath.toString());
algorithm.run(scenario.getTransitSchedule());
new TransitScheduleWriter(scenario.getTransitSchedule())
.writeFile(cmd.getOptionStrict("output-schedule-path"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.eqasim.core.components.config.EqasimConfigGroup;
import org.eqasim.core.components.raptor.EqasimRaptorConfigGroup;
import org.eqasim.core.components.raptor.EqasimRaptorModule;
import org.eqasim.core.components.traffic.EqasimTrafficModule;
import org.eqasim.core.components.traffic.EqasimTrafficQSimModule;
import org.eqasim.core.components.transit.EqasimTransitModule;
import org.eqasim.core.components.transit.EqasimTransitQSimModule;
Expand Down Expand Up @@ -72,6 +73,7 @@ public EqasimConfigurator() {
registerModule(new EpsilonModule());
registerModule(new EqasimRaptorModule());
registerModule(new EqasimModeChoiceModule());
registerModule(new EqasimTrafficModule());

registerQSimModule(new EqasimTransitQSimModule());
registerQSimModule(new EqasimTrafficQSimModule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
Config config = ConfigUtils.loadConfig(commandLine.getOptionStrict("input-config-path"), new EqasimConfigGroup(), new DiscreteModeChoiceConfigGroup());
commandLine.applyConfiguration(config);

DiscreteModeChoiceConfigGroup discreteModeChoiceConfigGroup = (DiscreteModeChoiceConfigGroup) config.getModules().get(DiscreteModeChoiceConfigGroup.GROUP_NAME);
run(config);

ConfigUtils.writeConfig(config, commandLine.getOptionStrict("output-config-path"));
}

static public void run(Config config) {
DiscreteModeChoiceConfigGroup discreteModeChoiceConfigGroup = (DiscreteModeChoiceConfigGroup) config.getModules().get(DiscreteModeChoiceConfigGroup.GROUP_NAME);
discreteModeChoiceConfigGroup.setSelector(SelectorModule.MAXIMUM);

EqasimConfigGroup eqasimConfigGroup = (EqasimConfigGroup) config.getModules().get(EqasimConfigGroup.GROUP_NAME);
Expand All @@ -29,7 +35,5 @@ public static void main(String[] args) throws CommandLine.ConfigurationException
}
eqasimConfigGroup.setEstimator(entry.getKey(), EpsilonModule.EPSILON_UTILITY_PREFIX + entry.getValue());
}

ConfigUtils.writeConfig(config, commandLine.getOptionStrict("output-config-path"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Optional;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.eqasim.core.components.traffic.CrossingPenalty;
import org.eqasim.core.scenario.cutter.extent.ScenarioExtent;
import org.eqasim.core.scenario.cutter.extent.ShapeScenarioExtent;
import org.eqasim.core.simulation.mode_choice.AbstractEqasimExtension;
Expand Down Expand Up @@ -70,13 +71,15 @@ public VDFScope provideVDFScope(VDFConfigGroup config) {
@Provides
@Singleton
public VDFTravelTime provideVDFTravelTime(VDFConfigGroup config, VDFScope scope, Network network,
VolumeDelayFunction vdf, QSimConfigGroup qsimConfig, EqasimConfigGroup eqasimConfig) throws IOException {
VolumeDelayFunction vdf, QSimConfigGroup qsimConfig, EqasimConfigGroup eqasimConfig,
CrossingPenalty crossingPenalty) throws IOException {
ScenarioExtent updateExtent = config.getUpdateAreaShapefile() == null ? null
: new ShapeScenarioExtent.Builder(new File(ConfigGroup
.getInputFileURL(getConfig().getContext(), config.getUpdateAreaShapefile()).getPath()),
Optional.empty(), Optional.empty()).build();

return new VDFTravelTime(scope, config.getMinimumSpeed(), config.getCapacityFactor(),
eqasimConfig.getSampleSize(), network, vdf, eqasimConfig.getCrossingPenalty(), updateExtent);
eqasimConfig.getSampleSize(), network, vdf, crossingPenalty, updateExtent);
}

@Provides
Expand Down
Loading
Loading