Skip to content

Commit

Permalink
Merge branch 'main' into to/#104-reset-trips-daily
Browse files Browse the repository at this point in the history
  • Loading branch information
t-ober authored Oct 13, 2022
2 parents a5e20a5 + 043c490 commit bc2bd75
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 123 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Scala ###

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
Expand Down
113 changes: 8 additions & 105 deletions src/main/scala/edu/ie3/mobsim/MobilitySimulator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import edu.ie3.mobsim.MobilitySimulator.Movement
import edu.ie3.mobsim.config.{ArgsParser, ConfigFailFast}
import edu.ie3.mobsim.exceptions.{
InitializationException,
SourceException,
UninitializedException
}
import edu.ie3.mobsim.io.geodata.PoiEnums.{
Expand All @@ -21,7 +20,6 @@ import edu.ie3.mobsim.io.geodata.PoiEnums.{
}
import edu.ie3.mobsim.io.geodata.{PoiUtils, PointOfInterest}
import edu.ie3.mobsim.io.probabilities._
import edu.ie3.mobsim.io.probabilities.factories._
import edu.ie3.mobsim.model.ChargingBehavior.chooseChargingStation
import edu.ie3.mobsim.model.TripSimulation.simulateNextTrip
import edu.ie3.mobsim.model.{
Expand All @@ -48,7 +46,7 @@ import javax.measure.quantity.Length
import scala.collection.immutable.{SortedSet, TreeSet}
import scala.collection.parallel.CollectionConverters._
import scala.jdk.CollectionConverters._
import scala.util.{Failure, Random, Success}
import scala.util.Random

final class MobilitySimulator(
evData: ExtEvData,
Expand Down Expand Up @@ -702,19 +700,6 @@ object MobilitySimulator
.toZonedDateTime(config.mobsim.simulation.startDate)
.withZoneSameInstant(ZoneId.of("UTC"))

logger.debug("Loading probabilities for first departure of day")
val firstDepartureOfDay = FirstDepartureFactory.getFromFile(
pathsAndSources.firstDepartureOfDayPath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for first departure of day from path.",
exception
)
case Success(value) => value
}

/* Initialize all EV objects in the area */
val evModelPdf =
EvType.getEvInputModelsWithProbabilities(
Expand All @@ -729,6 +714,12 @@ object MobilitySimulator
s"Creating $numberOfEvsInArea evs with a targeted home charging share of ${"%.2f"
.format(targetShareOfHomeCharging * 100)} %."
)

val tripProbabilities = TripProbabilities.read(
pathsAndSources,
config.mobsim.input.mobility.source.colSep
)

val evs = ElectricVehicle.createEvs(
numberOfEvsInArea,
poisWithSizes
Expand All @@ -749,7 +740,7 @@ object MobilitySimulator
startTime,
targetShareOfHomeCharging,
evModelPdf,
firstDepartureOfDay
tripProbabilities.firstDepartureOfDay
)
ioUtils.writeEvs(evs)

Expand Down Expand Up @@ -794,94 +785,6 @@ object MobilitySimulator
s"necessarily within reach of the POIs!"
)

