Skip to content

Commit

Permalink
* repair wrong positioning of vehicles if linkSpeedCalculator returns…
Browse files Browse the repository at this point in the history
… speed larger than free speed

* replace some (but not all) link.getAttributes()... by BicycleUtils.set/getXyz( link, ...)
* bind BicycleConfigGroup explicitly in BicycleModule so that not materializing it before does not lead to a non-interpretable error message (stating that Scenario is not bound about 20 times although that is not the root of the problem)
* possibly one or the other additional things
  • Loading branch information
kainagel committed Jun 27, 2024
1 parent e3552ad commit 38b88e3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
Therefore we need to use a fixed value here and then refer to the matsim version with ${project.parent.version} -->
<!-- Options: stable build based on weekly (e.g. 15.0-PR2344), PR-based (e.g. 15.0-2023w01) or official (e.g. 14.0) releases -->
<!-- <version>16.0-2024w02</version>-->
<version>2025.0-2024w21</version>
<!--<version>15.0-SNAPSHOT</version>-->
<!-- <version>16.0-SNAPSHOT</version>-->
<!-- <version>2025.0-2024w21</version>-->
<version>2025.0-SNAPSHOT</version>
<relativePath/>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,26 @@
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.population.Leg;
import org.matsim.api.core.v01.population.Plan;
import org.matsim.contrib.bicycle.BicycleConfigGroup;
import org.matsim.contrib.bicycle.BicycleModule;
import org.matsim.contrib.bicycle.BicycleUtils;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.ReplanningConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.router.TripStructureUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vehicles.VehiclesFactory;
import org.matsim.vis.otfvis.OTFVisConfigGroup;

import java.net.URL;
import java.util.*;

import static org.matsim.core.config.groups.QSimConfigGroup.*;

public final class RunBicycleContribExample{
private static final Logger LOG = LogManager.getLogger( RunBicycleContribExample.class );

Expand All @@ -46,8 +40,9 @@ public static void main(String[] args) {

config = ConfigUtils.createConfig( ExamplesUtils.getTestScenarioURL( "bicycle_example" ) );

config.qsim().setLinkDynamics( QSimConfigGroup.LinkDynamics.PassingQ );
config.qsim().setTrafficDynamics( QSimConfigGroup.TrafficDynamics.kinematicWaves );
config.qsim().setLinkDynamics( LinkDynamics.PassingQ );
config.qsim().setTrafficDynamics( TrafficDynamics.kinematicWaves );
config.qsim().setSnapshotStyle( SnapshotStyle.kinematicWaves );

config.network().setInputFile("network_normal.xml"); // change this to any of the others that are provided
config.plans().setInputFile("population_3.xml");
Expand All @@ -58,17 +53,17 @@ public static void main(String[] args) {
config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("home").setTypicalDuration(12*60*60 ) );
config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("work").setTypicalDuration(8*60*60 ) );

config.scoring().addModeParams( new ScoringConfigGroup.ModeParams(
BICYCLE_MODE ).setConstant(0. ).setMarginalUtilityOfDistance(-0.0004 ).setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) );
config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( BICYCLE_MODE ).setConstant(0.).setMarginalUtilityOfDistance(-0.0004 )
.setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) );

config.global().setNumberOfThreads(1 );
config.controller().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists );

config.controller().setLastIteration(0);
}

