|
| 1 | +"""Defines the output class.""" |
| 2 | + |
| 3 | + |
| 4 | +from datetime import datetime |
| 5 | +from typing import Any |
| 6 | + |
| 7 | +from pydantic import Field |
| 8 | + |
| 9 | +from nextmv.base_model import BaseModel |
| 10 | +from nextmv.nextroute.check import Output as checkOutput |
| 11 | +from nextmv.nextroute.schema.location import Location |
| 12 | + |
| 13 | + |
| 14 | +class Version(BaseModel): |
| 15 | + """A version used for solving.""" |
| 16 | + |
| 17 | + sdk: str |
| 18 | + """Nextmv SDK.""" |
| 19 | + |
| 20 | + |
| 21 | +class StopOutput(BaseModel): |
| 22 | + """Basic structure for the output of a stop.""" |
| 23 | + |
| 24 | + id: str |
| 25 | + """ID of the stop.""" |
| 26 | + location: Location |
| 27 | + """Location of the stop.""" |
| 28 | + |
| 29 | + custom_data: Any | None = None |
| 30 | + """Custom data of the stop.""" |
| 31 | + |
| 32 | + |
| 33 | +class PlannedStopOutput(BaseModel): |
| 34 | + """Output of a stop planned in the solution.""" |
| 35 | + |
| 36 | + stop: StopOutput |
| 37 | + """Basic information on the stop.""" |
| 38 | + |
| 39 | + arrival_time: datetime | None = None |
| 40 | + """Actual arrival time at this stop.""" |
| 41 | + cumulative_travel_distance: float | None = None |
| 42 | + """Cumulative distance to travel from the first stop to this one, in meters.""" |
| 43 | + cumulative_travel_duration: float | None = None |
| 44 | + """Cumulative duration to travel from the first stop to this one, in seconds.""" |
| 45 | + custom_data: Any | None = None |
| 46 | + """Custom data of the stop.""" |
| 47 | + duration: float | None = None |
| 48 | + """Duration of the service at the stop, in seconds.""" |
| 49 | + early_arrival_duration: float | None = None |
| 50 | + """Duration of early arrival at the stop, in seconds.""" |
| 51 | + end_time: datetime | None = None |
| 52 | + """End time of the service at the stop.""" |
| 53 | + late_arrival_duration: float | None = None |
| 54 | + """Duration of late arrival at the stop, in seconds.""" |
| 55 | + mix_items: Any | None = None |
| 56 | + """Mix items at the stop.""" |
| 57 | + start_time: datetime | None = None |
| 58 | + """Start time of the service at the stop.""" |
| 59 | + target_arrival_time: datetime | None = None |
| 60 | + """Target arrival time at this stop.""" |
| 61 | + travel_distance: float | None = None |
| 62 | + """Distance to travel from the previous stop to this one, in meters.""" |
| 63 | + travel_duration: float | None = None |
| 64 | + """Duration to travel from the previous stop to this one, in seconds.""" |
| 65 | + waiting_duration: float | None = None |
| 66 | + """Waiting duratino at the stop, in seconds.""" |
| 67 | + |
| 68 | + |
| 69 | +class VehicleOutput(BaseModel): |
| 70 | + """Output of a vehicle in the solution.""" |
| 71 | + |
| 72 | + id: str |
| 73 | + """ID of the vehicle.""" |
| 74 | + |
| 75 | + alternate_stops: list[str] | None = None |
| 76 | + """List of alternate stops that were planned on the vehicle.""" |
| 77 | + custom_data: Any | None = None |
| 78 | + """Custom data of the vehicle.""" |
| 79 | + route: list[PlannedStopOutput] | None = None |
| 80 | + """Route of the vehicle, which is a list of stops that were planned on |
| 81 | + it.""" |
| 82 | + route_duration: float | None = None |
| 83 | + """Total duration of the vehicle's route, in seconds.""" |
| 84 | + route_stops_duration: float | None = None |
| 85 | + """Total duration of the stops of the vehicle, in seconds.""" |
| 86 | + route_travel_distance: float | None = None |
| 87 | + """Total travel distance of the vehicle, in meters.""" |
| 88 | + route_travel_duration: float | None = None |
| 89 | + """Total travel duration of the vehicle, in seconds.""" |
| 90 | + route_waiting_duration: float | None = None |
| 91 | + """Total waiting duration of the vehicle, in seconds.""" |
| 92 | + |
| 93 | + |
| 94 | +class ObjectiveOutput(BaseModel): |
| 95 | + """Information of the objective (value function).""" |
| 96 | + |
| 97 | + name: str |
| 98 | + """Name of the objective.""" |
| 99 | + |
| 100 | + base: float | None = None |
| 101 | + """Base of the objective.""" |
| 102 | + custom_data: Any | None = None |
| 103 | + """Custom data of the objective.""" |
| 104 | + factor: float | None = None |
| 105 | + """Factor of the objective.""" |
| 106 | + objectives: list[dict[str, Any]] | None = None |
| 107 | + """List of objectives. Each list is actually of the same class |
| 108 | + `ObjectiveOutput`, but we avoid a recursive definition here.""" |
| 109 | + value: float | None = None |
| 110 | + """Value of the objective, which is equivalent to `self.base * |
| 111 | + self.factor`.""" |
| 112 | + |
| 113 | + |
| 114 | +class Solution(BaseModel): |
| 115 | + """Solution to a Vehicle Routing Problem (VRP).""" |
| 116 | + |
| 117 | + unplanned: list[StopOutput] | None = None |
| 118 | + """List of stops that were not planned in the solution.""" |
| 119 | + vehicles: list[VehicleOutput] | None = None |
| 120 | + """List of vehicles in the solution.""" |
| 121 | + objective: ObjectiveOutput | None = None |
| 122 | + """Information of the objective (value function).""" |
| 123 | + check: checkOutput | None = None |
| 124 | + """Check of the solution, if enabled.""" |
| 125 | + |
| 126 | + |
| 127 | +class RunStatistics(BaseModel): |
| 128 | + """Statistics about a general run.""" |
| 129 | + |
| 130 | + duration: float | None = None |
| 131 | + """Duration of the run in seconds.""" |
| 132 | + iterations: int | None = None |
| 133 | + """Number of iterations.""" |
| 134 | + custom: Any | None = None |
| 135 | + """Custom statistics created by the user. Can normally expect a `dict[str, |
| 136 | + Any]`.""" |
| 137 | + |
| 138 | + |
| 139 | +class ResultStatistics(BaseModel): |
| 140 | + """Statistics about a specific result.""" |
| 141 | + |
| 142 | + duration: float | None = None |
| 143 | + """Duration of the run in seconds.""" |
| 144 | + value: float | None = None |
| 145 | + """Value of the result.""" |
| 146 | + custom: Any | None = None |
| 147 | + """Custom statistics created by the user. Can normally expect a `dict[str, |
| 148 | + Any]`.""" |
| 149 | + |
| 150 | + |
| 151 | +class DataPoint(BaseModel): |
| 152 | + """A data point.""" |
| 153 | + |
| 154 | + x: float |
| 155 | + """X coordinate of the data point.""" |
| 156 | + y: float |
| 157 | + """Y coordinate of the data point.""" |
| 158 | + |
| 159 | + |
| 160 | +class Series(BaseModel): |
| 161 | + """A series of data points.""" |
| 162 | + |
| 163 | + name: str | None = None |
| 164 | + """Name of the series.""" |
| 165 | + data_points: list[DataPoint] | None = None |
| 166 | + """Data of the series.""" |
| 167 | + |
| 168 | + |
| 169 | +class SeriesData(BaseModel): |
| 170 | + """Data of a series.""" |
| 171 | + |
| 172 | + value: Series | None = None |
| 173 | + """A series for the value of the solution.""" |
| 174 | + custom: list[Series] | None = None |
| 175 | + """A list of series for custom statistics.""" |
| 176 | + |
| 177 | + |
| 178 | +class Statistics(BaseModel): |
| 179 | + """Statistics of a solution.""" |
| 180 | + |
| 181 | + run: RunStatistics | None = None |
| 182 | + """Statistics about the run.""" |
| 183 | + result: ResultStatistics | None = None |
| 184 | + """Statistics about the last result.""" |
| 185 | + series_data: SeriesData | None = None |
| 186 | + """Data of the series.""" |
| 187 | + statistics_schema: str | None = Field(alias="schema") |
| 188 | + """Schema (version).""" |
| 189 | + |
| 190 | + |
| 191 | +class Output(BaseModel): |
| 192 | + """Output schema for Nextroute.""" |
| 193 | + |
| 194 | + options: dict[str, Any] |
| 195 | + """Options used to obtain this output.""" |
| 196 | + version: Version |
| 197 | + """Versions used for the solution.""" |
| 198 | + |
| 199 | + solutions: list[Solution] | None = None |
| 200 | + """Solutions to the problem.""" |
| 201 | + statistics: Statistics | None = None |
| 202 | + """Statistics of the solution.""" |
0 commit comments