Skip to content

Commit

Permalink
build use case that tests the full infrastructure (existing tests als…
Browse files Browse the repository at this point in the history
…o passed when toll-sensitive router was removed)
  • Loading branch information
kainagel committed Jan 10, 2024
1 parent e239202 commit c97d77b
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 65 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 @@ -39,7 +39,6 @@
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 @@ -108,7 +107,7 @@ private void run() {
Controler controler = new Controler(scenario);

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

// toll-adjusted routing
controler.addOverridingModule(new AbstractModule(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
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 @@ -72,22 +71,18 @@ private void run() {
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

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

}
});

Expand Down
Loading

0 comments on commit c97d77b

Please sign in to comment.