-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3900 from LBNL-UCB-STI/tour-mode-clean-develop202403
Tour mode -- again
- Loading branch information
Showing
101 changed files
with
5,443 additions
and
1,090 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule seattle
updated
79 files
Submodule sfbay
updated
6474 files
172 changes: 172 additions & 0 deletions
172
src/main/java/beam/agentsim/events/TourModeChoiceEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package beam.agentsim.events; | ||
|
||
import beam.agentsim.agents.modalbehaviors.DrivesVehicle; | ||
import beam.agentsim.agents.planning.Tour; | ||
import beam.agentsim.agents.planning.Trip; | ||
import beam.router.Modes; | ||
import beam.router.TourModes; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.api.core.v01.events.Event; | ||
import org.matsim.api.core.v01.population.Activity; | ||
import org.matsim.api.core.v01.population.Person; | ||
import org.matsim.core.api.internal.HasPersonId; | ||
import scala.collection.JavaConverters; | ||
import scala.collection.Seq; | ||
import scala.collection.immutable.Vector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* BEAM | ||
*/ | ||
|
||
|
||
|
||
public class TourModeChoiceEvent extends Event implements HasPersonId { | ||
public final static String EVENT_TYPE = "TourModeChoice"; | ||
public final static String ATTRIBUTE_PERSON_ID = "person"; | ||
|
||
public final static String ATTRIBUTE_TOUR_MODE = "tourMode"; | ||
public final static String ATTRIBUTE_MODE_TO_TOUR_MODE = "modeToTourMode"; | ||
public final static String ATTRIBUTE_AVAILABLE_VEHICLES = "availableVehicles"; | ||
public final static String ATTRIBUTE_TOUR_ACTIVITIES = "tourActivities"; | ||
public final static String ATTRIBUTE_AVAILABLE_MODES = "availableModes"; | ||
public final static String ATTRIBUTE_TOUR_MODE_UTILITY = "tourModeUtility"; | ||
public final static String ATTRIBUTE_CURRENT_ACTIVITY = "startActivity"; | ||
public final static String ATTRIBUTE_CURRENT_ACTIVITY_X = "startX"; | ||
public final static String ATTRIBUTE_CURRENT_ACTIVITY_Y = "startY"; | ||
|
||
public final Id<Person> personId; | ||
public final String tourMode; | ||
public final Tour currentTour; | ||
public final String modeToTourModeString; | ||
public final String availablePersonalStreetVehiclesString; | ||
public final String tourActivitiesString; | ||
public final String availableModesString; | ||
public final String tourModeToUtilityString; | ||
public final String startActivityType; | ||
public final Double startX; | ||
public final Double startY; | ||
|
||
|
||
|
||
public TourModeChoiceEvent(double time, | ||
Id<Person> personId, | ||
String tourMode, | ||
Tour currentTour, | ||
Vector<DrivesVehicle.VehicleOrToken> availablePersonalStreetVehicles, | ||
scala.collection.immutable.Map<TourModes.BeamTourMode, Seq<Modes.BeamMode>> modeToTourMode, | ||
scala.collection.immutable.Map<TourModes.BeamTourMode, scala.Double> tourModeUtils, | ||
Vector<Modes.BeamMode> availableModes, | ||
Activity startActivity) { | ||
this(time, | ||
personId, | ||
tourMode, | ||
currentTour, | ||
modeToTourMode.mkString("-"), | ||
stringifyVehicles(availablePersonalStreetVehicles), | ||
currentTour == null ? "" : stringifyActivities(currentTour), | ||
availableModes.mkString("-"), | ||
tourModeUtils.mkString("; "), | ||
startActivity.getType(), | ||
startActivity.getCoord().getX(), | ||
startActivity.getCoord().getY()); | ||
} | ||
|
||
public TourModeChoiceEvent(double time, | ||
Id<Person> personId, | ||
String tourMode, | ||
Tour currentTour, | ||
String modeToTourModeString, | ||
String availablePersonalStreetVehiclesString, | ||
String tourActivitiesString, | ||
String availableModesString, | ||
String tourModeToUtilityString, | ||
String startActivityType, | ||
Double startX, | ||
Double startY) { | ||
super(time); | ||
|
||
this.personId = personId; | ||
this.tourMode = tourMode; | ||
this.currentTour = currentTour; | ||
this.modeToTourModeString = modeToTourModeString; | ||
this.availablePersonalStreetVehiclesString = availablePersonalStreetVehiclesString; | ||
this.tourActivitiesString = tourActivitiesString; | ||
this.availableModesString = availableModesString; | ||
this.tourModeToUtilityString = tourModeToUtilityString; | ||
this.startActivityType = startActivityType; | ||
this.startX = startX; | ||
this.startY = startY; | ||
} | ||
|
||
public static TourModeChoiceEvent apply(Event event) { | ||
if (!(event instanceof TourModeChoiceEvent) && EVENT_TYPE.equalsIgnoreCase(event.getEventType())) { | ||
Map<String, String> attr = event.getAttributes(); | ||
return new TourModeChoiceEvent(event.getTime(), | ||
Id.createPersonId(attr.get(ATTRIBUTE_PERSON_ID)), | ||
attr.get(ATTRIBUTE_TOUR_MODE), | ||
null, | ||
attr.get(ATTRIBUTE_MODE_TO_TOUR_MODE), | ||
attr.get(ATTRIBUTE_AVAILABLE_VEHICLES), | ||
attr.get(ATTRIBUTE_TOUR_ACTIVITIES), | ||
attr.get(ATTRIBUTE_AVAILABLE_MODES), | ||
attr.get(ATTRIBUTE_TOUR_MODE_UTILITY), | ||
attr.get(ATTRIBUTE_CURRENT_ACTIVITY), | ||
Double.parseDouble(attr.get(ATTRIBUTE_CURRENT_ACTIVITY_Y)), | ||
Double.parseDouble(attr.get(ATTRIBUTE_CURRENT_ACTIVITY_X)) | ||
); | ||
} | ||
return (TourModeChoiceEvent) event; | ||
} | ||
|
||
|
||
@Override | ||
public Map<String, String> getAttributes() { | ||
Map<String, String> attr = super.getAttributes(); | ||
attr.put(ATTRIBUTE_PERSON_ID, personId.toString()); | ||
attr.put(ATTRIBUTE_TOUR_MODE, tourMode); | ||
attr.put(ATTRIBUTE_MODE_TO_TOUR_MODE, modeToTourModeString); | ||
attr.put(ATTRIBUTE_AVAILABLE_VEHICLES, availablePersonalStreetVehiclesString); | ||
attr.put(ATTRIBUTE_TOUR_ACTIVITIES, tourActivitiesString); | ||
attr.put(ATTRIBUTE_AVAILABLE_MODES, availableModesString); | ||
attr.put(ATTRIBUTE_TOUR_MODE_UTILITY, tourModeToUtilityString); | ||
attr.put(ATTRIBUTE_CURRENT_ACTIVITY, startActivityType); | ||
attr.put(ATTRIBUTE_CURRENT_ACTIVITY_X, Double.toString(startX)); | ||
attr.put(ATTRIBUTE_CURRENT_ACTIVITY_Y, Double.toString(startY)); | ||
return attr; | ||
} | ||
|
||
@Override | ||
public String getEventType() { | ||
return EVENT_TYPE; | ||
} | ||
|
||
@Override | ||
public Id<Person> getPersonId() { | ||
return personId; | ||
} | ||
|
||
|
||
public static String stringifyVehicles(Vector<DrivesVehicle.VehicleOrToken> vehicles) { | ||
List<String> out = new ArrayList<>(); | ||
List<DrivesVehicle.VehicleOrToken> javaVehicles = JavaConverters.seqAsJavaList(vehicles.toSeq()); | ||
for (DrivesVehicle.VehicleOrToken veh : javaVehicles) { | ||
out.add(veh.vehicle().beamVehicleType().toString()); | ||
} | ||
return String.join("-", out); | ||
} | ||
|
||
public static String stringifyActivities(Tour tour) { | ||
List<String> out = new ArrayList<>(); | ||
List<Activity> javaActivities = JavaConverters.seqAsJavaList(tour.activities().toSeq()); | ||
for (Activity act : javaActivities) { | ||
out.add(act.getType()); | ||
} | ||
return String.join("->", out); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.