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

feat: Allow jpyinterpreter to create annotations on classes, fields and methods #21

Closed Christopher-Chianelli closed 6 months ago

Christopher-Chianelli commented 6 months ago

Part 1 of #14. This gives jpyinterpreter the ability to directly add Java annotations to the generated fields/methods/classes with the use of Annotated (see https://docs.python.org/3/library/typing.html#typing.Annotated).

Part 2 of #14 would be a complete do-over of timefold-solver-python-core that removes the majority of its java class generation code (most of which is just adding annotations) and change its API to use Annotations:

@planning_entity
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

becomes

@planning_entity
@dataclass
class Entity:
    value: PlanningVariable(V)

or

@planning_entity
@dataclass
class Entity:
    value: Annotated[V, PlanningVariable()]
Christopher-Chianelli commented 6 months ago

Example from Django: https://docs.djangoproject.com/en/5.0/topics/db/models/#quick-example ; it important to note: here PlanningVariable acts as a type (hence PascalCase), where before it acts as a function (hence snake_case).

Christopher-Chianelli commented 6 months ago

Example from Pydantic: https://docs.pydantic.dev/latest/api/standard_library_types/#decimaldecimal

Christopher-Chianelli commented 6 months ago

Example from FastAPI: https://fastapi.tiangolo.com/tutorial/dependencies/?h=annotated#first-steps