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

Tour mode choice -- clean version #3745

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion production/austin
Submodule austin updated 103 files
2 changes: 1 addition & 1 deletion production/sfbay
Submodule sfbay updated 1500 files
172 changes: 172 additions & 0 deletions src/main/java/beam/agentsim/events/TourModeChoiceEvent.java
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ private void overrideDefaultLoggerSetup(String eventsToWrite) {
case "ModeChoiceEvent":
eventClass = ModeChoiceEvent.class;
break;
case "TourModeChoiceEvent":
eventClass = TourModeChoiceEvent.class;
break;
case "ParkingEvent":
eventClass = ParkingEvent.class;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/beam-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,9 @@ beam.routing {
accessBufferTimeSeconds {
bike = "int | 60"
bike_rent = "int | 180"
walk = "int | 0"
walk = "int | 1"
car = "int | 300"
ride_hail = "int | 0"
ride_hail = "int | 30"
}
}
gh {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/beam/agentsim/agents/MobilityRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ object MobilityRequest {
person,
act,
-1,
Trip(act, None, new Tour()),
Trip(act, None, new Tour(0)),
BeamMode.CAR,
requestType,
-1,
Expand Down
Loading