Skip to content

Commit

Permalink
Merge branch 'master' into drtEstim
Browse files Browse the repository at this point in the history
# Conflicts:
#	contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/estimator/run/DrtEstimatorConfigGroup.java
#	contribs/drt/src/main/java/org/matsim/contrib/drt/run/DrtConfigGroup.java
  • Loading branch information
rakow committed May 6, 2024
2 parents 36e2895 + 25de0eb commit 8643d62
Show file tree
Hide file tree
Showing 193 changed files with 3,994 additions and 2,538 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-on-pr-merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'
server-id: 'matsim-releases'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-on-release-created.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'
server-id: matsim-releases
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'
server-id: 'matsim-releases'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/full-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
if: ${{matrix.module != 'matsim' || steps.detect-changes.outputs.outside-contribs == 'true'}}
uses: actions/setup-java@v4
with:
java-version: 17
java-version: 21
distribution: 'zulu'
cache: 'maven'

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ matsimExamples
matsim/docs/doxygen/html
matsim/src/main/java/Doxyfile

# VS Code files
.vscode

# ignore output directories:
output/
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URL;

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.drt.run.MultiModeDrtModule;
Expand All @@ -33,6 +34,7 @@
import org.matsim.contrib.taxi.run.MultiModeTaxiConfigGroup;
import org.matsim.contrib.taxi.run.MultiModeTaxiModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
Expand All @@ -44,8 +46,13 @@
*/
public class RunDrtAndTaxiExample {
public static void run(URL configUrl, boolean otfvis) {
DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup();
ConfigGroup zoneParams = dvrpConfigGroup.getTravelTimeMatrixParams().createParameterSet(SquareGridZoneSystemParams.SET_NAME);
dvrpConfigGroup.getTravelTimeMatrixParams().addParameterSet(zoneParams);


Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(), new MultiModeTaxiConfigGroup(),
new DvrpConfigGroup(), new OTFVisConfigGroup());
dvrpConfigGroup, new OTFVisConfigGroup());
Scenario scenario = DrtControlerCreator.createScenarioWithDrtRouteFactory(config);
ScenarioUtils.loadScenario(scenario);
config.controller()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
import org.matsim.contrib.commercialTrafficApplications.jointDemand.ChangeCommercialJobOperator;
import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandConfigGroup;
import org.matsim.contrib.commercialTrafficApplications.jointDemand.JointDemandModule;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtConfigs;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.core.config.ConfigGroup;
import org.matsim.freight.carriers.FreightCarriersConfigGroup;
import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.core.config.Config;
Expand Down Expand Up @@ -132,8 +134,11 @@ private static void prepareConfig(Config config) {
}

private static void loadConfigGroups(Config config) {
ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class);
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);
DvrpConfigGroup dvrpConfigGroup = ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class);
ConfigGroup zoneParams = dvrpConfigGroup.getTravelTimeMatrixParams().createParameterSet(SquareGridZoneSystemParams.SET_NAME);
dvrpConfigGroup.getTravelTimeMatrixParams().addParameterSet(zoneParams);

MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);

DrtConfigGroup drtCfg = new DrtConfigGroup();
drtCfg.maxWaitTime = 2 * 3600;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,18 @@
* *********************************************************************** *
*/

package org.matsim.contrib.util;
package org.matsim.contrib.common.util;

import com.google.common.base.Preconditions;
import com.google.common.base.Verify;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ReflectiveConfigGroup;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ReflectiveConfigGroup;

import com.google.common.base.Preconditions;
import com.google.common.base.Verify;

