Skip to content

Commit

Permalink
Merge pull request #1040 from matsim-org/update-to-recent-refactorings
Browse files Browse the repository at this point in the history
update code to work with 16.0-2023w43
  • Loading branch information
mrieser authored Oct 23, 2023
2 parents faac8c1 + 46be74a commit 0321d90
Show file tree
Hide file tree
Showing 77 changed files with 291 additions and 294 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- This is where we change the matsim version. Maven does not allow using properties in the parent declaration (like ${matsim.version}).
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-2023w41</version>
<version>16.0-2023w43</version>
<!--<version>16.0-2023w39</version>-->
<!--<version>15.0-SNAPSHOT</version>-->
<relativePath/>
Expand Down
10 changes: 5 additions & 5 deletions scenarios/equil-extended/config-with-subpopulation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

<!-- ====================================================================== -->

<module name="TimeAllocationMutator" >
<module name="timeAllocationMutator" >
<param name="mutationRange" value="1800.0" />
</module>

<!-- ====================================================================== -->

<module name="controler" >
<module name="controller" >
<param name="firstIteration" value="0" />
<param name="lastIteration" value="10" />
<param name="mobsim" value="qsim" />
Expand All @@ -37,8 +37,8 @@

<!-- ====================================================================== -->

<module name="planCalcScore" >
<param name="BrainExpBeta" value="2.0" />
<module name="scoring" >
<param name="brainExpBeta" value="2.0" />
<param name="learningRate" value="1.0" />

<parameterset type="scoringParameters" >
Expand Down Expand Up @@ -192,7 +192,7 @@

<!-- ====================================================================== -->

