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

Update MATSim CW35 #112

Merged
merged 45 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b96ea9d
tourStartTime is always set to 0, which can lead to the end time of a…
simei94 Aug 19, 2024
ac0cf1f
avoid deadlock situations with undercharged vehicles at hubs
nkuehnel Aug 20, 2024
ed975c5
Merge branch 'master' into updateShiftsParams
nkuehnel Aug 20, 2024
956ddf6
Merge branch 'master' into updateShiftsParams
nkuehnel Aug 20, 2024
a52f63b
Merge branch 'master' into updateShiftsParams
nkuehnel Aug 20, 2024
eb74e06
Merge pull request #3420 from moia-oss/updateShiftsParams
nkuehnel Aug 20, 2024
f236ed2
dump shifts after each iteration
nkuehnel Aug 21, 2024
d3ebe1d
some updates to drt shifts
nkuehnel Aug 22, 2024
235f85e
Merge branch 'master' into drtShiftsUpdate
nkuehnel Aug 22, 2024
03c1cb1
Merge pull request #3425 from moia-oss/drtShiftsUpdate
steffenaxer Aug 23, 2024
4a6f095
Bypass Fleet object in schedule interface
steffenaxer Aug 23, 2024
c9c868a
Merge pull request #3426 from steffenaxer/ShiftScheduler
steffenaxer Aug 23, 2024
8e7952c
Merge branch 'refs/heads/master' into bugfix-small-scale-commercial-t…
rewertvsp Aug 26, 2024
5335f23
remove static
rewertvsp Aug 26, 2024
55e0883
add comment
rewertvsp Aug 26, 2024
0386228
fix activity creation
rewertvsp Aug 27, 2024
dd608a2
add comments
rewertvsp Aug 27, 2024
b4a3338
update test
rewertvsp Aug 27, 2024
2fc9ced
use getFirst
rewertvsp Aug 27, 2024
22845b4
rename
rewertvsp Aug 27, 2024
809c27b
deprecate methods
rewertvsp Aug 27, 2024
5bc00ca
Fix pt fare config write to and read from config file (#3427)
vsp-gleich Aug 27, 2024
3a29317
use EnumeratedDistribution instead of own class
rewertvsp Aug 27, 2024
5f49dca
move tour specifications to separate class
rewertvsp Aug 27, 2024
53c8f12
add comment
rewertvsp Aug 27, 2024
7c47024
fix import
rewertvsp Aug 27, 2024
77e60ec
Merge branch 'master' into bugfix-small-scale-commercial-traffic-gene…
rewertvsp Aug 27, 2024
efb76f1
Merge remote-tracking branch 'origin/bugfix-small-scale-commercial-tr…
rewertvsp Aug 27, 2024
b074bb6
Merge pull request #3417 from matsim-org/bugfix-small-scale-commercia…
rewertvsp Aug 27, 2024
f9da759
Pt fares extended tests, check distance classes have distinct max dis…
vsp-gleich Aug 27, 2024
614fa89
use getFirst
rewertvsp Aug 28, 2024
1abc0f9
add variable for legMode for extracted plans
rewertvsp Aug 28, 2024
bec04db
Merge pull request #3429 from matsim-org/addModeParameterToLongDistan…
rewertvsp Aug 28, 2024
a632910
pt fares interpret file paths to fare zone shapes relative to config …
vsp-gleich Aug 28, 2024
5089306
fix rare insertion bug
nkuehnel Aug 28, 2024
9d6a5f9
Merge branch 'master' into insertionSchedulerUpdate
nkuehnel Aug 28, 2024
349189c
drt: add option to prevent agents re-attempting to book a rejected pr…
nkuehnel Aug 28, 2024
115e50a
correct german wide fare km / m conversion, add check fare != null in…
vsp-gleich Aug 28, 2024
ce6168a
update tests
nkuehnel Aug 29, 2024
27bf881
Merge branch 'master' into insertionSchedulerUpdate
nkuehnel Aug 29, 2024
783360d
update test
nkuehnel Aug 29, 2024
aa295ae
Merge branch 'master' into prebookingAbortRejectedPassengers
nkuehnel Aug 29, 2024
ac59969
Merge pull request #3432 from moia-oss/prebookingAbortRejectedPassengers
nkuehnel Aug 29, 2024
52e838a
Merge branch 'master' into insertionSchedulerUpdate
nkuehnel Aug 29, 2024
42cff92
Merge pull request #3431 from moia-oss/insertionSchedulerUpdate
nkuehnel Aug 29, 2024
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 @@ -74,6 +74,9 @@ private enum TripType {
@CommandLine.Option(names = "--tripType", description = "Set the tripType: OUTGOING, INCOMING, TRANSIT, INTERNAL, ALL", defaultValue = "ALL")
private TripType tripType;

@CommandLine.Option(names = "--LegMode", description = "Set leg mode for long distance freight legs.", defaultValue = "freight")
private String legMode;

private final SplittableRandom rnd = new SplittableRandom(4711);

private final List<Coord> fromCoords = new ArrayList<>();
Expand Down Expand Up @@ -161,7 +164,7 @@ public Integer call() throws Exception {
boolean destinationIsInside = relevantArea.contains(MGC.coord2Point(sct.transform(endCoord)));

Activity act0 = populationFactory.createActivityFromCoord("freight_start", null);
Leg leg = populationFactory.createLeg("freight");
Leg leg = populationFactory.createLeg(legMode);
Activity act1 = populationFactory.createActivityFromCoord("freight_end", null);

switch (tripType) {
Expand Down Expand Up @@ -312,7 +315,7 @@ private void createActivitiesForIncomingTrips(boolean originIsInside, boolean de
timeSpent += Math.floor(link.getLength() / link.getFreespeed()) + 1;
}
if (!isCoordSet) {
Coord originalCoord = route.links.get(0).getCoord();
Coord originalCoord = route.links.getFirst().getCoord();
act0.setCoord(ct.transform(originalCoord));
act0.setEndTime(departureTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilities;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilityFinder;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DefaultAssignShiftToVehicleLogic;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DefaultShiftStartLogic;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DrtShiftDispatcher;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DrtShiftDispatcherImpl;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.*;
import org.matsim.contrib.drt.extension.operations.shifts.optimizer.ShiftVehicleDataEntryFactory;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftDrtActionCreator;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftDrtTaskFactory;
import org.matsim.contrib.drt.extension.operations.shifts.scheduler.ShiftTaskScheduler;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShifts;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftsSpecification;
import org.matsim.contrib.drt.optimizer.VehicleEntry;
import org.matsim.contrib.drt.prebooking.PrebookingActionCreator;
import org.matsim.contrib.drt.run.DrtConfigGroup;
Expand Down Expand Up @@ -67,19 +64,22 @@ protected void configureQSim() {
).asEagerSingleton();

bindModal(DrtShiftDispatcher.class).toProvider(modalProvider(
getter -> new EDrtShiftDispatcherImpl(((EShiftTaskScheduler) getter.getModal(ShiftTaskScheduler.class)), getter.getModal(ChargingInfrastructure.class),
drtShiftParams, getter.getModal(OperationFacilities.class), new DrtShiftDispatcherImpl(getMode(),
getter.getModal(DrtShifts.class), getter.getModal(Fleet.class),
getter.get(MobsimTimer.class), getter.getModal(OperationFacilities.class), getter.getModal(OperationFacilityFinder.class),
getter.getModal(ShiftTaskScheduler.class), getter.getModal(Network.class), getter.get(EventsManager.class),
drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),
new EDrtAssignShiftToVehicleLogic(new DefaultAssignShiftToVehicleLogic(drtShiftParams), drtShiftParams)),
getter.getModal(Fleet.class)))).asEagerSingleton();
getter -> new EDrtShiftDispatcherImpl(((EShiftTaskScheduler) getter.getModal(ShiftTaskScheduler.class)),
getter.getModal(ChargingInfrastructure.class), drtShiftParams, getter.getModal(OperationFacilities.class),
new DrtShiftDispatcherImpl(getMode(), getter.getModal(Fleet.class), getter.get(MobsimTimer.class),
getter.getModal(OperationFacilities.class), getter.getModal(OperationFacilityFinder.class),
getter.getModal(ShiftTaskScheduler.class), getter.getModal(Network.class), getter.get(EventsManager.class),
drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),
new EDrtAssignShiftToVehicleLogic(new DefaultAssignShiftToVehicleLogic(drtShiftParams), drtShiftParams),
getter.getModal(ShiftScheduler.class)),
getter.getModal(Fleet.class)))
).asEagerSingleton();

bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter ->
new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0),
drtShiftParams.considerUpcomingShiftsForInsertion))).asEagerSingleton();


bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))).in(Singleton.class);
bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class))));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesSpecification;
import org.matsim.contrib.drt.extension.operations.shifts.io.DrtShiftsWriter;
import org.matsim.contrib.drt.extension.operations.shifts.io.OperationFacilitiesWriter;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesSpecification;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftsSpecification;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.events.ShutdownEvent;
import org.matsim.core.controler.listener.ShutdownListener;

import jakarta.inject.Provider;

/**
* Dumps DRT shift related data at end. Based on {@link org.matsim.core.controler.corelisteners.DumpDataAtEndImpl}
*
Expand All @@ -20,13 +18,13 @@
final public class DumpShiftDataAtEndImpl implements ShutdownListener {
private static final Logger log = LogManager.getLogger( DumpShiftDataAtEndImpl.class );

private final Provider<DrtShiftsSpecification> shifts;
private final DrtShiftsSpecification shifts;

private final OperationFacilitiesSpecification operationFacilities;

private final OutputDirectoryHierarchy controlerIO;

public DumpShiftDataAtEndImpl(Provider<DrtShiftsSpecification> shifts, OperationFacilitiesSpecification operationFacilities, OutputDirectoryHierarchy controlerIO) {
public DumpShiftDataAtEndImpl(DrtShiftsSpecification shifts, OperationFacilitiesSpecification operationFacilities, OutputDirectoryHierarchy controlerIO) {
this.shifts = shifts;
this.operationFacilities = operationFacilities;
this.controlerIO = controlerIO;
Expand All @@ -44,7 +42,7 @@ public void notifyShutdown(ShutdownEvent event) {
private void dumpShiftPans() {
try {
if ( this.shifts!=null){
new DrtShiftsWriter(shifts.get()).writeFile(this.controlerIO.getOutputFilename("output_shifts.xml.gz"));
new DrtShiftsWriter(shifts).writeFile(this.controlerIO.getOutputFilename("output_shifts.xml.gz"));
}
} catch ( Exception ee ) {
log.error("Exception writing shifts.", ee);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.matsim.contrib.drt.extension.operations.shifts.analysis;

import com.google.inject.Provider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.contrib.drt.extension.operations.shifts.io.DrtShiftsWriter;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftsSpecification;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.events.IterationEndsEvent;
import org.matsim.core.controler.listener.IterationEndsListener;


/**
*
* @author nkuehnel / MOIA
*/
final public class RegularShiftDump implements IterationEndsListener {
private static final Logger log = LogManager.getLogger( RegularShiftDump.class );

private final Provider<DrtShiftsSpecification> shifts;

private final OutputDirectoryHierarchy controlerIO;

public RegularShiftDump(Provider<DrtShiftsSpecification> shifts, OutputDirectoryHierarchy controlerIO) {
this.shifts = shifts;
this.controlerIO = controlerIO;
}

private void dumpShiftPans(int iteration) {
try {
if ( this.shifts!=null){
new DrtShiftsWriter(shifts.get()).writeFile(this.controlerIO.getIterationFilename(iteration, "output_shifts.xml.gz"));
}
} catch ( Exception ee ) {
log.error("Exception writing shifts.", ee);
}
}


@Override
public void notifyIterationEnds(IterationEndsEvent event) {
dumpShiftPans(event.getIteration());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,28 @@ public void handleEvent(DrtShiftBreakStartedEvent event) {
@Override
public void handleEvent(final DrtShiftEndedEvent event) {
if (event.getMode().equals(mode)) {
final Double start = shift2StartTime.get(event.getShiftId());
double duration = event.getTime() - start;
final DrtShiftSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId());
double plannedDuration = drtShift.getEndTime() - drtShift.getStartTime();
shift2plannedVsActualDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration));
Map<Id<DrtShift>, DrtShiftSpecification> shiftSpecifications = shifts.get().getShiftSpecifications();
if(shiftSpecifications.containsKey(event.getShiftId())) {
final DrtShiftSpecification drtShift = shiftSpecifications.get(event.getShiftId());
final Double start = shift2StartTime.get(event.getShiftId());
double duration = event.getTime() - start;
double plannedDuration = drtShift.getEndTime() - drtShift.getStartTime();
shift2plannedVsActualDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration));
}
}
}