/**
* Provides additional functionality for handling parameter sets according to definitions.
* <p>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.matsim.contrib.common.zones;

import org.matsim.api.core.v01.Coord;

import java.util.Optional;

public interface GridZoneSystem extends ZoneSystem {

Optional<Zone> getZoneForCoord(Coord coord);

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package org.matsim.contrib.common.zones;

import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedPolygon;
import org.matsim.api.core.v01.BasicLocation;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Identifiable;
import org.matsim.api.core.v01.network.Link;
import org.matsim.utils.objectattributes.attributable.Attributable;

import javax.annotation.Nullable;
import java.util.List;

public interface Zone extends BasicLocation, Identifiable<Zone> {
public interface Zone extends BasicLocation, Identifiable<Zone>, Attributable {
@Nullable
PreparedGeometry getPreparedGeometry();
PreparedPolygon getPreparedGeometry();

Coord getCentroid();
String getType();

List<Link> getLinks();
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
package org.matsim.contrib.common.zones;

import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedPolygon;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.utils.objectattributes.attributable.Attributes;
import org.matsim.utils.objectattributes.attributable.AttributesImpl;

import javax.annotation.Nullable;
import java.util.List;

public class ZoneImpl implements Zone {

private final Id<Zone> id;
@Nullable
private final PreparedGeometry preparedGeometry; //null for virtual/dummy zones
private final List<Link> links;
private PreparedPolygon preparedGeometry; //null for virtual/dummy zones
private final Coord centroid;
private String type;

public ZoneImpl(Id<Zone> id, PreparedGeometry preparedGeometry, List<Link> links) {
this(id, preparedGeometry, links, MGC.point2Coord(preparedGeometry.getGeometry().getCentroid()));
private final Attributes attributes = new AttributesImpl();


public ZoneImpl(Id<Zone> id, PreparedPolygon preparedGeometry, @Nullable String type) {
this(id, preparedGeometry, MGC.point2Coord(preparedGeometry.getGeometry().getCentroid()), type);
}

private ZoneImpl(Id<Zone> id, @Nullable PreparedGeometry preparedGeometry, List<Link> links, Coord centroid) {
public ZoneImpl(Id<Zone> id, @Nullable PreparedPolygon preparedGeometry, Coord centroid, @Nullable String type) {
this.id = id;
this.preparedGeometry = preparedGeometry;
this.links = links;
this.centroid = centroid;
}
this.type = type;
}

@Override
public Id<Zone> getId() {
Expand All @@ -40,7 +43,7 @@ public Coord getCoord() {

@Override
@Nullable
public PreparedGeometry getPreparedGeometry() {
public PreparedPolygon getPreparedGeometry() {
return preparedGeometry;
}

Expand All @@ -50,16 +53,25 @@ public Coord getCentroid() {
}

@Override
public List<Link> getLinks() {
return links;
public String getType() {
return type;
}

boolean isDummy() {
return preparedGeometry == null;
}

public static ZoneImpl createDummyZone(Id<Zone> id, List<Link> links, Coord centroid) {
return new ZoneImpl(id, null, links, centroid);
public void setGeometry(PreparedPolygon preparedPolygon) {
this.preparedGeometry = preparedPolygon;
}


public static ZoneImpl createDummyZone(Id<Zone> id, Coord centroid) {
return new ZoneImpl(id, null, centroid, null);
}

@Override
public Attributes getAttributes() {
return attributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Node;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public interface ZoneSystem {
@Nullable
Zone getZoneForLinkId(Id<Link> linkId);
Optional<Zone> getZoneForLinkId(Id<Link> link);

Optional<Zone> getZoneForNodeId(Id<Node> nodeId);

List<Link> getLinksForZoneId(Id<Zone> zone);


Map<Id<Zone>, Zone> getZones();
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
package org.matsim.contrib.common.zones;

import org.apache.commons.lang3.tuple.Pair;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.IdMap;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.network.Node;
import org.matsim.contrib.common.zones.util.ZoneFinder;

import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.*;

public class ZoneSystemImpl implements ZoneSystem {

private final Map<Id<Zone>, Zone> zones = new IdMap<>(Zone.class);
private final IdMap<Link, Zone> link2zone = new IdMap<>(Link.class);

private final IdMap<Node, Zone> nodeToZoneMap = new IdMap<>(Node.class);

private final IdMap<Zone, List<Link>> zoneToLinksMap = new IdMap<>(Zone.class);

public ZoneSystemImpl(Collection<Zone> zones) {
zones.forEach(zone -> this.zones.put(zone.getId(), zone));
zones.stream()
.flatMap(zone -> zone.getLinks().stream().map(link -> Pair.of(link.getId(), zone)))
.forEach(idZonePair -> link2zone.put(idZonePair.getKey(), idZonePair.getValue()));
}

public ZoneSystemImpl(Collection<Zone> zones, ZoneFinder zoneFinder, Network network) {
zones.forEach(zone -> this.zones.put(zone.getId(), zone));

IdMap<Node, Zone> nodeToZoneMap = ZoneSystemUtils.createNodeToZoneMap(network, zoneFinder);
IdMap<Link, Zone> linkToZoneMap = ZoneSystemUtils.createLinkToZoneMap(network, zoneFinder);
this.nodeToZoneMap.putAll(nodeToZoneMap);
this.link2zone.putAll(linkToZoneMap);

for (Link link : network.getLinks().values()) {
zoneFinder.findZone(link.getToNode().getCoord()).ifPresent(zone -> {
List<Link> links = zoneToLinksMap.computeIfAbsent(zone.getId(), zoneId1 -> new ArrayList<>());
links.add(link);
});
}
}

/**
* @param linkId
* @param link
* @return the the {@code DrtZone} that contains the {@code linkId}. If the given link's {@code Coord} borders two or more cells, the allocation to a cell is random.
* Result may be null in case the given link is outside of the service area.
*/
@Override
@Nullable
public Zone getZoneForLinkId(Id<Link> linkId) {
return link2zone.get(linkId);
public Optional<Zone> getZoneForLinkId(Id<Link> link) {
return Optional.ofNullable(link2zone.get(link));
}

@Override
public Optional<Zone> getZoneForNodeId(Id<Node> nodeId) {
return Optional.ofNullable(nodeToZoneMap.get(nodeId));
}

@Override
public List<Link> getLinksForZoneId(Id<Zone> zone) {
return zoneToLinksMap.getOrDefault(zone, Collections.emptyList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.matsim.contrib.common.zones;

import org.matsim.core.config.ReflectiveConfigGroup;

/**
* @author nkuehnel / MOIA
*/
public abstract class ZoneSystemParams extends ReflectiveConfigGroup {
public ZoneSystemParams(String paramSetName) {
super(paramSetName);
}
}
Loading

0 comments on commit 8643d62

Please sign in to comment.