val categoricalLocation = CategoricalLocationFactory.getFromFile(
pathsAndSources.categoricalLocationPath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get categorical location probabilities from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for categorical locations")

val drivingSpeed = DrivingSpeedFactory.getFromFile(
pathsAndSources.drivingSpeedPath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get driving speed parameters from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for driving speed")

val lastTripOfDay = LastTripFactory.getFromFile(
pathsAndSources.lastTripPath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get last trip probabilities from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for last trip of day")

val parkingTime = ParkingTimeFactory.getFromFile(
pathsAndSources.parkingTimePath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for parking time from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for parking time")

val poiTransition = PoiTransitionFactory.getFromFile(
pathsAndSources.poiTransitionPath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for poi type transitions from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for poi transition")

val tripDistance = TripDistanceFactory.getFromFile(
pathsAndSources.tripDistancePath,
config.mobsim.input.mobility.source.colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for trip distance transitions from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for trip distance")

val tripProbabilities = TripProbabilities(
categoricalLocation,
drivingSpeed,
firstDepartureOfDay,
lastTripOfDay,
parkingTime,
poiTransition,
tripDistance
)

val mobSim = new MobilitySimulator(
availableEvData,
chargingStations,
Expand Down
125 changes: 125 additions & 0 deletions src/main/scala/edu/ie3/mobsim/io/probabilities/TripProbabilities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@

package edu.ie3.mobsim.io.probabilities

import com.typesafe.scalalogging.LazyLogging
import edu.ie3.mobsim.exceptions.SourceException
import edu.ie3.mobsim.io.probabilities.factories.{
CategoricalLocationFactory,
DrivingSpeedFactory,
FirstDepartureFactory,
LastTripFactory,
ParkingTimeFactory,
PoiTransitionFactory,
TripDistanceFactory
}
import edu.ie3.mobsim.utils.PathsAndSources

import scala.util.{Failure, Success}

/** Container class to wrap probabilities for trip generation.
*
* @param categoricalLocation
Expand All @@ -32,3 +47,113 @@ final case class TripProbabilities(
poiTransition: PoiTransition,
tripDistance: TripDistance
)

object TripProbabilities extends LazyLogging {

def read(
pathsAndSources: PathsAndSources,
colSep: String
): TripProbabilities = {

val firstDepartureOfDay = FirstDepartureFactory.getFromFile(
pathsAndSources.firstDepartureOfDayPath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for first departure of day from path.",
exception
)
case Success(value) => value
}

val categoricalLocation = CategoricalLocationFactory.getFromFile(
pathsAndSources.categoricalLocationPath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get categorical location probabilities from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for categorical locations")

val drivingSpeed = DrivingSpeedFactory.getFromFile(
pathsAndSources.drivingSpeedPath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get driving speed parameters from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for driving speed")

val lastTripOfDay = LastTripFactory.getFromFile(
pathsAndSources.lastTripPath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get last trip probabilities from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for last trip of day")

val parkingTime = ParkingTimeFactory.getFromFile(
pathsAndSources.parkingTimePath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for parking time from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for parking time")

val poiTransition = PoiTransitionFactory.getFromFile(
pathsAndSources.poiTransitionPath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for poi type transitions from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for poi transition")

val tripDistance = TripDistanceFactory.getFromFile(
pathsAndSources.tripDistancePath,
colSep
) match {
case Failure(exception) =>
throw SourceException(
"Unable to get probabilities for trip distance transitions from path.",
exception
)
case Success(value) => value
}
logger.debug("Done loading probabilities for trip distance")

TripProbabilities(
categoricalLocation,
drivingSpeed,
firstDepartureOfDay,
lastTripOfDay,
parkingTime,
poiTransition,
tripDistance
)
}

}
35 changes: 35 additions & 0 deletions src/main/scala/edu/ie3/mobsim/model/ElectricVehicle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,41 @@ import javax.measure.quantity.{Energy, Length, Power}
import scala.collection.immutable.{Queue, SortedSet}
import scala.util.{Failure, Success, Try}

/** Class to denote electric vehicle and its current trip.
*
* @param simulationStart
* start time of simulation
* @param uuid
* its uuid
* @param id
* its id
* @param evType
* type information of car
* @param homePoi
* the vehicles home poi
* @param workPoi
* the vehicles work poi
* @param storedEnergy
* current soc
* @param destinationPoi
* destination POI of current trip
* @param parkingTimeStart
* parking start time of current trip
* @param departureTime
* departure time from destination
* @param chargingAtHomePossible
* whether car can charge at home
* @param chosenChargingStation
* the chosen charging station it wants to charge at
* @param chargingAtSimona
* whether the car will charge at SIMONA
* @param finalDestinationPoi
* stores final destination if making a trip to charging hub
* @param remainingDistanceAfterChargingHub
* distance remaining when departing from charging hub
* @param chargingPricesMemory
* the charging prices at charging stations
*/
final case class ElectricVehicle(
simulationStart: ZonedDateTime,
uuid: UUID,
Expand Down
Loading

0 comments on commit bc2bd75

Please sign in to comment.