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
27 stars 3 forks source link

feat: Support getters/setters for annotations #87

Open Christopher-Chianelli opened 2 weeks ago

Christopher-Chianelli commented 2 weeks ago

Is your feature request related to a problem? Please describe. See https://github.com/TimefoldAI/timefold-solver-python/issues/86

Describe the solution you'd like The ability to annotate a getter/setter function pair for annotations that require setting fields, like PlanningVariable or PlanningEntityCollection:

class MyEntity:
    entities: list[Entity]

    def get_entities(self) -> Annotated[list[Entity], PlanningEntityCollection]:
        return self.entities

    def set_entities(self, entities):
        self.entities = entities

Describe alternatives you've considered None

Additional context Useful for whoever is migrating from optapy.

Note that Java will check for method names "get..." and "set...", so we will need to generate two additional methods. However, attributes also generate getter and setter methods, so it should has a prefix to distinguish it from the attribute getter/setter.