Skip to content

Commit

Permalink
Update to latest python app style
Browse files Browse the repository at this point in the history
  • Loading branch information
merschformann committed Dec 16, 2024
1 parent 1730cc8 commit 5f7bc41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pydantic>=2.5.2
ruff>=0.1.7
twine>=4.0.2
hatch>=1.13.0
nextmv>=0.13.1
nextmv>=0.14.1
26 changes: 15 additions & 11 deletions src/tests/solve_golden/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This script is copied to the `src` root so that the `nextroute` import is
# resolved. It is fed an input via stdin and is meant to write the output to
# stdout.
from typing import Any, Dict

import nextmv

import nextroute
Expand All @@ -16,8 +14,8 @@ def main() -> None:
nextmv.Parameter("output", str, "", "Path to output file. Default is stdout.", False),
]

nextroute_options = nextroute.Options()
for name, default_value in nextroute_options.to_dict().items():
default_options = nextroute.Options()
for name, default_value in default_options.to_dict().items():
parameters.append(nextmv.Parameter(name.lower(), type(default_value), default_value, name, False))

options = nextmv.Options(*parameters)
Expand All @@ -28,18 +26,24 @@ def main() -> None:
nextmv.log(f" - stops: {len(input.data.get('stops', []))}")
nextmv.log(f" - vehicles: {len(input.data.get('vehicles', []))}")

output = solve(input, options)
model = DecisionModel()
output = model.solve(input)
nextmv.write_local(output, path=options.output)


def solve(input: nextmv.Input, options: nextmv.Options) -> Dict[str, Any]:
"""Solves the given problem and returns the solution."""
class DecisionModel(nextmv.Model):
def solve(self, input: nextmv.Input) -> nextmv.Output:
"""Solves the given problem and returns the solution."""

nextroute_input = nextroute.schema.Input.from_dict(input.data)
nextroute_options = nextroute.Options.extract_from_dict(options.to_dict())
nextroute_output = nextroute.solve(nextroute_input, nextroute_options)
nextroute_input = nextroute.schema.Input.from_dict(input.data)
nextroute_options = nextroute.Options.extract_from_dict(input.options.to_dict())
nextroute_output = nextroute.solve(nextroute_input, nextroute_options)

return nextroute_output.to_dict()
return nextmv.Output(
options=input.options,
solution=nextroute_output.solutions[0].to_dict(),
statistics=nextroute_output.statistics.to_dict(),
)


if __name__ == "__main__":
Expand Down

0 comments on commit 5f7bc41

Please sign in to comment.