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

Bicycle contrib #1149

Open
wants to merge 2 commits into
base: dev.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -7,82 +7,108 @@
import org.matsim.api.core.v01.TransportMode;
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.scenario.ScenarioUtils;
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.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;

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

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

private static final String BICYCLE_MODE = "bicycle";

public static void main(String[] args) {
Config config;
if (args.length >= 1) {
LOG.info("A user-specified config.xml file was provided. Using it...");
config = ConfigUtils.loadConfig(args, new BicycleConfigGroup() );
} else {
LOG.info("No config.xml file was provided. Using 'standard' example files given in this contrib's resources folder.");
// Setting the context like this works when the data is stored under "/matsim/contribs/bicycle/src/main/resources/bicycle_example"
config = ConfigUtils.createConfig("bicycle_example/");
config.addModule(new BicycleConfigGroup());
config.network().setInputFile("network_lane.xml"); // Modify this
config.plans().setInputFile("population_1200.xml");
LOG.info("No config.xml file was provided. Using bicycle_example from ExamplesUtils.");

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

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

config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ChangeExpBeta" ).setWeight(0.8 ) );
config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ReRoute" ).setWeight(0.2 ) );
config.network().setInputFile("network_normal.xml"); // change this to any of the others that are provided
config.plans().setInputFile("population_3.xml");

// config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ChangeExpBeta" ).setWeight(0.8 ) );
// config.replanning().addStrategySettings( new ReplanningConfigGroup.StrategySettings().setStrategyName("ReRoute" ).setWeight(0.2 ) );

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").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(100); // Modify if motorized interaction is used
config.controller().setLastIteration(0);
}

BicycleConfigGroup bicycleConfigGroup = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class );
bicycleConfigGroup.setBicycleMode( "bicycle" );
bicycleConfigGroup.setMarginalUtilityOfInfrastructure_m(-0.0002);
bicycleConfigGroup.setMarginalUtilityOfComfort_m(-0.0002);
bicycleConfigGroup.setMarginalUtilityOfGradient_m_100m(-0.02);
bicycleConfigGroup.setMaxBicycleSpeedForRouting(4.16666666);
// 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);
// bicycleConfig.setMaxBicycleSpeedForRouting(4.16666666);

List<String> mainModeList = Arrays.asList( "bicycle", TransportMode.car);
Set<String> mainModeSet = new LinkedHashSet<>( Arrays.asList( BICYCLE_MODE, TransportMode.car ) );

config.qsim().setMainModes(mainModeList );
config.qsim().setMainModes(mainModeSet );

config.routing().setNetworkModes(mainModeList );
config.routing().setNetworkModes(mainModeSet );

// ===

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 hte mode vehicles into the vehicles data:
// 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", VehicleType.class ) ).setNetworkMode( "bicycle" ).setMaximumVelocity(4.16666666 ).setPcuEquivalents(0.25 ) );
scenario.getVehicles().addVehicleType( vf.createVehicleType(Id.create( BICYCLE_MODE, VehicleType.class ) ).setNetworkMode( BICYCLE_MODE ).setMaximumVelocity(4.16666666 ).setPcuEquivalents(0.25 ) );

// // create a bicycle expressway
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() ){
// link.setAllowedModes( mainModeSet );
// }
// Plan plan = scenario.getPopulation().getPersons().get( Id.createPersonId( 1 ) ).getSelectedPlan();
// for( Leg leg : TripStructureUtils.getLegs( plan ) ){
// leg.setMode( TransportMode.car );
// }

// ===

Controler controler = new Controler(scenario);
controler.addOverridingModule(new BicycleModule() );

controler.addOverridingModule( new OTFVisLiveModule() );
OTFVisConfigGroup otfConfig = ConfigUtils.addOrGetModule( config, OTFVisConfigGroup.class );
otfConfig.setAgentSize( otfConfig.getAgentSize()*2 );

controler.run();
}

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
Loading