<module name="strategy" >
<module name="replanning" >
<param name="fractionOfIterationsToDisableInnovation" value="Infinity" />
<param name="maxAgentPlanMemorySize" value="5" />
<param name="planSelectorForRemoval" value="WorstPlanSelector" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RunWithCommandLineOptionsExample{
public static void main( String[] args ){
Config config = ConfigUtils.createConfig() ;

log.warn( config.controler().getOutputDirectory() ) ;
log.warn( config.controller().getOutputDirectory() ) ;

try{
CommandLine.Builder bld = new CommandLine.Builder( args ) ;
Expand All @@ -22,7 +22,7 @@ public static void main( String[] args ){
throw new RuntimeException( e ) ;
}

log.warn( config.controler().getOutputDirectory() ) ;
log.warn( config.controller().getOutputDirectory() ) ;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void main(String[] args) {

//path to events file. For this you first need to run a simulation.
Config config = ConfigUtils.loadConfig("scenarios/equil/config.xml");
config.controler().setLastIteration(5);
config.controller().setLastIteration(5);
Scenario scenario = ScenarioUtils.loadScenario(config);
Controler controler = new Controler(scenario);
controler.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void main(String[] args) {
config = ConfigUtils.loadConfig( args[0] ) ;
}

config.controler().setOutputDirectory(outputDirectory);
config.controller().setOutputDirectory(outputDirectory);

final Scenario scenario = ScenarioUtils.loadScenario(config) ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.matsim.contrib.bicycle.BicycleModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.StrategyConfigGroup;
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;
Expand Down Expand Up @@ -39,18 +39,18 @@ public static void main(String[] args) {
config.network().setInputFile("network_lane.xml"); // Modify this
config.plans().setInputFile("population_1200.xml");

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

config.planCalcScore().addActivityParams( new PlanCalcScoreConfigGroup.ActivityParams("home").setTypicalDuration(12*60*60 ) );
config.planCalcScore().addActivityParams( new PlanCalcScoreConfigGroup.ActivityParams("work").setTypicalDuration(8*60*60 ) );
config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("home").setTypicalDuration(12*60*60 ) );
config.scoring().addActivityParams( new ScoringConfigGroup.ActivityParams("work").setTypicalDuration(8*60*60 ) );

config.planCalcScore().addModeParams( new PlanCalcScoreConfigGroup.ModeParams("bicycle").setConstant(0. ).setMarginalUtilityOfDistance(-0.0004 ).setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) );
config.scoring().addModeParams( new ScoringConfigGroup.ModeParams("bicycle").setConstant(0. ).setMarginalUtilityOfDistance(-0.0004 ).setMarginalUtilityOfTraveling(-6.0 ).setMonetaryDistanceRate(0. ) );

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

config.controler().setLastIteration(100); // Modify if motorized interaction is used
config.controller().setLastIteration(100); // Modify if motorized interaction is used
}

BicycleConfigGroup bicycleConfigGroup = ConfigUtils.addOrGetModule( config, BicycleConfigGroup.class );
Expand All @@ -64,7 +64,7 @@ public static void main(String[] args) {

config.qsim().setMainModes(mainModeList );

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

// ===

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import org.matsim.contribs.discrete_mode_choice.modules.config.DiscreteModeChoiceConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.ScoringConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.collections.CollectionUtils;

import static org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings;
import static org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;

public final class RunDiscreteModeChoiceExample{
// The code below works with v14 since approx jun'21. kai
Expand All @@ -29,23 +29,23 @@ public static void main ( String [] args ) {

Config config = ConfigUtils.loadConfig( args );

config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists );
config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists );

config.controler().setLastIteration( 2 );
config.controller().setLastIteration( 2 );

String modeB = "modeB";
String modeC = "modeC";
final String[] modes = {TransportMode.car, modeB, modeC};

config.plansCalcRoute().addTeleportedModeParams( new PlansCalcRouteConfigGroup.TeleportedModeParams(modeB).setTeleportedModeSpeed(10. ) );
config.plansCalcRoute().addTeleportedModeParams( new PlansCalcRouteConfigGroup.TeleportedModeParams(modeC).setTeleportedModeSpeed(10. ) );
config.plansCalcRoute().addTeleportedModeParams( new PlansCalcRouteConfigGroup.TeleportedModeParams(TransportMode.walk).setTeleportedModeSpeed(4./3.6 ) );
config.routing().addTeleportedModeParams( new RoutingConfigGroup.TeleportedModeParams(modeB).setTeleportedModeSpeed(10. ) );
config.routing().addTeleportedModeParams( new RoutingConfigGroup.TeleportedModeParams(modeC).setTeleportedModeSpeed(10. ) );
config.routing().addTeleportedModeParams( new RoutingConfigGroup.TeleportedModeParams(TransportMode.walk).setTeleportedModeSpeed(4./3.6 ) );

config.planCalcScore().addModeParams( new PlanCalcScoreConfigGroup.ModeParams( modeB ).setConstant( 13. ) );
config.planCalcScore().addModeParams( new PlanCalcScoreConfigGroup.ModeParams( modeC ).setConstant( 12. ) );
config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( modeB ).setConstant( 13. ) );
config.scoring().addModeParams( new ScoringConfigGroup.ModeParams( modeC ).setConstant( 12. ) );

// the following is first inlined and then adapted from DiscreteModeChoiceConfigurator.configureAsSubtourModeChoiceReplacement( config );
config.strategy().addStrategySettings( new StrategySettings().setStrategyName( DiscreteModeChoiceModule.STRATEGY_NAME ).setWeight( 1. ) );
config.replanning().addStrategySettings( new StrategySettings().setStrategyName( DiscreteModeChoiceModule.STRATEGY_NAME ).setWeight( 1. ) );
{
DiscreteModeChoiceConfigGroup dmcConfig = ConfigUtils.addOrGetModule( config, DiscreteModeChoiceConfigGroup.class );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams;
import org.matsim.core.config.groups.ScoringConfigGroup.ModeParams;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup.SnapshotStyle;
import org.matsim.core.config.groups.StrategyConfigGroup.StrategySettings;
import org.matsim.core.config.groups.ReplanningConfigGroup.StrategySettings;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule.DefaultSelector;
Expand Down Expand Up @@ -53,10 +53,10 @@ public static void run(boolean otfvis, String... args ){
config = ConfigUtils.loadConfig( args );
} else {
config = ConfigUtils.loadConfig( IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "dvrp-grid" ), "multi_mode_one_shared_taxi_config.xml" ) );
config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists );
config.controller().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists );
}