BicycleConfigGroup bicycleConfig = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class );
bicycleConfig.setBicycleMode( BICYCLE_MODE );
// BicycleConfigGroup bicycleConfig = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class );
// bicycleConfig.setBicycleMode( BICYCLE_MODE );
// bicycleConfig.setMarginalUtilityOfInfrastructure_m(-0.0002);
// bicycleConfig.setMarginalUtilityOfComfort_m(-0.0002);
// bicycleConfig.setMarginalUtilityOfGradient_m_100m(-0.02);
Expand All @@ -85,15 +80,16 @@ public static void main(String[] args) {
Scenario scenario = ScenarioUtils.loadScenario( config );

// set config such that the mode vehicles come from vehicles data:
scenario.getConfig().qsim().setVehiclesSource( QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData );
scenario.getConfig().qsim().setVehiclesSource( VehiclesSource.modeVehicleTypesFromVehiclesData );

// now put the mode vehicles into the vehicles data:
final VehiclesFactory vf = VehicleUtils.getFactory();
scenario.getVehicles().addVehicleType( vf.createVehicleType( Id.create(TransportMode.car, VehicleType.class ) ).setNetworkMode( TransportMode.car ) );
scenario.getVehicles().addVehicleType( vf.createVehicleType(Id.create( BICYCLE_MODE, VehicleType.class ) ).setNetworkMode( BICYCLE_MODE ).setMaximumVelocity(4.16666666 ).setPcuEquivalents(0.25 ) );

// // create a bicycle expressway
// scenario.getNetwork().getLinks().get( Id.createLinkId( 2 ) ).getAttributes().putAttribute( BicycleUtils.BICYCLE_INFRASTRUCTURE_SPEED_FACTOR, 10. );
BicycleUtils.setBicycleInfrastructureFactor( scenario.getNetwork().getLinks().get( Id.createLinkId( 2 ) ), 5. );
BicycleUtils.setSmoothness( scenario.getNetwork().getLinks().get( Id.createLinkId( 3 ) ), "sand" );

// // allow cars on all links ... and switch one person to car:
// for( Link link : scenario.getNetwork().getLinks().values() ){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ public static void runSingle(File populationPath, File networkPath, File outputP
drtConfig.mode = "drt";
drtConfig.operationalScheme = OperationalScheme.door2door;
drtConfig.stopDuration = 60.0;
DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam();
constraintsParam.maxWaitTime = settings.maxWaitTime;
constraintsParam.maxTravelTimeAlpha = settings.maxTravelTimeAlpha;
constraintsParam.maxTravelTimeBeta = settings.maxWaitTime;
// DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam();
// constraintsParam.maxWaitTime = settings.maxWaitTime;
// constraintsParam.maxTravelTimeAlpha = settings.maxTravelTimeAlpha;
// constraintsParam.maxTravelTimeBeta = settings.maxWaitTime;

DrtInsertionSearchParams insertionSearchParams = new ExtensiveInsertionSearchParams();
drtConfig.addDrtInsertionSearchParams(insertionSearchParams);
Expand Down Expand Up @@ -299,4 +299,4 @@ static public void main(String[] args) throws ConfigurationException {

runAll(populationPath, networkPath, outputPath);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.contrib.drt.optimizer.DrtOptimizationConstraintsParams;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.routing.DrtRoute;
import org.matsim.contrib.drt.routing.DrtRouteFactory;
Expand Down Expand Up @@ -71,10 +72,10 @@ public static void run(boolean otfvis, String... args ){
DrtConfigGroup drtConfig = new DrtConfigGroup();
drtConfig.mode = DRT_A;
drtConfig.stopDuration = 60.;
drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900;
drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3;
drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.;
drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
// drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900;
// drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3;
// drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.;
// drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
drtConfig.vehiclesFile="one_shared_taxi_vehicles_A.xml";
drtConfig.changeStartLinkToLastLinkInSchedule=true;
drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() );
Expand All @@ -84,10 +85,10 @@ public static void run(boolean otfvis, String... args ){
DrtConfigGroup drtConfig = new DrtConfigGroup();
drtConfig.mode = DRT_B;
drtConfig.stopDuration = 60.;
drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900;
drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3;
drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.;
drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
// drtConfig.getDrtOptimizationConstraintsParam().maxWaitTime=900;
// drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeAlpha = 1.3;
// drtConfig.getDrtOptimizationConstraintsParam().maxTravelTimeBeta=10. * 60.;
// drtConfig.getDrtOptimizationConstraintsParam().rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
drtConfig.vehiclesFile="one_shared_taxi_vehicles_B.xml";
drtConfig.changeStartLinkToLastLinkInSchedule=true;
drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() );
Expand All @@ -97,11 +98,11 @@ public static void run(boolean otfvis, String... args ){
DrtConfigGroup drtConfig = new DrtConfigGroup();
drtConfig.mode = DRT_C;
drtConfig.stopDuration = 60.;
DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam();
constraintsParam.maxWaitTime=900;
constraintsParam.maxTravelTimeAlpha = 1.3;
constraintsParam.maxTravelTimeBeta=10. * 60.;
constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
// DrtOptimizationConstraintsParams constraintsParam = drtConfig.getDrtOptimizationConstraintsParam();
// constraintsParam.maxWaitTime=900;
// constraintsParam.maxTravelTimeAlpha = 1.3;
// constraintsParam.maxTravelTimeBeta=10. * 60.;
// constraintsParam.rejectRequestIfMaxWaitOrTravelTimeViolated= false ;
drtConfig.vehiclesFile="one_shared_taxi_vehicles_C.xml";
drtConfig.changeStartLinkToLastLinkInSchedule=true;
drtConfig.addParameterSet( new ExtensiveInsertionSearchParams() );
Expand Down

0 comments on commit 38b88e3

Please sign in to comment.