Skip to content

Commit

Permalink
Merge branch 'master' into emissions-viz
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Jan 17, 2024
2 parents 9cd30b8 + 0a402d9 commit 205ef4d
Show file tree
Hide file tree
Showing 46 changed files with 725 additions and 373 deletions.
10 changes: 9 additions & 1 deletion contribs/decongestion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
<artifactId>contrib</artifactId>
<version>16.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>otfvis</artifactId>
<version>${parent.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<modelVersion>4.0.0</modelVersion>
<groupId>org.matsim.contrib</groupId>
<artifactId>decongestion</artifactId>
<name>decongestion</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

package org.matsim.contrib.decongestion;

import org.matsim.api.core.v01.Scenario;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.contrib.decongestion.data.DecongestionInfo;
import org.matsim.contrib.decongestion.handler.DelayAnalysis;
import org.matsim.contrib.decongestion.handler.IntervalBasedTolling;
import org.matsim.contrib.decongestion.handler.IntervalBasedTollingAll;
import org.matsim.contrib.decongestion.handler.PersonVehicleTracker;
import org.matsim.contrib.decongestion.routing.TollTimeDistanceTravelDisutilityFactory;
import org.matsim.contrib.decongestion.tollSetting.DecongestionTollSetting;
import org.matsim.contrib.decongestion.tollSetting.DecongestionTollingBangBang;
import org.matsim.contrib.decongestion.tollSetting.DecongestionTollingPID;
Expand All @@ -37,51 +40,46 @@

public class DecongestionModule extends AbstractModule {

private final DecongestionConfigGroup decongestionConfigGroup;

public DecongestionModule(Scenario scenario) {
this.decongestionConfigGroup = (DecongestionConfigGroup) scenario.getConfig().getModules().get(DecongestionConfigGroup.GROUP_NAME);
}
@Inject private DecongestionConfigGroup decongestionConfigGroup;

@Override
public void install() {

if (decongestionConfigGroup.isEnableDecongestionPricing()) {
switch( decongestionConfigGroup.getDecongestionApproach() ) {
case BangBang:
this.bind(DecongestionTollingBangBang.class).asEagerSingleton();
this.bind(DecongestionTollSetting.class).to(DecongestionTollingBangBang.class);
break;
case PID:
this.bind(DecongestionTollingPID.class).asEagerSingleton();
this.bind(DecongestionTollSetting.class).to(DecongestionTollingPID.class);
this.addEventHandlerBinding().to(DecongestionTollingPID.class);
break;
case P_MC:
this.bind(DecongestionTollingP_MCP.class).asEagerSingleton();
this.bind(DecongestionTollSetting.class).to(DecongestionTollingP_MCP.class);
this.addEventHandlerBinding().to(DecongestionTollingP_MCP.class);
break;
default:
throw new RuntimeException("not implemented") ;
switch( decongestionConfigGroup.getDecongestionApproach() ){
case BangBang -> {
this.bind( DecongestionTollingBangBang.class ).in( Singleton.class );
this.bind( DecongestionTollSetting.class ).to( DecongestionTollingBangBang.class );
}
case PID -> {
this.bind( DecongestionTollingPID.class ).in( Singleton.class );
this.bind( DecongestionTollSetting.class ).to( DecongestionTollingPID.class );
this.addEventHandlerBinding().to( DecongestionTollingPID.class );
}
case P_MC -> {
this.bind( DecongestionTollingP_MCP.class ).in( Singleton.class );
this.bind( DecongestionTollSetting.class ).to( DecongestionTollingP_MCP.class );
this.addEventHandlerBinding().to( DecongestionTollingP_MCP.class );
}
default -> throw new RuntimeException( "not implemented" );
}

} else {
// no pricing

}
this.bind(DecongestionInfo.class).asEagerSingleton();
addTravelDisutilityFactoryBinding( TransportMode.car ).to( TollTimeDistanceTravelDisutilityFactory.class );

this.bind(DecongestionInfo.class).in( Singleton.class );

this.bind(IntervalBasedTollingAll.class).asEagerSingleton();
this.bind(IntervalBasedTolling.class).to(IntervalBasedTollingAll.class);
this.addEventHandlerBinding().to(IntervalBasedTollingAll.class);
this.bind(IntervalBasedTolling.class).to(IntervalBasedTollingAll.class).in( Singleton.class );
this.addEventHandlerBinding().to(IntervalBasedTolling.class);

this.bind(DelayAnalysis.class).asEagerSingleton();
this.addEventHandlerBinding().to(DelayAnalysis.class);
this.addEventHandlerBinding().to(DelayAnalysis.class).in( Singleton.class );

this.addEventHandlerBinding().to(PersonVehicleTracker.class).asEagerSingleton();
this.addEventHandlerBinding().to(PersonVehicleTracker.class).in( Singleton.class );

this.addControlerListenerBinding().to(DecongestionControlerListener.class);
this.addControlerListenerBinding().to(DecongestionControlerListener.class).in( Singleton.class );
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*
* @author ikaddoura
*/
public final class TollTimeDistanceTravelDisutility implements TravelDisutility {
final class TollTimeDistanceTravelDisutility implements TravelDisutility {
private static final Logger log = LogManager.getLogger(TollTimeDistanceTravelDisutility.class);

private final TravelDisutility delegate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,24 @@
/**
*
*/
package org.matsim.contrib.decongestion;
package org.matsim.contrib.decongestion.run;


import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.contrib.decongestion.DecongestionConfigGroup;
import org.matsim.contrib.decongestion.DecongestionConfigGroup.DecongestionApproach;
import org.matsim.contrib.decongestion.DecongestionConfigGroup.IntegralApproach;
import org.matsim.contrib.decongestion.DecongestionModule;
import org.matsim.contrib.decongestion.routing.TollTimeDistanceTravelDisutilityFactory;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.scenario.ScenarioUtils;

/**
Expand Down Expand Up @@ -70,7 +72,10 @@ public static void main(String[] args) throws IOException {

private void run() {

final DecongestionConfigGroup decongestionSettings = new DecongestionConfigGroup();
Config config = ConfigUtils.loadConfig(configFile);

final DecongestionConfigGroup decongestionSettings = ConfigUtils.addOrGetModule( config, DecongestionConfigGroup.class );

decongestionSettings.setToleratedAverageDelaySec(30.);
decongestionSettings.setFractionOfIterationsToEndPriceAdjustment(1.0);
decongestionSettings.setFractionOfIterationsToStartPriceAdjustment(0.0);
Expand All @@ -92,32 +97,29 @@ private void run() {
// decongestionSettings.setTOLL_ADJUSTMENT(1.0);
// decongestionSettings.setINITIAL_TOLL(1.0);

Config config = ConfigUtils.loadConfig(configFile);
config.addModule(decongestionSettings);

// ---

final Scenario scenario = ScenarioUtils.loadScenario(config);
Controler controler = new Controler(scenario);

// #############################################################
// ---

// congestion toll computation
Controler controler = new Controler(scenario);

controler.addOverridingModule(new DecongestionModule(scenario));
// congestion toll computation
controler.addOverridingModule(new DecongestionModule() );

// toll-adjusted routing

controler.addOverridingModule(new AbstractModule(){
@Override
public void install() {
final TollTimeDistanceTravelDisutilityFactory travelDisutilityFactory = new TollTimeDistanceTravelDisutilityFactory();
this.bindCarTravelDisutilityFactory().toInstance( travelDisutilityFactory );
addTravelDisutilityFactoryBinding( TransportMode.car ).toInstance( new TollTimeDistanceTravelDisutilityFactory() );
// yyyy try if this could add the class instead of the instance. possibly as singleton. kai, jan'24

}
});

// #############################################################

controler.getConfig().controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists);
controler.run();
controler.run();

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@
/**
*
*/
package org.matsim.contrib.decongestion;
package org.matsim.contrib.decongestion.run;


import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.contrib.decongestion.DecongestionConfigGroup;
import org.matsim.contrib.decongestion.DecongestionModule;
import org.matsim.contrib.decongestion.routing.TollTimeDistanceTravelDisutilityFactory;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.scenario.ScenarioUtils;

/**
Expand Down Expand Up @@ -64,34 +66,27 @@ public static void main(String[] args) throws IOException {
main.run();
}

private void run() throws IOException {
private void run() {

Config config = ConfigUtils.loadConfig(configFile, new DecongestionConfigGroup());
Config config = ConfigUtils.loadConfig(configFile, new DecongestionConfigGroup() );

final Scenario scenario = ScenarioUtils.loadScenario(config);
Controler controler = new Controler(scenario);

// #############################################################
Controler controler = new Controler(scenario);

// congestion toll computation

controler.addOverridingModule(new DecongestionModule(scenario));
controler.addOverridingModule(new DecongestionModule() );

// toll-adjusted routing

final TollTimeDistanceTravelDisutilityFactory travelDisutilityFactory = new TollTimeDistanceTravelDisutilityFactory();

controler.addOverridingModule(new AbstractModule(){
controler.addOverridingModule(new AbstractModule(){
@Override
public void install() {
this.bindCarTravelDisutilityFactory().toInstance( travelDisutilityFactory );
addTravelDisutilityFactoryBinding( TransportMode.car ).toInstance( new TollTimeDistanceTravelDisutilityFactory() );
// yyyy try if this could add the class instead of the instance. possibly as singleton. kai, jan'24
}
});

// #############################################################

controler.getConfig().controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.failIfDirectoryExists);
controler.run();
controler.run();
}
}

Loading

0 comments on commit 205ef4d

Please sign in to comment.