config.controler().setLastIteration( 1 );
config.controller().setLastIteration( 1 );

config.qsim().setSimStarttimeInterpretation( QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime );
config.qsim().setInsertingWaitingVehiclesBeforeDrivingVehicles(true);
Expand Down Expand Up @@ -108,24 +108,24 @@ public static void run(boolean otfvis, String... args ){
}

for (DrtConfigGroup drtCfg : multiModeDrtCfg.getModalElements()) {
DrtConfigs.adjustDrtConfig(drtCfg, config.planCalcScore(), config.plansCalcRoute());
DrtConfigs.adjustDrtConfig(drtCfg, config.scoring(), config.routing());
}
{
// clear strategy settings from config file:
config.strategy().clearStrategySettings();
config.replanning().clearStrategySettings();

// configure mode innovation so that travellers start using drt:
config.strategy().addStrategySettings( new StrategySettings().setStrategyName( DefaultStrategy.ChangeSingleTripMode ).setWeight( 0.1 ) );
config.replanning().addStrategySettings( new StrategySettings().setStrategyName( DefaultStrategy.ChangeSingleTripMode ).setWeight( 0.1 ) );
config.changeMode().setModes( new String[]{TransportMode.car, DRT_A, DRT_B, DRT_C} );

// have a "normal" plans choice strategy:
config.strategy().addStrategySettings( new StrategySettings().setStrategyName( DefaultSelector.ChangeExpBeta ).setWeight( 1. ) );
config.replanning().addStrategySettings( new StrategySettings().setStrategyName( DefaultSelector.ChangeExpBeta ).setWeight( 1. ) );
}
{
// add params so that scoring works:
config.planCalcScore().addModeParams( new ModeParams( DRT_A ) );
config.planCalcScore().addModeParams( new ModeParams( DRT_B ) );
config.planCalcScore().addModeParams( new ModeParams( DRT_C ) );
config.scoring().addModeParams( new ModeParams( DRT_A ) );
config.scoring().addModeParams( new ModeParams( DRT_B ) );
config.scoring().addModeParams( new ModeParams( DRT_C ) );
}
Scenario scenario = ScenarioUtils.createScenario( config ) ;
scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory( DrtRoute.class, new DrtRouteFactory() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void main (String[] args){
} else {
config = ConfigUtils.loadConfig( args );
}
config.plansCalcRoute().clearTeleportedModeParams();
config.routing().clearTeleportedModeParams();

EmissionsConfigGroup emissionsConfig = ConfigUtils.addOrGetModule( config, EmissionsConfigGroup.class );
{
Expand Down Expand Up @@ -129,7 +129,7 @@ public void install(){
// ---

// add events writer into emissions event handler
final EventWriterXML eventWriterXML = new EventWriterXML( config.controler().getOutputDirectory() + '/' + emissionEventOutputFileName );
final EventWriterXML eventWriterXML = new EventWriterXML( config.controller().getOutputDirectory() + '/' + emissionEventOutputFileName );
eventsManager.addHandler( eventWriterXML );

// read events file into the events reader. EmissionsModule and events writer have been added as handlers, and will act accordingly.
Expand All @@ -139,10 +139,10 @@ public void install(){
eventWriterXML.closeFile();

// also write vehicles and network and config as a service so we have all out files in one directory:
new MatsimVehicleWriter( scenario.getVehicles() ).writeFile( config.controler().getOutputDirectory() + "/output_vehicles.xml.gz" );
NetworkUtils.writeNetwork( scenario.getNetwork(), config.controler().getOutputDirectory() + "/output_network.xml.gz" );
ConfigUtils.writeConfig( config, config.controler().getOutputDirectory() + "/output_config.xml" );
ConfigUtils.writeMinimalConfig( config, config.controler().getOutputDirectory() + "/output_config_reduced.xml" );
new MatsimVehicleWriter( scenario.getVehicles() ).writeFile( config.controller().getOutputDirectory() + "/output_vehicles.xml.gz" );
NetworkUtils.writeNetwork( scenario.getNetwork(), config.controller().getOutputDirectory() + "/output_network.xml.gz" );
ConfigUtils.writeConfig( config, config.controller().getOutputDirectory() + "/output_config.xml" );
ConfigUtils.writeMinimalConfig( config, config.controller().getOutputDirectory() + "/output_config_reduced.xml" );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.matsim.codeexamples.extensions.freight;

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.freight.FreightConfigGroup;
import org.matsim.contrib.freight.carrier.CarrierPlanWriter;
import org.matsim.contrib.freight.controler.CarrierModule;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.freight.carriers.FreightCarriersConfigGroup;
import org.matsim.freight.carriers.CarrierPlanWriter;
import org.matsim.freight.carriers.controler.CarrierModule;
import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
Expand All @@ -35,7 +35,7 @@


/**
* @see org.matsim.contrib.freight
* @see org.matsim.freight.carriers
*/
public class RunFreightExample {

Expand All @@ -49,34 +49,34 @@ public static void run( String[] args, boolean runWithOTFVis ) throws ExecutionE
if ( args==null || args.length==0 || args[0]==null ){
config = ConfigUtils.loadConfig( IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "freight-chessboard-9x9" ), "config.xml" ) );
config.plans().setInputFile( null ); // remove passenger input
config.controler().setOutputDirectory( "./output/freight" );
config.controler().setLastIteration( 0 ); // no iterations; for iterations see RunFreightWithIterationsExample. kai, jan'23
config.controller().setOutputDirectory( "./output/freight" );
config.controller().setLastIteration( 0 ); // no iterations; for iterations see RunFreightWithIterationsExample. kai, jan'23

FreightConfigGroup freightConfigGroup = ConfigUtils.addOrGetModule( config, FreightConfigGroup.class );
FreightCarriersConfigGroup freightConfigGroup = ConfigUtils.addOrGetModule( config, FreightCarriersConfigGroup.class );
freightConfigGroup.setCarriersFile( "singleCarrierFiveActivitiesWithoutRoutes.xml" );
freightConfigGroup.setCarriersVehicleTypesFile( "vehicleTypes.xml" );
} else {
config = ConfigUtils.loadConfig( args, new FreightConfigGroup() );
config = ConfigUtils.loadConfig( args, new FreightCarriersConfigGroup() );
}

// load scenario (this is not loading the freight material):
Scenario scenario = ScenarioUtils.loadScenario( config );

//load carriers according to freight config
FreightUtils.loadCarriersAccordingToFreightConfig( scenario );
CarriersUtils.loadCarriersAccordingToFreightConfig( scenario );

// how to set the capacity of the "light" vehicle type to "1":
// FreightUtils.getCarrierVehicleTypes( scenario ).getVehicleTypes().get( Id.create("light", VehicleType.class ) ).getCapacity().setOther( 1 );
// CarriersUtils.getCarrierVehicleTypes( scenario ).getVehicleTypes().get( Id.create("light", VehicleType.class ) ).getCapacity().setOther( 1 );

// output before jsprit run (not necessary)
new CarrierPlanWriter(FreightUtils.getCarriers( scenario )).write( "output/jsprit_unplannedCarriers.xml" ) ;
new CarrierPlanWriter(CarriersUtils.getCarriers( scenario )).write( "output/jsprit_unplannedCarriers.xml" ) ;
// (this will go into the standard "output" directory. note that this may be removed if this is also used as the configured output dir.)

// Solving the VRP (generate carrier's tour plans)
FreightUtils.runJsprit( scenario );
CarriersUtils.runJsprit( scenario );

// Output after jsprit run (not necessary)
new CarrierPlanWriter(FreightUtils.getCarriers( scenario )).write( "output/jsprit_plannedCarriers.xml" ) ;
new CarrierPlanWriter(CarriersUtils.getCarriers( scenario )).write( "output/jsprit_plannedCarriers.xml" ) ;
// (this will go into the standard "output" directory. note that this may be removed if this is also used as the configured output dir.)

// ## MATSim configuration: ##
Expand Down
Loading

0 comments on commit 0321d90

Please sign in to comment.