I get the error:
TypeError: '>' not supported between instances of 'ai.timefold.jpyinterpreter.types.datetime.PythonDate' and 'datetime.date'
When using this constraint:
def teacher_soft(constraint_factory: ConstraintFactory):
return constraint_factory.for_each(Exam) \
.filter(
lambda e:
e.teacher != None and
e.timeslot and (
_search("Doe",exam.teacher)!=None and (
exam.timeslot.start_time.date() > datetime.date(2025,2,10)
)
-- ...
Where e
is part of the PlanningEntity
.
I had a similar error with str comparisons, which I could resolve by enforcing str(x)
on PythonString
, however, this seems to be more complicated.
How can I get this constraint to work without resorting to desperate measures, like, e.g., creating my own PythonDateTimeSet
class?
The domain structures are basically defined as follows:
class Timeslot:
id : Annotated[int, PlanningId]
start_time : datetime.datetime
end_time : datetime.datetime
grain:datetime.timedelta = datetime.timedelta(hours=2)
time_max=datetime.time.max
...
@planning_entity
class Exam:
id: Annotated[int,PlanningId]
subject: str
teacher: str
participants: int
pinned : Annotated[bool, PlanningPin]
timeslot : Annotated[Timeslot | None,
PlanningVariable]
This is the code that is ported from OptaPy
. However, the Java-Python layer seems to have changed substantially with Timefold
.