Skip to content

Commit

Permalink
Merge branch 'master' into code-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mrieser authored Dec 30, 2023
2 parents 2271c58 + 247deef commit e86faee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -123,7 +122,7 @@ void addCompanionAgents() {
private Person createCompanionAgent(String drtMode, Person originalPerson, TripStructureUtils.Trip trip,
Activity fromActivity, Activity toActivity, int groupPart, int groupSize) {
String prefix = getCompanionPrefix(drtMode);
String companionId = prefix + "_" + originalPerson.getId().toString() + "_" + UUID.randomUUID();
String companionId = prefix + "_" + originalPerson.getId().toString() + "_" + groupPart;
Person person = PopulationUtils.getFactory().createPerson(Id.createPersonId(companionId));
DrtCompanionUtils.setDRTCompanionType(person, DRT_COMPANION_TYPE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public static boolean isSwitchingFromStopToStay(DvrpVehicle vehicle) {
if (!STAY.isBaseTypeOf(currentTask)) {
return false;
}

// only if stay task is last task: with prebooking we may also idle during the day, but
// currently all the downstream relocation/charging logic assumes that we only stay at
// currently all the downstream relocation/charging logic assumes that we only stay at
// the end of the schedule
if (currentTask.getTaskIdx() < schedule.getTaskCount() - 1) {
return false;
Expand All @@ -64,13 +64,15 @@ public static boolean isSwitchingFromStopToStay(DvrpVehicle vehicle) {
}

public static Link findStraightLineNearestDepot(DvrpVehicle vehicle, Set<Link> links) {
Link currentLink = ((DrtStayTask)vehicle.getSchedule().getCurrentTask()).getLink();
Link currentLink = ((DrtStayTask) vehicle.getSchedule().getCurrentTask()).getLink();
return links.contains(currentLink) ?
null /* already at a depot*/ :
links.stream()
.min(Comparator.comparing(
l -> DistanceUtils.calculateSquaredDistance(currentLink.getToNode().getCoord(),
l.getFromNode().getCoord())))
.get();
null /* already at a depot*/ :
links.stream().map(l -> new DepotCandidates(l, DistanceUtils.calculateSquaredDistance(currentLink.getToNode().getCoord(),
l.getFromNode().getCoord())))
.min(Comparator.comparing(DepotCandidates::distance)
.thenComparing(h -> h.link.getId()))
.get().link();
}

record DepotCandidates(Link link, double distance) {}
}

0 comments on commit e86faee

Please sign in to comment.