diff --git a/notebooks/analyze-depot-vehicles.ipynb b/notebooks/analyze-depot-vehicles.ipynb index ea5d967..2eb4862 100644 --- a/notebooks/analyze-depot-vehicles.ipynb +++ b/notebooks/analyze-depot-vehicles.ipynb @@ -18,9 +18,11 @@ "outputs": [], "source": [ "from rssched.io.reader import import_response\n", + "from rssched.io.reader import import_request\n", "\n", "import pandas as pd\n", "\n", + "SOLVER_REQUEST_FILE = \"../rssched/data/small_test_request.json\"\n", "SOLVER_RESPONSE_FILE = \"../rssched/data/small_test_response.json\"" ] }, @@ -30,6 +32,7 @@ "metadata": {}, "outputs": [], "source": [ + "request = import_request(SOLVER_REQUEST_FILE)\n", "response = import_response(SOLVER_RESPONSE_FILE)" ] }, diff --git a/rssched/data/small_test_request.json b/rssched/data/small_test_request.json index a816533..b9cfacc 100644 --- a/rssched/data/small_test_request.json +++ b/rssched/data/small_test_request.json @@ -106,7 +106,7 @@ { "id": "trip_0_seg_1", "routeSegment": "route_0_seg_1", - "departure": "2023-7-24T12:40:00", + "departure": "2023-07-24T12:40:00", "passengers": 100, "seated": 90 } @@ -143,7 +143,7 @@ { "id": "maintenance_slot_0", "location": "ZH", - "start": "2023-07-24T6:00:00", + "start": "2023-07-24T06:00:00", "end": "2023-07-24T12:00:00", "trackCount": 2 }, diff --git a/rssched/io/reader.py b/rssched/io/reader.py index d7b2ee1..4e4aed9 100644 --- a/rssched/io/reader.py +++ b/rssched/io/reader.py @@ -3,6 +3,7 @@ from datetime import datetime from pathlib import Path +from rssched.model.request import Request from rssched.model.response import Info, ObjectiveValue, Response, Schedule @@ -28,6 +29,12 @@ def convert_keys_to_snake_case(data): return data +def import_request(file_path: Path) -> Request: + with open(file_path, "r", encoding="utf-8") as file: + data = convert_keys_to_snake_case(json.load(file)) + return Request(**data) + + def import_response(file_path: Path) -> Response: with open(file_path, "r", encoding="utf-8") as file: data = convert_keys_to_snake_case(json.load(file)) diff --git a/rssched/model/request.py b/rssched/model/request.py new file mode 100644 index 0000000..a8a9989 --- /dev/null +++ b/rssched/model/request.py @@ -0,0 +1,108 @@ +from datetime import datetime +from typing import Dict, List, Optional + +from pydantic import BaseModel + + +class VehicleType(BaseModel): + id: str + capacity: int + seats: int + maximal_formation_count: Optional[int] = None + + +class Location(BaseModel): + id: str + day_limit: Optional[int] = None + + +class AllowedType(BaseModel): + vehicle_type: str + upper_bound: Optional[int] = None + + +class Depot(BaseModel): + id: str + location: str + capacity: int + allowed_types: List[AllowedType] + + +class RouteSegment(BaseModel): + id: str + order: int + origin: str + destination: str + distance: int + duration: int + maximal_formation_count: Optional[int] = None + + +class Route(BaseModel): + id: str + vehicle_type: str + segments: List[RouteSegment] + + +class DepartureSegment(BaseModel): + id: str + route_segment: str + departure: datetime + passengers: int + seated: int + + +class Departure(BaseModel): + id: str + route: str + segments: List[DepartureSegment] + + +class MaintenanceSlot(BaseModel): + id: str + location: str + start: datetime + end: datetime + track_count: int + + +class DeadHeadTrips(BaseModel): + indices: List[str] + durations: List[List[int]] + distances: List[List[int]] + + +class Shunting(BaseModel): + minimal_duration: int + dead_head_trip_duration: int + + +class MaintenanceParameters(BaseModel): + maximal_distance: int + + +class Costs(BaseModel): + staff: int + service_trip: int + maintenance: int + dead_head_trip: int + idle: int + + +class Parameters(BaseModel): + forbid_dead_head_trips: bool + day_limit_threshold: int + shunting: Shunting + maintenance: MaintenanceParameters + costs: Costs + + +class Request(BaseModel): + vehicle_types: List[VehicleType] + locations: List[Location] + depots: List[Depot] + routes: List[Route] + departures: List[Departure] + maintenance_slots: List[MaintenanceSlot] + dead_head_trips: DeadHeadTrips + parameters: Parameters diff --git a/tests/io/test_reader.py b/tests/io/test_reader.py index c74e78b..ab2fc27 100644 --- a/tests/io/test_reader.py +++ b/tests/io/test_reader.py @@ -1,5 +1,12 @@ from rssched.data.access import PkgDataAccess -from rssched.io.reader import import_response +from rssched.io.reader import import_request, import_response + + +def test_import_request(): + request = import_request(PkgDataAccess.locate_request()) + print(request) + assert len(request.vehicle_types) == 2 + assert len(request.routes) == 2 def test_import_response():