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

jpyinterpreter - Java annotation support #14

Closed Christopher-Chianelli closed 3 months ago

Christopher-Chianelli commented 4 months ago

Currently, timefold.solver is doing a lot of extra work just to add annotations (see https://github.com/TimefoldAI/timefold-solver-python/blob/main/timefold-solver-python-core/src/main/java/ai/timefold/solver/python/PythonWrapperGenerator.java). Ideally, the entire class can be removed if jpyinterpreter allows adding annotations to fields and methods.

Python supports annotations via Annotated: https://docs.python.org/3/library/typing.html#typing.Annotated , so

class Entity:
    value: V | None

    def __init__(self):
        self.value = None

    @planning_variable(V)
    def get_value(self):
        return self.value

    def set_value(self, value):
        self.value = value

can be replaced with

class Entity:
    value: PlanningVariable(V | None)

    def __init__(self):
        self.value = None

(where PlanningVariable = lambda x: Annotated[x, JavaAnnotation(annotation_class=PlanningVariable.class)])

Christopher-Chianelli commented 3 months ago

Done by #23