Skip to content

Commit

Permalink
Merge pull request #1065 from matsim-org/decongestion
Browse files Browse the repository at this point in the history
Decongestion
  • Loading branch information
kainagel authored Jan 10, 2024
2 parents fabe40c + 220449f commit acb7135
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
<!-- 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-2024w02</version>
<!--<version>16.0-2023w39</version>-->
<!-- <version>16.0-2024w02</version>-->
<version>16.0-PR3045</version>
<!--<version>15.0-SNAPSHOT</version>-->
<!-- <version>16.0-SNAPSHOT</version>-->
<relativePath/>
</parent>

Expand Down Expand Up @@ -157,6 +158,11 @@
<artifactId>application</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>decongestion</artifactId>
<version>${project.parent.version}</version>
</dependency>

<!-- Include the JUnit testing library -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* There is a test case that shows how this contrib can be used. But not (yet) material here. So please have a look at the test case.
*/
package org.matsim.codeexamples.extensions.decongestion;
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2013 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */

/**
*
*/
package org.matsim.codeexamples.extensions.decongestion;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Population;
import org.matsim.contrib.decongestion.DecongestionConfigGroup;
import org.matsim.contrib.decongestion.DecongestionModule;
import org.matsim.contrib.decongestion.data.DecongestionInfo;
import org.matsim.contrib.decongestion.data.LinkInfo;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;
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.testcases.MatsimTestUtils;

import java.net.URL;

/**
*
*
* @author ikaddoura
*
*/
public class DecongestionPricingTestIT{

@RegisterExtension
private MatsimTestUtils testUtils = new MatsimTestUtils();


@Test
final void testDecongestion() {

URL configUrl = IOUtils.extendUrl( ExamplesUtils.getTestScenarioURL( "equil" ), "config.xml" );

Config config = ConfigUtils.loadConfig( configUrl );
config.controller().setOutputDirectory( testUtils.getOutputDirectory() );

config.plans().setInputFile( "plans2000.xml.gz" );
// (in my first attempts, the default plans file had too few agents. after my later changes, it may no longer be necessary to use this file here. kai, jan'23)

config.controller().setLastIteration( 20 );
// (need some iterations for the decongestion to unfold. 20 may be more than really needed. kai, jan'23)

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

decongestionSettings.setWriteOutputIteration(1);
// decongestionSettings.setKp(0.0123);
decongestionSettings.setKp(0.123);
decongestionSettings.setKd(0.0);
decongestionSettings.setKi(0.0);
decongestionSettings.setMsa(false);
decongestionSettings.setTollBlendFactor(1.0);
decongestionSettings.setFractionOfIterationsToEndPriceAdjustment(1.0);
decongestionSettings.setFractionOfIterationsToStartPriceAdjustment(0.0);

// ===

final Scenario scenario = ScenarioUtils.loadScenario(config);

Network network = scenario.getNetwork();

// make middle link faster
network.getLinks().get( Id.createLinkId( "6" )).setFreespeed( 100. );

// make alternative wider
network.getLinks().get( Id.createLinkId( "14" ) ).setCapacity( 100000. );

// increase some other capacities:
network.getLinks().get( Id.createLinkId( "5" ) ).setCapacity( 100000. );
network.getLinks().get( Id.createLinkId( "6" ) ).setCapacity( 100000. );

// remove all other alternatives:
network.removeLink( Id.createLinkId( "11" ) );
network.removeLink( Id.createLinkId( "12" ) );
network.removeLink( Id.createLinkId( "13" ) );
network.removeLink( Id.createLinkId( "16" ) );
network.removeLink( Id.createLinkId( "17" ) );
network.removeLink( Id.createLinkId( "18" ) );
network.removeLink( Id.createLinkId( "19" ) );

network.removeLink( Id.createLinkId( "2" ) );
network.removeLink( Id.createLinkId( "3" ) );
network.removeLink( Id.createLinkId( "4" ) );
network.removeLink( Id.createLinkId( "7" ) );
network.removeLink( Id.createLinkId( "8" ) );
network.removeLink( Id.createLinkId( "9" ) );
network.removeLink( Id.createLinkId( "10" ) );

// ---

Population population = scenario.getPopulation();

// remove 3/4 of the population to reduce computation time:
for ( int ii=500; ii<2000; ii++ ){
population.removePerson( Id.createPersonId( ii ) );
}


// ---

Controler controler = new Controler(scenario);

controler.addOverridingModule(new DecongestionModule() );

// controler.addOverridingModule( new OTFVisLiveModule() );

controler.run();

// ===

DecongestionInfo info = controler.getInjector().getInstance( DecongestionInfo.class );

final LinkInfo linkInfo = info.getlinkInfos().get( Id.createLinkId( "15" ) );
if ( linkInfo!= null ){
System.out.println( linkInfo.getTime2toll().toString() );
}

final TravelTime linkTravelTimes = controler.getLinkTravelTimes();
double tt0a = linkTravelTimes.getLinkTravelTime(scenario.getNetwork().getLinks().get(Id.createLinkId("15" ) ), 6 * 3600-1 , null, null );
double tt0b = linkTravelTimes.getLinkTravelTime(scenario.getNetwork().getLinks().get(Id.createLinkId("15" ) ), 6 * 3600 , null, null );
double tt0c = linkTravelTimes.getLinkTravelTime(scenario.getNetwork().getLinks().get(Id.createLinkId("15" ) ), 6 * 3600+15*60 , null, null );
double tt1 = linkTravelTimes.getLinkTravelTime(scenario.getNetwork().getLinks().get(Id.createLinkId("14" ) ), 6 * 3600, null, null );

System.err.println( tt0a + " " + tt0b + " " + tt0c );
System.err.println( tt1 );

Assertions.assertEquals(179.985, tt0a, MatsimTestUtils.EPSILON, "Wrong travel time. The run output seems to have changed.");
Assertions.assertEquals(344.04, tt0b, MatsimTestUtils.EPSILON, "Wrong travel time. The run output seems to have changed.");
Assertions.assertEquals(179.985, tt0c, MatsimTestUtils.EPSILON, "Wrong travel time. The run output seems to have changed.");
Assertions.assertEquals(180.0, tt1, MatsimTestUtils.EPSILON, "Wrong travel time. The run output seems to have changed.");

}


}

0 comments on commit acb7135

Please sign in to comment.