Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add backwards compatibility for dvrp matrix and drt zone system configs #3294

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading