Skip to content

Commit

Permalink
add backwards compatibility for dvrp matrix and drt zone system confi…
Browse files Browse the repository at this point in the history
…gs (#3294)

* add backwards compatibility for dvrp matrix and drt zone system config params

* fix test issue

* addresses #3173 (comment)
  • Loading branch information
nkuehnel authored May 28, 2024
1 parent 0992cf3 commit 1c2cf78
Show file tree
Hide file tree
Showing 4 changed files with 496 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

import jakarta.validation.constraints.NotNull;
import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.contrib.common.zones.GridZoneSystem;
import org.matsim.contrib.common.zones.ZoneSystemParams;
import org.matsim.contrib.common.zones.systems.grid.GISFileZoneSystemParams;
import org.matsim.contrib.common.zones.systems.grid.h3.H3GridZoneSystemParams;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.core.config.ConfigGroup;

/**
* @author Michal Maciejewski (michalm)
Expand Down Expand Up @@ -65,8 +67,69 @@ private void initSingletonParameterSets() {
params -> zoneSystemParams = (H3GridZoneSystemParams)params);
}

@Override
public void handleAddUnknownParam(String paramName, String value) {
switch (paramName) {
case "zonesGeneration": {
if (getZoneSystemParams() == null) {
switch (value) {
case "ShapeFile": {
addParameterSet(createParameterSet(GISFileZoneSystemParams.SET_NAME));
break;
}
case "GridFromNetwork": {
addParameterSet(createParameterSet(SquareGridZoneSystemParams.SET_NAME));
break;
}
case "H3": {
addParameterSet(createParameterSet(H3GridZoneSystemParams.SET_NAME));
break;
}
default:
super.handleAddUnknownParam(paramName, value);
}
}
break;
}
case "cellSize": {
SquareGridZoneSystemParams squareGridParams;
if(getZoneSystemParams() == null) {
squareGridParams = (SquareGridZoneSystemParams) createParameterSet(SquareGridZoneSystemParams.SET_NAME);
addParameterSet(squareGridParams);
} else {
squareGridParams = (SquareGridZoneSystemParams) getZoneSystemParams();
}
squareGridParams.cellSize = Double.parseDouble(value);
break;
}
case "zonesShapeFile": {
GISFileZoneSystemParams gisFileParams;
if(getZoneSystemParams() == null) {
gisFileParams = (GISFileZoneSystemParams) createParameterSet(GISFileZoneSystemParams.SET_NAME);
addParameterSet(gisFileParams);
} else {
gisFileParams = (GISFileZoneSystemParams) getZoneSystemParams();
}
gisFileParams.zonesShapeFile = value;
break;
}
case "h3Resolution": {
H3GridZoneSystemParams h3GridParams;
if(getZoneSystemParams() == null) {
h3GridParams = (H3GridZoneSystemParams) createParameterSet(GISFileZoneSystemParams.SET_NAME);
addParameterSet(h3GridParams);
} else {
h3GridParams = (H3GridZoneSystemParams) getZoneSystemParams();
}
h3GridParams.h3Resolution = Integer.parseInt(value);
break;
}
default:
super.handleAddUnknownParam(paramName, value);
}
}

public ZoneSystemParams getZoneSystemParams() {
return zoneSystemParams;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.matsim.contrib.drt.analysis.zonal;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;

import java.net.URL;

/**
* @author nkuehnel / MOIA
*/
public class ReadOldConfigTest {

@Test
public void test() {
URL context = ExamplesUtils.getTestScenarioURL("kelheim");
Config config = ConfigUtils.loadConfig(IOUtils.extendUrl(context, "config-with-drt_old.xml"));
Assertions.assertThatNoException().isThrownBy(() -> ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class));
Assertions.assertThatNoException().isThrownBy(() -> ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ private void initSingletonParameterSets() {
params -> zoneSystemParams = (H3GridZoneSystemParams)params);
}

@Override
public void handleAddUnknownParam(String paramName, String value) {
if ("cellSize".equals(paramName)) {
SquareGridZoneSystemParams squareGridParams;
if(getZoneSystemParams() == null) {
squareGridParams = (SquareGridZoneSystemParams) createParameterSet(SquareGridZoneSystemParams.SET_NAME);
addParameterSet(squareGridParams);
} else {
squareGridParams = (SquareGridZoneSystemParams) getZoneSystemParams();
}
squareGridParams.cellSize = Double.parseDouble(value);
} else {
super.handleAddUnknownParam(paramName, value);
}
}

public ZoneSystemParams getZoneSystemParams() {
return zoneSystemParams;
}
Expand Down
Loading

0 comments on commit 1c2cf78

Please sign in to comment.