Skip to content
Advertisement

Optapy error at “solver_manager_create(solver_config)”

I am trying to run solver_manager_create method as it shown in the quick start code in optapy repo (https://github.com/optapy/optapy-quickstarts/blob/04fd102ee31919cacc4145d0517fe07b2627ca02/employee-scheduling/services.py#L168)

SINGLETON_ID = 1
solver_config = optapy.config.solver.SolverConfig()
solver_config
    .withSolutionClass(EmployeeSchedule)
    .withEntityClasses(Shift)
    .withConstraintProviderClass(employee_scheduling_constraints)
    .withTerminationSpentLimit(Duration.ofSeconds(60))

#error occurs in this line
solver_manager = solver_manager_create(solver_config)

But i am receiving a java.lang.IllegalArgumentException error.

Full Error:

java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Cannot use class (org.optaplanner.optapy.generated.class6.domain.Shift.GeneratedClass) in a constraint stream as it is neither the same as, nor a superclass or superinterface of one of planning entities or problem facts.
Ensure that all from(), join(), ifExists() and ifNotExists() building blocks only reference classes assignable from planning entities or problem facts ([org.optaplanner.optapy.generated.class0.shift_planning.domain.Employee.GeneratedClass, org.optaplanner.optapy.generated.class1.shift_planning.domain.ConstraintForTag.GeneratedClass, org.optaplanner.optapy.generated.class2.shift_planning.domain.Shift.GeneratedClass]) annotated on the planning solution (org.optaplanner.optapy.generated.class3.shift_planning.domain.EmployeeSchedule.GeneratedClass).

what am i missing?

Advertisement

Answer

From the error message, it appears the constraint stream use one version of Shift, and the domain model use a DIFFERENT version of Shift. Do not redefine or define multiple versions of entity classes/problem fact classes: they will be considered distinct from one another. Note ...domain.Shift... (the one used by Constraint Streams) is different from ...shift_planning.domain.Shift... (the one used by the domain). Either use domain.Shift in your Constraint Stream or use shift_planning.domain.Shift in your domain.

Advertisement