VROOM-Project / pyvroom

Vehicle Routing Open-source Optimization Machine
BSD 2-Clause "Simplified" License
67 stars 14 forks source link

pydantic models for input and output? #39

Open hklarner opened 2 years ago

hklarner commented 2 years ago

Is there a place somewhere to keep pydantic models of vroom input and output? I need them anyways so I thought I could share them. Looks something like this:

from pydantic import BaseModel

class Vehicle(BaseModel):
    id: int

    profile: Optional[str] = None
    description: Optional[str] = None
    start_index: Optional[int] = None
    end_index: Optional[int] = None
    capacity: Optional[Tuple[int]] = None
    skills: Optional[Tuple[int]] = None
    time_window: Optional[Tuple[int, int]] = None  # timestamp or relative seconds
    max_tasks: Optional[int] = None

class Matrix(BaseModel):
    durations: List[List[int]]

class Job(BaseModel):
    id: int
    location_index: int

    description: Optional[str] = None
    service: Optional[int] = None

class VroomRequest(BaseModel):
    vehicles: List[Vehicle]
    matrices: Dict[str, Matrix]
    jobs: List[Job]
jcoupey commented 2 years ago

This does not really belong in the core C++ repo, but we have a WIP repo with python bindings. Best would be to sync with @jonathf over there.

jonathf commented 2 years ago

Hello @hklarner,

I'm going to assume that the idea here is to do validation against the JSON input and output.

Specially for input, that would be quite useful, as it can give much better client side validation even if the execution is server side.

Not that it is a huge jub, but I haven't gotten around to porting JSON I/O to the Python interface. But when I do, adding something like this is a good idea.

I'll keep this issue open for when I get to to that task.

Related to: #5.

hklarner commented 2 years ago

Hi @jonathf yes, I use the input model for validation but I also use them for code completion in the IDE and as a schema. I am testing VROOM as a service inside an existing project so I have to generate the vroom input and also convert the vroom output into my own output.

hklarner commented 2 years ago

Eventually, of course, I can use pyvroom instead of having vroom-express running ..

jonathf commented 2 years ago

Yeah, sounds like you would benefit a lot from the python interface.