@Override
public void handleEvent(DrtShiftBreakEndedEvent event) {
if (event.getMode().equals(mode)) {
final Double start = shift2BreakStartTime.get(event.getShiftId());
double duration = event.getTime() - start;
final DrtShiftBreakSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow();
double plannedDuration = drtShift.getDuration();
shift2plannedVsActualBreakDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration));
Map<Id<DrtShift>, DrtShiftSpecification> shiftSpecifications = shifts.get().getShiftSpecifications();
if(shiftSpecifications.containsKey(event.getShiftId())) {
final Double start = shift2BreakStartTime.get(event.getShiftId());
double duration = event.getTime() - start;
final DrtShiftBreakSpecification drtShift = shifts.get().getShiftSpecifications().get(event.getShiftId()).getBreak().orElseThrow();
double plannedDuration = drtShift.getDuration();
shift2plannedVsActualBreakDuration.put(event.getShiftId(), new Tuple<>(plannedDuration, duration));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.matsim.contrib.drt.extension.operations.shifts.analysis;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.population.Population;
import org.matsim.contrib.drt.extension.operations.shifts.events.*;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShift;
import org.matsim.core.config.Config;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.core.utils.misc.Time;
Expand All @@ -12,35 +9,30 @@
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UncheckedIOException;
import java.util.Set;

/**
* @author nkuehnel / MOIA
*/
public class ShiftHistogram implements DrtShiftStartedEventHandler, DrtShiftEndedEventHandler,
DrtShiftBreakStartedEventHandler, DrtShiftBreakEndedEventHandler {
DrtShiftBreakStartedEventHandler, DrtShiftBreakEndedEventHandler {

private final String mode;

public static final int DEFAULT_END_TIME = 30 * 3600;
public static final int DEFAULT_BIN_SIZE = 300;
public static final int DEFAULT_END_TIME = 30 * 3600;
public static final int DEFAULT_BIN_SIZE = 300;

private Set<Id<DrtShift>> shiftIds;
private int iteration = 0;
private final int binSize;
private final int nofBins;
private DataFrame data = null;


public ShiftHistogram(Population population, String mode, Config config) {
super();
public ShiftHistogram(String mode, Config config) {
super();
this.mode = mode;
this.binSize = DEFAULT_BIN_SIZE;
this.nofBins = ((int) config.qsim().getEndTime().orElse(DEFAULT_END_TIME) ) / this.binSize + 1;
reset(0);
if (population == null) {
this.shiftIds = null;
}
this.nofBins = ((int) config.qsim().getEndTime().orElse(DEFAULT_END_TIME)) / this.binSize + 1;
reset(0);
}

/**
Expand All @@ -63,21 +55,19 @@ public ShiftHistogram(String mode, final int binSize, final int nofBins) {
public void handleEvent(final DrtShiftStartedEvent event) {
if (event.getMode().equals(mode)) {
int index = getBinIndex(event.getTime());
if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) {
DataFrame dataFrame = getData();
dataFrame.countsStart[index]++;
}
DataFrame dataFrame = getData();
dataFrame.countsStart[index]++;

}
}

@Override
public void handleEvent(final DrtShiftEndedEvent event) {
if (event.getMode().equals(mode)) {
int index = getBinIndex(event.getTime());
if ((this.shiftIds == null || this.shiftIds.contains(event.getShiftId()))) {
DataFrame dataFrame = getData();
dataFrame.countsEnd[index]++;
}
DataFrame dataFrame = getData();
dataFrame.countsEnd[index]++;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
*/
package org.matsim.contrib.drt.extension.operations.shifts.config;

import com.google.common.base.Verify;
import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.contrib.ev.infrastructure.ChargerSpecification;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;

import java.net.URL;
Expand Down Expand Up @@ -60,7 +62,7 @@ public class ShiftsParams extends ReflectiveConfigGroupWithConfigurableParameter
@Parameter
@Comment("defines the battery state of charge threshold at which vehicles will start charging" +
" at hubs when not in an active shift. values between [0,1)")
public double chargeAtHubThreshold = 0.5;
public double chargeAtHubThreshold = 0.6;

@Parameter
@Comment("defines the battery state of charge threshold at which vehicles will start charging" +
Expand Down Expand Up @@ -97,11 +99,19 @@ public class ShiftsParams extends ReflectiveConfigGroupWithConfigurableParameter
"In this case, make sure that 'shiftScheduleLookAhead' is larger than the prebboking slack.")
public boolean considerUpcomingShiftsForInsertion = false;

public ShiftsParams() {
public ShiftsParams() {
super(SET_NAME);
}

public URL getShiftInputUrl(URL context) {
return shiftInputFile == null ? null : ConfigGroup.getInputFileURL(context, shiftInputFile);
}

@Override
protected void checkConsistency(Config config) {
super.checkConsistency(config);
Verify.verify(chargeAtHubThreshold >= shiftAssignmentBatteryThreshold,
"chargeAtHubThreshold must be higher than shiftAssignmentBatteryThreshold to " +
"avoid deadlocks with undercharged vehicles in hubs.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.matsim.contrib.drt.extension.operations.shifts.dispatcher;

import com.google.common.collect.ImmutableMap;
import org.matsim.api.core.v01.Id;
import org.matsim.contrib.drt.extension.operations.shifts.shift.*;
import org.matsim.contrib.dvrp.fleet.Fleet;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
* @author nkuehnel / MOIA
*/
public final class DefaultShiftScheduler implements ShiftScheduler {

private final DrtShiftsSpecification shiftsSpecification;
public static Function<DrtShiftSpecification, DrtShift> createShiftFromSpec = spec -> {
DefaultShiftBreakImpl shiftBreak = null;
DrtShiftBreakSpecification breakSpec = spec.getBreak().orElse(null);
if (breakSpec != null) {
shiftBreak = new DefaultShiftBreakImpl(
breakSpec.getEarliestBreakStartTime(),
breakSpec.getLatestBreakEndTime(),
breakSpec.getDuration());
}
return (DrtShift) new DrtShiftImpl(spec.getId(), spec.getStartTime(), spec.getEndTime(),
spec.getOperationFacilityId().orElse(null), spec.getDesignatedVehicleId().orElse(null),
shiftBreak);
};

public DefaultShiftScheduler(DrtShiftsSpecification shiftsSpecification) {
this.shiftsSpecification = shiftsSpecification;
}
@Override
public List<DrtShift> schedule(double time, Fleet fleet) {
return Collections.emptyList();
}

@Override
public ImmutableMap<Id<DrtShift>, DrtShift> initialSchedule() {
return shiftsSpecification.getShiftSpecifications().values()
.stream()
.map(createShiftFromSpec)
.collect(ImmutableMap.toImmutableMap(DrtShift::getId, s -> s));
}

@Override
public DrtShiftsSpecification get() {
return shiftsSpecification;
}
}
Loading