Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jp/depot-charging-rhm' into rjf/#…
Browse files Browse the repository at this point in the history
…1946-rhm-parking-infrastructure

# Conflicts:
#	src/main/scala/beam/agentsim/infrastructure/ZonalParkingManager.scala
#	src/main/scala/beam/agentsim/infrastructure/charging/ChargingPointType.scala
#	src/main/scala/beam/agentsim/infrastructure/parking/ParkingZoneSearch.scala
  • Loading branch information
robfitzgerald committed Jul 11, 2019
2 parents 3f67865 + 91c5b29 commit 0613af6
Show file tree
Hide file tree
Showing 63 changed files with 1,336 additions and 437 deletions.
161 changes: 84 additions & 77 deletions src/main/java/beam/agentsim/events/handling/BeamEventsLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@

import java.util.*;


/**
* Logger class for BEAM events
*/
class BeamEventsLogger {

private final EventsManager eventsManager;
private final MatsimServices matsimServices;
private final BeamServices beamServices;
private final List<BeamEventsWriterBase> writers = new ArrayList<>();
private final Set<Class<?>> eventsToLog = new HashSet<>();
private final EventsManager eventsManager;
private final MatsimServices matsimServices;
private final BeamServices beamServices;
private final List<BeamEventsWriterBase> writers = new ArrayList<>();
private final Set<Class<?>> eventsToLog = new HashSet<>();
private final List<BeamEventsFileFormats> eventsFileFormatsArray = new ArrayList<>();

BeamEventsLogger(BeamServices beamServices, MatsimServices matsimServices, EventsManager eventsManager) {
Expand All @@ -31,7 +32,7 @@ class BeamEventsLogger {
}

void iterationEnds() {
for (BeamEventsWriterBase writer : writers) {
for(BeamEventsWriterBase writer : writers) {
writer.closeFile();
eventsManager.removeHandler(writer);
}
Expand All @@ -42,10 +43,10 @@ private void createEventsWriters() {
int iterationNumber = matsimServices.getIterationNumber();
final int writeEventsInterval = beamServices.beamConfig().beam().outputs().writeEventsInterval();
final boolean writeThisIteration = (writeEventsInterval > 0) && (iterationNumber % writeEventsInterval == 0);
if (writeThisIteration) {
if(writeThisIteration) {
matsimServices.getControlerIO().createIterationDirectory(iterationNumber);
String eventsFileBasePath = matsimServices.getControlerIO().getIterationFilename(iterationNumber, "events");
for (BeamEventsFileFormats fmt : eventsFileFormatsArray) {
for(BeamEventsFileFormats fmt : eventsFileFormatsArray) {
BeamEventsWriterBase newWriter;
newWriter = createEventWriterForClassAndFormat(eventsFileBasePath, null, fmt);
writers.add(newWriter);
Expand All @@ -55,11 +56,12 @@ private void createEventsWriters() {
}

private BeamEventsWriterBase createEventWriterForClassAndFormat(String eventsFilePathBase,
Class<?> theClass, BeamEventsFileFormats fmt) {
Class<?> theClass,
BeamEventsFileFormats fmt) {
final String path = eventsFilePathBase + "." + fmt.getSuffix();
if (fmt == BeamEventsFileFormats.XML || fmt == BeamEventsFileFormats.XML_GZ) {
if(fmt == BeamEventsFileFormats.XML || fmt == BeamEventsFileFormats.XML_GZ) {
return new BeamEventsWriterXML(path, this, beamServices, theClass);
} else if (fmt == BeamEventsFileFormats.CSV || fmt == BeamEventsFileFormats.CSV_GZ) {
} else if(fmt == BeamEventsFileFormats.CSV || fmt == BeamEventsFileFormats.CSV_GZ) {
return new BeamEventsWriterCSV(path, this, beamServices, theClass);
}
return null;
Expand All @@ -80,9 +82,8 @@ Set<Class<?>> getAllEventsToLog() {
private void setEventsFileFormats() {
eventsFileFormatsArray.clear();
String eventsFileFormats = beamServices.beamConfig().beam().outputs().events().fileOutputFormats();
for (String format : eventsFileFormats.split(",")) {
BeamEventsFileFormats.from(format)
.ifPresent(eventsFileFormatsArray::add);
for(String format : eventsFileFormats.split(",")) {
BeamEventsFileFormats.from(format).ifPresent(eventsFileFormatsArray::add);
}
}

Expand All @@ -98,71 +99,77 @@ private void overrideDefaultLoggerSetup() {
// Generate the required event class reference based on the class name
String eventsToWrite = beamServices.beamConfig().beam().outputs().events().eventsToWrite();
if(!eventsToWrite.isEmpty()) {
for (String className : beamServices.beamConfig().beam().outputs().events().eventsToWrite()
.split(",")) {
switch (className) {
case "ActivityStartEvent":
eventClass = ActivityStartEvent.class;
break;
case "ActivityEndEvent":
eventClass = ActivityEndEvent.class;
break;
case "LeavingParkingEvent":
eventClass = LeavingParkingEvent.class;
break;
case "LinkEnterEvent":
eventClass = LinkEnterEvent.class;
break;
case "LinkLeaveEvent":
eventClass = LinkLeaveEvent.class;
break;
case "ModeChoiceEvent":
eventClass = ModeChoiceEvent.class;
break;
case "ParkEvent":
eventClass = ParkEvent.class;
break;
case "PathTraversalEvent":
eventClass = PathTraversalEvent.class;
break;
case "PersonArrivalEvent":
eventClass = PersonArrivalEvent.class;
break;
case "PersonDepartureEvent":
eventClass = PersonDepartureEvent.class;
break;
case "PersonEntersVehicleEvent":
eventClass = PersonEntersVehicleEvent.class;
break;
case "PersonLeavesVehicleEvent":
eventClass = PersonLeavesVehicleEvent.class;
break;
case "RefuelEvent":
eventClass = RefuelEvent.class;
break;
case "ReplanningEvent":
eventClass = ReplanningEvent.class;
break;
case "ReserveRideHailEvent":
eventClass = ReserveRideHailEvent.class;
break;
case "VehicleEntersTrafficEvent":
eventClass = VehicleEntersTrafficEvent.class;
break;
case "VehicleLeavesTrafficEvent":
eventClass = VehicleLeavesTrafficEvent.class;
break;
case "PersonCostEvent":
eventClass = PersonCostEvent.class;
break;
case "AgencyRevenueEvent":
eventClass = AgencyRevenueEvent.class;
break;
default:
DebugLib.stopSystemAndReportInconsistency("Logging class name: Unidentified event type class " + className);
for(String className : beamServices.beamConfig().beam().outputs().events().eventsToWrite().split(",")) {
switch(className) {
case "ActivityStartEvent":
eventClass = ActivityStartEvent.class;
break;
case "ActivityEndEvent":
eventClass = ActivityEndEvent.class;
break;
case "LeavingParkingEvent":
eventClass = LeavingParkingEvent.class;
break;
case "LinkEnterEvent":
eventClass = LinkEnterEvent.class;
break;
case "LinkLeaveEvent":
eventClass = LinkLeaveEvent.class;
break;
case "ModeChoiceEvent":
eventClass = ModeChoiceEvent.class;
break;
case "ParkEvent":
eventClass = ParkEvent.class;
break;
case "PathTraversalEvent":
eventClass = PathTraversalEvent.class;
break;
case "PersonArrivalEvent":
eventClass = PersonArrivalEvent.class;
break;
case "PersonDepartureEvent":
eventClass = PersonDepartureEvent.class;
break;
case "PersonEntersVehicleEvent":
eventClass = PersonEntersVehicleEvent.class;
break;
case "PersonLeavesVehicleEvent":
eventClass = PersonLeavesVehicleEvent.class;
break;
case "RefuelSessionEvent":
eventClass = RefuelSessionEvent.class;
break;
case "ChargingPlugOutEvent":
eventClass = ChargingPlugOutEvent.class;
break;
case "ChargingPlugInEvent":
eventClass = ChargingPlugInEvent.class;
break;
case "ReplanningEvent":
eventClass = ReplanningEvent.class;
break;
case "ReserveRideHailEvent":
eventClass = ReserveRideHailEvent.class;
break;
case "VehicleEntersTrafficEvent":
eventClass = VehicleEntersTrafficEvent.class;
break;
case "VehicleLeavesTrafficEvent":
eventClass = VehicleLeavesTrafficEvent.class;
break;
case "PersonCostEvent":
eventClass = PersonCostEvent.class;
break;
case "AgencyRevenueEvent":
eventClass = AgencyRevenueEvent.class;
break;
default:
DebugLib.stopSystemAndReportInconsistency(
"Logging class name: Unidentified event type class " + className);
}
//add the matched event class to the list of events to log
if (eventClass != null)
if(eventClass != null)
eventsToLog.add(eventClass);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/beam-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ beam.debug.stuckAgentDetection {
}
},
{
triggerType = "beam.agentsim.agents.modalbehaviors.DrivesVehicle$StartRefuelTrigger"
triggerType = "beam.agentsim.agents.modalbehaviors.DrivesVehicle$StartRefuelSessionTrigger"
markAsStuckAfterMs = "duration:ms | 21s"
actorTypeToMaxNumberOfMessages {
population = "int?"
Expand All @@ -356,7 +356,7 @@ beam.debug.stuckAgentDetection {
}
},
{
triggerType = "beam.agentsim.agents.modalbehaviors.DrivesVehicle$EndRefuelTrigger"
triggerType = "beam.agentsim.agents.modalbehaviors.DrivesVehicle$EndRefuelSessionTrigger"
markAsStuckAfterMs = "duration:ms | 21s"
actorTypeToMaxNumberOfMessages {
population = "int?"
Expand Down Expand Up @@ -449,7 +449,7 @@ beam.outputs.events.fileOutputFormats = "csv" # valid options: xml(.gz) , csv(.g

# Events Writing Logging Levels:
# Any event types not explicitly listed in overrideWritingLevels take on defaultWritingLevel
beam.outputs.events.eventsToWrite = "ActivityEndEvent,ActivityStartEvent,PersonEntersVehicleEvent,PersonLeavesVehicleEvent,ModeChoiceEvent,PathTraversalEvent,ReserveRideHailEvent,ReplanningEvent,RefuelEvent,ParkEvent,LeavingParkingEvent"
beam.outputs.events.eventsToWrite = "ActivityEndEvent,ActivityStartEvent,PersonEntersVehicleEvent,PersonLeavesVehicleEvent,ModeChoiceEvent,PathTraversalEvent,ReserveRideHailEvent,ReplanningEvent,RefuelSessionEvent,ChargingPlugInEvent,ChargingPlugOutEvent,ParkEvent,LeavingParkingEvent"
beam.outputs.stats.binSize = 3600

##################################################################
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Logger name="beam.utils.DebugActorWithTimer" level="ERROR" />
<Logger name="beam.calibration" level="INFO" />
<Logger name="beam.router.BeamRouter" level="ERROR" />
<Logger name="beam.agentsim.agents.ridehail.RideHailAgent " level="DEBUG" />
<Logger name="beam.agentsim.agents.TransitDriverAgent" level="ERROR" />
<Logger name="beam.router.r5.R5RoutingWorker" level="INFO" />
<!--<Logger name="beam.agentsim.agents.vehicles.BeamVehicle" level="error" additivity="false">-->
Expand Down
16 changes: 16 additions & 0 deletions src/main/scala/beam/agentsim/agents/PersonAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.matsim.api.core.v01.Id
import org.matsim.api.core.v01.events._
import org.matsim.api.core.v01.population._
import org.matsim.core.api.experimental.events.{EventsManager, TeleportationArrivalEvent}
import org.matsim.core.utils.misc.Time
import org.matsim.vehicles.Vehicle

import scala.concurrent.duration._
Expand Down Expand Up @@ -333,6 +334,18 @@ class PersonAgent(
nextActivity(data) match {
case None =>
logDebug(s"didn't get nextActivity")

// if we still have a BEV/PHEV that is connected to a charging point,
// we assume that they will charge until the end of the simulation and throwing events accordingly
beamVehicles.foreach(idVehicleOrTokenTuple => {
beamScenario.privateVehicles
.get(idVehicleOrTokenTuple._1)
.foreach(beamvehicle => {
if ((beamvehicle.isPHEV | beamvehicle.isBEV) & beamvehicle.isConnectedToChargingPoint()) {
handleEndCharging(Time.parseTime(beamScenario.beamConfig.beam.agentsim.endTime).toInt, beamvehicle)
}
})
})
stop replying CompletionNotice(triggerId)
case Some(nextAct) =>
logDebug(s"wants to go to ${nextAct.getType} @ $tick")
Expand Down Expand Up @@ -1000,6 +1013,9 @@ class PersonAgent(
stop(Failure("Unexpected RideHailResponse"))
case Event(ParkingInquiryResponse(_, _), _) =>
stop(Failure("Unexpected ParkingInquiryResponse"))
case Event(e, s) =>
log.warning("received unhandled request {} in state {}/{}", e, stateName, s)
stay()
}

whenUnhandled(drivingBehavior.orElse(myUnhandled))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ object MultinomialLogit {
)

def apply[A, T](utilityFunctions: Map[A, Map[T, UtilityFunctionOperation]]): MultinomialLogit[A, T] = {
new MultinomialLogit(utilityFunctions, Map())
new MultinomialLogit(utilityFunctions, Map.empty)
}

def apply[A, T](
Expand All @@ -181,4 +181,10 @@ object MultinomialLogit {
): MultinomialLogit[A, T] = {
new MultinomialLogit(utilityFunctions, commonUtilityFunction)
}

// cannot add this constructor, because after type erasure, it looks the same as the first one. :-(
// def apply[A, T](
// singleUtilityFunction: Map[T, UtilityFunctionOperation]
// ): MultinomialLogit[A, T] = new MultinomialLogit(Map.empty, singleUtilityFunction)

}
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ object HouseholdActor {
veh.manager = Some(self)
veh.spaceTime = SpaceTime(homeCoord.getX, homeCoord.getY, 0)
for {
ParkingInquiryResponse(stall, _) <- parkingManager ? ParkingInquiry(homeCoord, "home", 0.0, None, 0)
ParkingInquiryResponse(stall, _) <- parkingManager ? ParkingInquiry.apply(homeCoord, "home")
} {
veh.useParkingStall(stall)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class HouseholdFleetManager(parkingManager: ActorRef, vehicles: Map[Id[BeamVehic
veh.spaceTime = SpaceTime(homeCoord.getX, homeCoord.getY, 0)
veh.mustBeDrivenHome = true
for {
ParkingInquiryResponse(stall, _) <- parkingManager ? ParkingInquiry(homeCoord, "home", 0.0, None, 0)
ParkingInquiryResponse(stall, _) <- parkingManager ? ParkingInquiry.apply(homeCoord, "home")
} {
veh.useParkingStall(stall)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ trait ChoosesMode {
destinationInUTM,
activityType,
attributes.valueOfTime,
None,
ParkingInquiry.simpleDistanceAndParkingTicketEqualUtilityFunction,
duration,
reserveStall = false
)
Expand Down
Loading

0 comments on commit 0613af6

Please sign in to comment.