Skip to content

Commit

Permalink
Merge branch 'master' into cleanupDeprecatedInFreight
Browse files Browse the repository at this point in the history
  • Loading branch information
rewertvsp committed Nov 29, 2024
2 parents bb8ee1c + adadbe4 commit 8365a69
Show file tree
Hide file tree
Showing 289 changed files with 36,490 additions and 136 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deploy-dtds.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: deploy-dtds-on-website

on:
push:
branches:
- master
pull_request:
types:
- closed
paths:
- matsim/src/main/resources/dtd
- 'matsim/src/main/resources/dtd/**'

jobs:
rsync-dtds:
if: github.event.pull_request.merged == true # only if PR closed by merging
name: sync DTDs to website
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: rsync dtds
uses: burnett01/[email protected]
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/full-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest, windows-latest]
#os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Prepare git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class SquareGridZoneSystem implements GridZoneSystem {

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

private final IdMap<Zone, List<Link>> zoneToLinksMap = new IdMap<>(Zone.class);
private final Map<Integer, List<Link>> index2Links;
private final Network network;

Expand Down Expand Up @@ -114,7 +113,7 @@ public Optional<Zone> getZoneForCoord(Coord coord) {

@Override
public List<Link> getLinksForZoneId(Id<Zone> zone) {
return zoneToLinksMap.get(zone);
return this.index2Links.get(Integer.parseInt(zone.toString()));
}

private Optional<Zone> getOrCreateZone(Coord coord) {
Expand All @@ -129,12 +128,6 @@ private Optional<Zone> getOrCreateZone(Coord coord) {
if(zoneFilter.test(zone)) {
internalZones[index] = zone;
zones.put(zone.getId(), zone);
List<Link> linkList = zoneToLinksMap.computeIfAbsent(zone.getId(), zoneId -> new ArrayList<>());
List<Link> links = index2Links.get(index);
if(links!=null)
{
linkList.addAll(links);
}
} else {
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector;
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector.EventSequence;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.dvrp.optimizer.Request;
import org.matsim.core.controler.events.IterationEndsEvent;
import org.matsim.core.controler.events.ShutdownEvent;
import org.matsim.core.controler.listener.IterationEndsListener;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void notifyIterationEnds(IterationEndsEvent event) {
}

public void write(String fileName) {
Map<Id<Zone>, DescriptiveStatistics> zoneStats = createZonalStats();
Map<Id<Zone>, ZonalStatistics> zoneStats = createZonalStats();
BufferedWriter bw = IOUtils.getBufferedWriter(fileName);
try {
DecimalFormat format = new DecimalFormat();
Expand All @@ -90,7 +91,8 @@ public void write(String fileName) {
String header = new StringJoiner(delimiter)
.add("zone").add("centerX").add("centerY").add("nRequests")
.add("sumWaitTime").add("meanWaitTime").add("min").add("max")
.add("p95").add("p90").add("p80").add("p75").add("p50").toString();
.add("p95").add("p90").add("p80").add("p75").add("p50")
.add("rejections").add("rejectionRate").toString();
bw.append(header);
// sorted output
SortedSet<Id<Zone>> zoneIdsAndOutside = new TreeSet<>(zones.getZones().keySet());
Expand All @@ -100,7 +102,8 @@ public void write(String fileName) {
Zone drtZone = zones.getZones().get(zoneId);
String centerX = drtZone != null ? String.valueOf(drtZone.getCentroid().getX()) : notAvailableString;
String centerY = drtZone != null ? String.valueOf(drtZone.getCentroid().getY()) : notAvailableString;
DescriptiveStatistics stats = zoneStats.get(zoneId);
DescriptiveStatistics stats = zoneStats.get(zoneId).waitStats;
Set<Id<Request>> rejections = zoneStats.get(zoneId).rejections;
bw.newLine();
bw.append(
new StringJoiner(delimiter)
Expand All @@ -116,7 +119,10 @@ public void write(String fileName) {
.add(String.valueOf(stats.getPercentile(90)))
.add(String.valueOf(stats.getPercentile(80)))
.add(String.valueOf(stats.getPercentile(75)))
.add(String.valueOf(stats.getPercentile(50))).toString()
.add(String.valueOf(stats.getPercentile(50)))
.add(String.valueOf(rejections.size()))
.add(String.valueOf(rejections.size() / (double) (rejections.size() + stats.getN())))
.toString()
);
}
bw.flush();
Expand All @@ -126,24 +132,33 @@ public void write(String fileName) {
}
}

private Map<Id<Zone>, DescriptiveStatistics> createZonalStats() {
Map<Id<Zone>, DescriptiveStatistics> zoneStats = new IdMap<>(Zone.class);
record ZonalStatistics(DescriptiveStatistics waitStats, Set<Id<Request>> rejections){}

private Map<Id<Zone>, ZonalStatistics> createZonalStats() {
Map<Id<Zone>, ZonalStatistics> zoneStats = new IdMap<>(Zone.class);
// prepare stats for all zones
for (Id<Zone> zoneId : zones.getZones().keySet()) {
zoneStats.put(zoneId, new DescriptiveStatistics());
zoneStats.put(zoneId, new ZonalStatistics(new DescriptiveStatistics(), new HashSet<>()));
}
zoneStats.put(zoneIdForOutsideOfZonalSystem, new DescriptiveStatistics());
zoneStats.put(zoneIdForOutsideOfZonalSystem, new ZonalStatistics(new DescriptiveStatistics(), new HashSet<>()));

for (EventSequence seq : requestAnalyzer.getPerformedRequestSequences().values()) {
for (Map.Entry<Id<Person>, EventSequence.PersonEvents> entry : seq.getPersonEvents().entrySet()) {
if(entry.getValue().getPickedUp().isPresent()) {
Id<Zone> zone = zones.getZoneForLinkId(seq.getSubmitted().getFromLinkId())
.map(Identifiable::getId).orElse(zoneIdForOutsideOfZonalSystem);
double waitTime = entry.getValue().getPickedUp().get() .getTime() - seq.getSubmitted().getTime();
zoneStats.get(zone).addValue(waitTime);
zoneStats.get(zone).waitStats.addValue(waitTime);
}
}
}

for (EventSequence seq : requestAnalyzer.getRejectedRequestSequences().values()) {
Id<Zone> zone = zones.getZoneForLinkId(seq.getSubmitted().getFromLinkId())
.map(Identifiable::getId).orElse(zoneIdForOutsideOfZonalSystem);
zoneStats.get(zone).rejections.add(seq.getSubmitted().getRequestId());
}

return zoneStats;
}

Expand Down Expand Up @@ -191,16 +206,19 @@ private Collection<SimpleFeature> convertGeometriesToSimpleFeatures(String targe
simpleFeatureBuilder.add("p80", Double.class);
simpleFeatureBuilder.add("p75", Double.class);
simpleFeatureBuilder.add("p50", Double.class);
simpleFeatureBuilder.add("rejections", Double.class);
simpleFeatureBuilder.add("rejectRate", Double.class);
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureBuilder.buildFeatureType());

Collection<SimpleFeature> features = new ArrayList<>();

Map<Id<Zone>, DescriptiveStatistics> zoneStats = createZonalStats();
Map<Id<Zone>, ZonalStatistics> zoneStats = createZonalStats();

for (Zone zone : zones.getZones().values()) {
Object[] routeFeatureAttributes = new Object[14];
Object[] routeFeatureAttributes = new Object[16];
Geometry geometry = zone.getPreparedGeometry() != null ? zone.getPreparedGeometry().getGeometry() : null;
DescriptiveStatistics stats = zoneStats.get(zone.getId());
DescriptiveStatistics stats = zoneStats.get(zone.getId()).waitStats;
Set<Id<Request>> rejections = zoneStats.get(zone.getId()).rejections;
routeFeatureAttributes[0] = geometry;
routeFeatureAttributes[1] = zone.getId();
routeFeatureAttributes[2] = zone.getCentroid().getX();
Expand All @@ -215,6 +233,8 @@ private Collection<SimpleFeature> convertGeometriesToSimpleFeatures(String targe
routeFeatureAttributes[11] = stats.getPercentile(80);
routeFeatureAttributes[12] = stats.getPercentile(75);
routeFeatureAttributes[13] = stats.getPercentile(50);
routeFeatureAttributes[14] = rejections.size();
routeFeatureAttributes[15] = rejections.size() / (double) (rejections.size() + stats.getN());

try {
features.add(builder.buildFeature(zone.getId().toString(), routeFeatureAttributes));
Expand Down
19 changes: 17 additions & 2 deletions contribs/freight/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@

# Freight

Package that plugs freight algorithms (programmed in external package jsprit) into matsim.
This contrib contains the following packages:

## Carriers
(This is formally knows as 'freight contrib')

Package that plugs vehicle routing problem algorithms (programmed in external package jsprit) into MATSim.

A good starting point for jsprit is [ https://github.com/graphhopper/jsprit](https://github.com/graphhopper/jsprit).

For runnable code see, e.g., the packages org.matsim.contrib.freight.usecases.* above .
For runnable code see, e.g., the packages org.matsim.contrib.freight.carriers.usecases.* above .

## Logistics
(This code comes from [https://github.com/matsim-vsp/logistics/](https://github.com/matsim-vsp/logistics/) )

This code deals with creating logistics chains for freight transport.

Here the decision agent is the logistics service provider (LSP) who decides on the logistics chain to be used for a given freight transport request.
Therefore, it can use carriers (see above) and hubs.

This package bases on work in the dfg-freight project.


Loading

0 comments on commit 8365a69

Please sign in to comment.