diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 98752c5..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: build - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.9", "3.10", "3.11"] - - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --max-complexity=20 --max-line-length=127 --statistics - - name: Test with pytest - run: | - python -m pytest diff --git a/.github/workflows/python-lint.yml b/.github/workflows/python-lint.yml new file mode 100644 index 0000000..3c52586 --- /dev/null +++ b/.github/workflows/python-lint.yml @@ -0,0 +1,24 @@ +name: python lint +on: [push] +jobs: + python-lint: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + steps: + - name: git clone + uses: actions/checkout@v3 + + - name: set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: lint with ruff + run: ruff check --output-format=github . diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml new file mode 100644 index 0000000..8224085 --- /dev/null +++ b/.github/workflows/python-test.yml @@ -0,0 +1,24 @@ +name: python test +on: [push] +jobs: + python-test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12"] + steps: + - name: git clone + uses: actions/checkout@v3 + + - name: set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: unit tests + run: python -m unittest diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ad45950 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022-2023 nextmv.io inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/nextmv-py.code-workspace b/nextmv-py.code-workspace new file mode 100644 index 0000000..8234f0a --- /dev/null +++ b/nextmv-py.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "test*.py"], + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true + } +} diff --git a/nextmv/__init__.py b/nextmv/__init__.py index 777bd8c..1d37ac3 100644 --- a/nextmv/__init__.py +++ b/nextmv/__init__.py @@ -1,3 +1 @@ -from .hello import main - -__all__ = [main] +"""Nextmv Python SDK.""" diff --git a/nextmv/hello.py b/nextmv/hello.py deleted file mode 100644 index 855cc7c..0000000 --- a/nextmv/hello.py +++ /dev/null @@ -1,2 +0,0 @@ -def main(): - print("Hello, Python!") diff --git a/nextmv/nextroute/__init__.py b/nextmv/nextroute/__init__.py new file mode 100644 index 0000000..9064253 --- /dev/null +++ b/nextmv/nextroute/__init__.py @@ -0,0 +1,2 @@ +"""Nextroute is a fast and flexible solver for Vehicle Routing Problems +(VRPs).""" diff --git a/nextmv/nextroute/schema/__init__.py b/nextmv/nextroute/schema/__init__.py new file mode 100644 index 0000000..c9080f6 --- /dev/null +++ b/nextmv/nextroute/schema/__init__.py @@ -0,0 +1,12 @@ +"""Schema (class) definitions for the entities in Nextroute.""" + +from .input import Defaults as Defaults +from .input import DurationGroup as DurationGroup +from .input import Input as Input +from .location import Location as Location +from .stop import AlternateStop as AlternateStop +from .stop import Stop as Stop +from .stop import StopDefaults as StopDefaults +from .vehicle import InitialStop as InitialStop +from .vehicle import Vehicle as Vehicle +from .vehicle import VehicleDefaults as VehicleDefaults diff --git a/nextmv/nextroute/schema/base.py b/nextmv/nextroute/schema/base.py new file mode 100644 index 0000000..b5bb0dd --- /dev/null +++ b/nextmv/nextroute/schema/base.py @@ -0,0 +1,33 @@ +"""Base class for data wrangling.""" + +import json +from dataclasses import asdict, dataclass +from typing import Any + + +@dataclass +class _Base: + """Base class for data wrangling tasks.""" + + @classmethod + def from_dict(cls, data: dict[str, Any]): + """Instantiates the class from a dict.""" + + return cls(**data) + + @classmethod + def from_json(cls, filepath: str): + """Instantiates the class from a JSON file.""" + + with open(filepath) as f: + data = json.load(f) + + return cls.from_dict(data) + + def to_dict(self) -> dict[str, Any]: + """Converts the class to a dict.""" + + return asdict( + self, + dict_factory=lambda x: {k: v for (k, v) in x if v is not None}, + ) diff --git a/nextmv/nextroute/schema/input.py b/nextmv/nextroute/schema/input.py new file mode 100644 index 0000000..1413290 --- /dev/null +++ b/nextmv/nextroute/schema/input.py @@ -0,0 +1,56 @@ +"""Defines the input class""" + +from dataclasses import dataclass +from typing import Any + +from .base import _Base +from .stop import AlternateStop, Stop, StopDefaults +from .vehicle import Vehicle, VehicleDefaults + + +@dataclass +class Defaults(_Base): + """Default values for vehicles and stops.""" + + stops: StopDefaults | None = None + """Default values for stops.""" + vehicles: VehicleDefaults | None = None + """Default values for vehicles.""" + + +@dataclass +class DurationGroup(_Base): + """Represents a group of stops that get additional duration whenever a stop + of the group is approached for the first time.""" + + duration: int + """Duration to add when visiting the group.""" + group: list[str] + """Stop IDs contained in the group.""" + + +@dataclass +class Input(_Base): + """Input schema for Nextroute.""" + + stops: list[Stop] + """Stops that must be visited by the vehicles.""" + vehicles: list[Vehicle] + """Vehicles that service the stops.""" + + alternate_stops: list[AlternateStop] | None = None + """A set of alternate stops for the vehicles.""" + custom_data: Any | None = None + """Arbitrary data associated with the input.""" + defaults: Defaults | None = None + """Default values for vehicles and stops.""" + distance_matrix: list[list[float]] | None = None + """Matrix of travel distances in meters between stops.""" + duratrion_groups: list[DurationGroup] | None = None + """Duration in seconds added when approaching the group.""" + duration_matrix: list[list[float]] | None = None + """Matrix of travel durations in seconds between stops.""" + options: Any | None = None + """Arbitrary options.""" + stop_groups: list[list[str]] | None = None + """Groups of stops that must be part of the same route.""" diff --git a/nextmv/nextroute/schema/location.py b/nextmv/nextroute/schema/location.py new file mode 100644 index 0000000..a2f7360 --- /dev/null +++ b/nextmv/nextroute/schema/location.py @@ -0,0 +1,16 @@ +"""Defines the location class.""" + + +from dataclasses import dataclass + +from .base import _Base + + +@dataclass +class Location(_Base): + """Location represents a geographical location.""" + + lon: float + """Longitude of the location.""" + lat: float + """Latitude of the location.""" diff --git a/nextmv/nextroute/schema/stop.py b/nextmv/nextroute/schema/stop.py new file mode 100644 index 0000000..5ddd396 --- /dev/null +++ b/nextmv/nextroute/schema/stop.py @@ -0,0 +1,66 @@ +"""Defines the stop class.""" + + +from dataclasses import dataclass +from datetime import datetime +from typing import Any + +from .base import _Base +from .location import Location + + +@dataclass +class StopDefaults(_Base): + """Default values for a stop.""" + + compatibility_attributes: list[str] | None = None + """Attributes that the stop is compatible with.""" + duration: int | None = None + """Duration of the stop in seconds.""" + early_arrival_time_penalty: float | None = None + """Penalty per second for arriving at the stop before the target arrival time.""" + late_arrival_time_penalty: float | None = None + """Penalty per second for arriving at the stop after the target arrival time.""" + max_wait: int | None = None + """Maximum waiting duration in seconds at the stop.""" + quantity: Any | None = None + """Quantity of the stop.""" + start_time_window: Any | None = None + """Time window in which the stop can start service.""" + target_arrival_time: datetime | None = None + """Target arrival time at the stop.""" + unplanned_penalty: int | None = None + """Penalty for not planning a stop.""" + + +@dataclass(kw_only=True) +class Stop(StopDefaults): + """Stop is a location that must be visited by a vehicle in a Vehicle + Routing Problem (VRP.)""" + + id: str + """Unique identifier for the stop.""" + location: Location + """Location of the stop.""" + + custom_data: Any | None = None + """Arbitrary data associated with the stop.""" + mixing_items: Any | None = None + """Defines the items that are inserted or removed from the vehicle when visiting the stop.""" + precedes: Any | None = None + """Stops that must be visited after this one on the same route.""" + succeeds: Any | None = None + """Stops that must be visited before this one on the same route.""" + + +@dataclass(kw_only=True) +class AlternateStop(StopDefaults): + """An alternate stop can be serviced instead of another stop.""" + + id: str + """Unique identifier for the stop.""" + location: Location + """Location of the stop.""" + + custom_data: Any | None = None + """Arbitrary data associated with the stop.""" diff --git a/nextmv/nextroute/schema/vehicle.py b/nextmv/nextroute/schema/vehicle.py new file mode 100644 index 0000000..dddad9e --- /dev/null +++ b/nextmv/nextroute/schema/vehicle.py @@ -0,0 +1,73 @@ +"""Defines the vehicle class.""" + + +from dataclasses import dataclass +from datetime import datetime +from typing import Any + +from .base import _Base +from .location import Location + + +@dataclass +class InitialStop(_Base): + """Represents a stop that is already planned on a vehicle.""" + + id: str + """Unique identifier of the stop.""" + + fixed: bool | None = None + """Whether the stop is fixed on the route.""" + + +@dataclass +class VehicleDefaults(_Base): + """Default values for vehicles.""" + + activation_penalty: int | None = None + """Penalty of using the vehicle.""" + alternate_stops: list[str] | None = None + """A set of alternate stops for which only one should be serviced.""" + capacity: Any | None = None + """Capacity of the vehicle.""" + compatibility_attributes: list[str] | None = None + """Attributes that the vehicle is compatible with.""" + end_location: Location | None = None + """Location where the vehicle ends.""" + end_time: datetime | None = None + """Latest time at which the vehicle ends its route.""" + max_distance: int | None = None + """Maximum distance in meters that the vehicle can travel.""" + max_duration: int | None = None + """Maximum duration in seconds that the vehicle can travel.""" + max_stops: int | None = None + """Maximum number of stops that the vehicle can visit.""" + max_wait: int | None = None + """Maximum aggregated waiting time that the vehicle can wait across route stops.""" + min_stops: int | None = None + """Minimum stops that a vehicle should visit.""" + min_stops_penalty: float | None = None + """Penalty for not visiting the minimum number of stops.""" + speed: float | None = None + """Speed of the vehicle in meters per second.""" + start_level: Any | None = None + """Initial level of the vehicle.""" + start_location: Location | None = None + """Location where the vehicle starts.""" + start_time: datetime | None = None + """Time when the vehicle starts its route.""" + + +@dataclass(kw_only=True) +class Vehicle(VehicleDefaults): + """A vehicle services stops in a Vehicle Routing Problem (VRP).""" + + id: str + """Unique identifier of the vehicle.""" + + custom_data: Any | None = None + """Arbitrary custom data.""" + initial_stops: list[InitialStop] | None = None + """Initial stops planned on the vehicle.""" + stop_duration_multiplier: float | None = None + """Multiplier for the duration of stops.""" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7215bdd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["hatchling >= 1.13.0"] +build-backend = "hatchling.build" + +[project] +name = "nextmv" +description = "The Python SDK for Nextmv" +readme = "README.md" +requires-python = ">=3.10" +license = {file = "LICENSE"} +authors = [ + { name = "Nextmv", email = "tech@nextmv.io" } +] +keywords = ["nextmv", "optimization", "solver", "vehicle routing problem", "operations research", "decisions", "decision engineering"] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] +version = "0.1.0" + +[project.urls] +Homepage = "https://www.nextmv.io" +Documentation = "https://www.nextmv.io/docs" +Repository = "https://github.com/nextmv-io/sdk-python" + +[tool.ruff] +target-version = "py312" +select = [ + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes + "I", # isort + "C", # flake8-comprehensions + "B", # flake8-bugbear + "UP", # pyupgrade +] +line-length = 120 diff --git a/requirements.txt b/requirements.txt index e69de29..b3485fe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,3 @@ +ruff==0.1.7 +setuptools==69.0.2 +wheel==0.42.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 337512f..0000000 --- a/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -from os import path -import setuptools - -# Collect additional information from separate files -dir = path.abspath(path.dirname(__file__)) -with open(path.join(dir, "requirements.txt"), encoding="utf-8") as fp: - install_requires = fp.read() -with open(path.join(dir, "version.txt"), encoding="utf-8") as fp: - version = fp.readline().strip() -with open(path.join(dir, "README.md"), encoding="utf-8") as fp: - readme = fp.read() - -# Actual setup -setuptools.setup( - name="nextmv", - description="Nextmv's Python library for solving decision problems", - long_description=readme, - long_description_content_type="text/markdown", - version=version, - author="Nextmv inc.", - author_email="support@nextmv.io", - url="https://github.com/nextmv/sdk-python", - packages=["nextmv"], - install_requires=install_requires, - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - ], -) diff --git a/test/test_hello.py b/test/test_hello.py deleted file mode 100644 index 43aba5b..0000000 --- a/test/test_hello.py +++ /dev/null @@ -1,10 +0,0 @@ -import nextmv - - -def test_hello(): - nextmv.main() - - -if __name__ == "__main__": - test_hello() - print("Everything passed") diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/nextroute/__init__.py b/tests/nextroute/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/nextroute/schema/__init__.py b/tests/nextroute/schema/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/nextroute/schema/input.json b/tests/nextroute/schema/input.json new file mode 100644 index 0000000..bfb9969 --- /dev/null +++ b/tests/nextroute/schema/input.json @@ -0,0 +1,263 @@ +{ + "defaults": { + "vehicles": { + "capacity": { + "bunnies": 20, + "rabbits": 10 + }, + "start_location": { + "lat": 35.791729813680874, + "lon": -78.7401685145487 + }, + "end_location": { + "lat": 35.791729813680874, + "lon": -78.7401685145487 + }, + "speed": 10 + }, + "stops": { + "duration": 300, + "quantity": { + "bunnies": -1, + "rabbits": -1 + }, + "unplanned_penalty": 200000, + "target_arrival_time": "2023-01-01T10:00:00Z", + "early_arrival_time_penalty": 1.5, + "late_arrival_time_penalty": 1.5 + } + }, + "stops": [ + { + "id": "s1", + "location": { + "lon": -78.90919, + "lat": 35.72389 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s2", + "location": { + "lon": -78.813862, + "lat": 35.75712 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s3", + "location": { + "lon": -78.92996, + "lat": 35.932795 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s4", + "location": { + "lon": -78.505745, + "lat": 35.77772 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s5", + "location": { + "lon": -78.75084, + "lat": 35.732995 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s6", + "location": { + "lon": -78.788025, + "lat": 35.813025 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s7", + "location": { + "lon": -78.749391, + "lat": 35.74261 + }, + "compatibility_attributes": ["premium"] + }, + { + "id": "s8", + "location": { + "lon": -78.94658, + "lat": 36.039135 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s9", + "location": { + "lon": -78.64972, + "lat": 35.64796 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s10", + "location": { + "lon": -78.747955, + "lat": 35.672955 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s11", + "location": { + "lon": -78.83403, + "lat": 35.77013 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s12", + "location": { + "lon": -78.864465, + "lat": 35.782855 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s13", + "location": { + "lon": -78.952142, + "lat": 35.88029 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s14", + "location": { + "lon": -78.52748, + "lat": 35.961465 + }, + "compatibility_attributes": ["basic"] + }, + { + "id": "s15", + "location": { + "lon": -78.89832, + "lat": 35.83202 + } + }, + { + "id": "s16", + "location": { + "lon": -78.63216, + "lat": 35.83458 + } + }, + { + "id": "s17", + "location": { + "lon": -78.76063, + "lat": 35.67337 + } + }, + { + "id": "s18", + "location": { + "lon": -78.911485, + "lat": 36.009015 + } + }, + { + "id": "s19", + "location": { + "lon": -78.522705, + "lat": 35.93663 + } + }, + { + "id": "s20", + "location": { + "lon": -78.995162, + "lat": 35.97414 + } + }, + { + "id": "s21", + "location": { + "lon": -78.50509, + "lat": 35.7606 + } + }, + { + "id": "s22", + "location": { + "lon": -78.828547, + "lat": 35.962635 + }, + "precedes": ["s16", "s23"] + }, + { + "id": "s23", + "location": { + "lon": -78.60914, + "lat": 35.84616 + }, + "start_time_window": [ + "2023-01-01T09:00:00-06:00", + "2023-01-01T09:30:00-06:00" + ] + }, + { + "id": "s24", + "location": { + "lon": -78.65521, + "lat": 35.740605 + }, + "start_time_window": [ + "2023-01-01T09:00:00-06:00", + "2023-01-01T09:30:00-06:00" + ], + "succeeds": "s25" + }, + { + "id": "s25", + "location": { + "lon": -78.92051, + "lat": 35.887575 + }, + "start_time_window": [ + "2023-01-01T09:00:00-06:00", + "2023-01-01T09:30:00-06:00" + ], + "precedes": "s26" + }, + { + "id": "s26", + "location": { + "lon": -78.84058, + "lat": 35.823865 + }, + "start_time_window": [ + "2023-01-01T09:00:00-06:00", + "2023-01-01T09:30:00-06:00" + ] + } + ], + "vehicles": [ + { + "id": "vehicle-0", + "start_time": "2023-01-01T06:00:00-06:00", + "end_time": "2023-01-01T10:00:00-06:00", + "activation_penalty": 4000, + "compatibility_attributes": ["premium"] + }, + { + "id": "vehicle-1", + "start_time": "2023-01-01T10:00:00-06:00", + "end_time": "2023-01-01T16:00:00-06:00", + "max_duration": 21000, + "compatibility_attributes": ["basic"] + } + ] +} diff --git a/tests/nextroute/schema/test_input.py b/tests/nextroute/schema/test_input.py new file mode 100644 index 0000000..51e3ae4 --- /dev/null +++ b/tests/nextroute/schema/test_input.py @@ -0,0 +1,21 @@ +import json +import os +import unittest + +from nextmv.nextroute.schema import Input + + +class TestInput(unittest.TestCase): + def test_from_json(self): + filepath = os.path.join(os.path.dirname(__file__), "input.json") + input = Input.from_json(filepath) + parsed = input.to_dict() + with open(filepath) as f: + expected = json.load(f) + + self.maxDiff = None + self.assertEqual( + parsed, + expected, + "Parsing the JSON into the class and back should yield the same result.", + ) diff --git a/version.txt b/version.txt deleted file mode 100644 index 8acdd82..0000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -0.0.1