Skip to content

Commit

Permalink
Merge pull request #1138 from matsim-org/add-multiple-modes
Browse files Browse the repository at this point in the history
add-multiple-modes
  • Loading branch information
paulheinr authored Jun 27, 2024
2 parents a7fed54 + d04e35b commit 5de30b6
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
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.Person;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;

import java.net.URL;
import java.util.Arrays;
Expand Down Expand Up @@ -60,13 +65,27 @@ static Scenario prepareScenario( Config config ){
Set<String> modes = new LinkedHashSet<>( Arrays.asList( TransportMode.car, TransportMode.bike ));
link.setAllowedModes( modes );
}

// add vehicle types for both modes (they are only used, if the vehicles source is set correspondingly)
scenario.getVehicles().addVehicleType( VehicleUtils.getFactory().createVehicleType(Id.create("car", VehicleType.class)) );

VehicleType bike = VehicleUtils.getFactory().createVehicleType(Id.create("bike", VehicleType.class))
.setNetworkMode("bike")
.setMaximumVelocity(5.);

scenario.getVehicles().addVehicleType(bike);

return scenario;
}

static Config prepareConfig(){
final URL url = IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "equil" ), "config.xml" );
log.warn("url=" + url) ;
Config config = ConfigUtils.loadConfig( url );
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

// in case you want the different modes to use different vehicle types, you need to set this
config.qsim().setVehiclesSource(QSimConfigGroup.VehiclesSource.modeVehicleTypesFromVehiclesData);

{ // add strategy that switches between car and bike:
StrategySettings stratSets = new StrategySettings( ) ;
Expand Down

0 comments on commit 5de30b6

Please sign in to comment.