-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Description
Hi!
I was trying to solve a school timetabling problem using Optapy, but I got the following error:
solution = solver.solve(problem_to_solve)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/d-future/miniconda3/envs/Minerva/lib/python3.11/site-packages/optapy/optaplanner_api_wrappers.py",
line 416, in solve
wrapped_problem = PythonSolver.wrapProblem(object_class, problem)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
org.optaplanner.optapy.org.optaplanner.optapy.OptaPyException: org.optaplanner.optapy.OptaPyException:
A problem occurred when wrapping the python problem
(<jpype._jproxy.proxy.OptaPlannerSchedule object at 0x7ff372e86440>).
Maybe an annotation was passed an incorrect type (for example, @problem_fact_collection_property(str)
on a function that return a list of int).
I have reviewed the code multiple times to find an error like the one described in the msg but I did not succeed. Could you have a quick look at the code below to see if I am missing something? From the error msg, it seems to be something trivial, but it keeps eluding me :S
Thanks in advance!
@dataclass(frozen=True)
class Slot:
id: int
t0: datetime
tf: datetime
duration: timedelta = field(init=False)
def __post_init__(self):
object.__setattr__(self, "duration", self.tf - self.t0)
@problem_fact
class SlotFact:
def __init__(self, slot: Slot):
self.slot = slot
@planning_id
def get_id(self) -> int:
return self.slot.id
@property
def duration(self):
return self.slot.duration
@planning_entity
class AssignmentEntity:
def __init__(
self,
id: int,
teacher: OptaTeacher,
group: OptaGroup,
subject: Subject,
room: Classroom,
slot: Optional[SlotFact] = None,
) -> None:
self.id = id
self.teacher = teacher
self.group = group
self.subject = subject
self.room = room
self.slot = slot
@planning_id
def get_id(self):
return self.id
@planning_variable(SlotFact, ["SlotRange"])
def get_slot(self):
return self.slot
def set_slot(self, new_slot: SlotFact):
self.slot = new_slot
@planning_solution
class OptaPlannerSchedule:
def __init__(
self, slots: list[SlotFact], assignments: list[AssignmentEntity], score=None
):
self.slots = slots
self.assignments = assignments
self.score = score
@problem_fact_collection_property(SlotFact)
@value_range_provider("SlotRange")
def get_slots(self) -> list[SlotFact]:
return self.slots
@planning_entity_collection_property(AssignmentEntity)
def get_assignments(self) -> list[AssignmentEntity]:
return self.assignments
@planning_score(HardSoftScore)
def get_score(self):
return self.score
def set_score(self, score):
self.score = scoreMetadata
Metadata
Assignees
Labels
No labels