Skip to content

Commit

Permalink
Merge branch 'master' into kmt_mergeLogisticsProjectIntoMATSim
Browse files Browse the repository at this point in the history
  • Loading branch information
kt86 authored Nov 26, 2024
2 parents 12cfb51 + 1513628 commit 74d4d11
Show file tree
Hide file tree
Showing 67 changed files with 153 additions and 137 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/deploy-dtds.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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

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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Identifiable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import com.google.inject.Inject;
import org.apache.logging.log4j.LogManager;
Expand All @@ -29,8 +29,8 @@
import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.freight.carriers.ScheduledTour;
import org.matsim.freight.carriers.Tour;
import org.matsim.contrib.freightreceiver.collaboration.CollaborationUtils;
import org.matsim.contrib.freightreceiver.replanning.ReceiverStrategyManager;
import org.matsim.freight.receiver.collaboration.CollaborationUtils;
import org.matsim.freight.receiver.replanning.ReceiverStrategyManager;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.events.*;
import org.matsim.core.controler.listener.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* ***********************************************************************
*/

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.matsim.freight.carriers.Carrier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* ***********************************************************************
*/

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import com.google.inject.Inject;
import org.matsim.api.core.v01.Id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* *
* ***********************************************************************
*/
package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.matsim.freight.carriers.Carrier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* ***********************************************************************
*/

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

/**
* The supported ways in which the carrier's cost is spread among the receivers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.matsim.freight.carriers.Carrier;
import org.matsim.contrib.freightreceiver.replanning.*;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.freight.receiver.replanning.ReceiverReplanningUtils;
import org.matsim.freight.receiver.replanning.ReceiverStrategyManager;

public final class ReceiverModule extends AbstractModule {
final private static Logger LOG = LogManager.getLogger(ReceiverModule.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -25,7 +25,7 @@
import org.matsim.api.core.v01.population.Person;
import org.matsim.freight.carriers.Carrier;
import org.matsim.freight.carriers.TimeWindow;
import org.matsim.contrib.freightreceiver.collaboration.CollaborationUtils;
import org.matsim.freight.receiver.collaboration.CollaborationUtils;
import org.matsim.utils.objectattributes.attributable.Attributable;
import org.matsim.utils.objectattributes.attributable.Attributes;
import org.matsim.utils.objectattributes.attributable.AttributesImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

/**
* Returns a new instance of a receiver product with associated information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

public enum ReceiverReplanningType {
serviceTime, timeWindow, orderFrequency, afterHoursTimeWindow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import com.google.inject.Inject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.freight.carriers.CarriersUtils;
import org.matsim.contrib.freightreceiver.collaboration.CollaborationUtils;
import org.matsim.freight.receiver.collaboration.CollaborationUtils;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.events.IterationEndsEvent;
import org.matsim.core.controler.events.ShutdownEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.matsim.core.scoring.ScoringFunction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.apache.logging.log4j.LogManager;
import org.matsim.core.scoring.ScoringFunction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* *
* *********************************************************************** */

package org.matsim.contrib.freightreceiver;
package org.matsim.freight.receiver;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
Expand Down
Loading

0 comments on commit 74d4d11

Please sign in to comment.