TimefoldAI / timefold-solver-python

Timefold Solver is an AI constraint solver for Python to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling, Bin Packing and many more planning problems.
https://timefold.ai
Apache License 2.0
36 stars 3 forks source link

README uses value_range_provider_refs #22

Closed ge0ffrey closed 6 months ago

ge0ffrey commented 6 months ago

Are value range provider refs still needed? In Java, by default they are not if there is no ambiguity.

From the readme: @planning_variable(Timeslot, value_range_provider_refs=["timeslotRange"])

Christopher-Chianelli commented 6 months ago

There will be a completely new syntax soon, using typing.Annotated that is used in Python libraries like Pydantic (https://docs.pydantic.dev/latest/api/standard_library_types/#decimaldecimal) and FastAPI (https://fastapi.tiangolo.com/tutorial/dependencies/?h=annotated#first-steps):

@timefold.solver.planning_entity
@dataclass
class Entity:
    code: Annotated[str, timefold.solver.PlanningId]
    value: Annotated[Value, timefold.solver.PlanningVariable] = field(default=None)

(dataclass is a Python builtin decorator that adds equality, constructor, etc.; this is equivalent to):

@timefold.solver.planning_entity
class Entity:
    code: Annotated[str, timefold.solver.PlanningId]
    value: Annotated[Value, timefold.solver.PlanningVariable]

    def __init__(self, code: str, value: Value = None):
        self.code = code
        self.value = value

    # also defines __str__, __hash__, __eq__, etc.
    ...
Christopher-Chianelli commented 6 months ago

(PlanningVariable, PlanningId, etc. become classes, and hence PascalCase; planning_entity is still a decorator (since you cannot apply Annotated to a class), and thus a function, and thus snake_case)

Christopher-Chianelli commented 6 months ago

(the timefold.solver prefix can be removed if you do from timefold.solver import ...)

triceo commented 6 months ago

@Christopher-Chianelli I think that Geoffrey's point is that the value range ref is not necessary. A while ago I added a feature that - if there is only one value range - that it is automatically matched.

It's not a matter of syntax; the ref simply shouldn't have to be there.

Christopher-Chianelli commented 6 months ago

Yes, but the syntax in the README will be completely changed. That is, it won't be @planning_variable(Timeslot), (the old decorator with the parameter made optional) but Annotated[Timeslot, PlanningVariable] (new Python Annotated syntax). This issue (along with other annotation changes such as removal of CustomShadowVariable (replaced with ShadowVariable and PiggyBackShadowVariable) and nullable -> allows_unassigned) will be fixed in the Annotated refactor.

Christopher-Chianelli commented 6 months ago

Done by #23