Skip to content

odys.domain.entities.trip

Vehicle trip that consumes energy and makes the EV unavailable for charging. Trips define time windows, energy consumption, and minimum SoC requirements at departure.

Trip entity for electric vehicle scheduling.

This module provides the Trip class for modeling vehicle trips that consume energy and make the vehicle unavailable for charging.

Trip

Bases: BaseModel

Represents a vehicle trip that consumes energy and makes the vehicle unavailable.

Trips define when an EV is driving (unavailable for charging) and how much energy is consumed. They also specify minimum SoC requirements at departure.

Note: energy_consumption represents the battery-side energy consumed during the trip. This is the energy that must be provided by the battery, accounting for all losses in the drivetrain. Fleet managers can estimate this from vehicle telemetry (kWh used) or calculate from distance x vehicle efficiency.

Source code in src/odys/domain/entities/trip.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class Trip(BaseModel):
    """Represents a vehicle trip that consumes energy and makes the vehicle unavailable.

    Trips define when an EV is driving (unavailable for charging) and how much
    energy is consumed. They also specify minimum SoC requirements at departure.

    Note: energy_consumption represents the battery-side energy consumed during the trip.
    This is the energy that must be provided by the battery, accounting for all losses
    in the drivetrain. Fleet managers can estimate this from vehicle telemetry (kWh used)
    or calculate from distance x vehicle efficiency.
    """

    model_config = ConfigDict(frozen=True, extra="forbid")

    name: str
    start_time: timedelta = Field(
        strict=True,
        ge=timedelta(0),
        description="Time from the start of the horizon at which the trip departs.",
    )
    end_time: timedelta = Field(
        strict=True,
        ge=timedelta(0),
        description="Time from the start of the horizon at which the vehicle is back.",
    )
    energy_consumption: float = Field(
        gt=0,
        description="Battery-side energy consumed during trip in MWh. This is what the battery provides.",
    )
    min_soc_at_departure: float = Field(
        default=0.0,
        ge=0,
        le=1,
        description="Minimum SoC required at departure (start_time), before trip energy is consumed.",
    )

    @model_validator(mode="after")
    def _validate_time_window(self) -> Self:
        if self.end_time <= self.start_time:
            msg = f"end_time ({self.end_time}) must be > start_time ({self.start_time})."
            raise OdysValidationError(msg)
        return self