Timefold SolverFactory.create() — неверная функция: ожидалось 2 аргумента, но получено 1Python

Программы на Python
Anonymous
Timefold SolverFactory.create() — неверная функция: ожидалось 2 аргумента, но получено 1

Сообщение Anonymous »

Я работаю с Timefold Solver и столкнулся со следующей ошибкой при попытке создать SolverFactory:

Traceback (самый последний вызов последним): File
"G:\PycharmProject\Timefold-training\tools\main.py", строка 62, в

solver_factory = SolverFactory.create( File "G:\PycharmProject\Timefold-training\ venv\lib\site-packages\timefold\solver_solver_factory.py",
строка 52, в create
delegate = JavaSolverFactory.create(solver_config) # noqa ValueError: Неверная функция: ожидалось 2 аргумента, но получено 1< /p>

Вот соответствующий код, в котором возникает ошибка:

Код: Выделить всё

solver_factory = SolverFactory.create(
SolverConfig(
solution_class=DeviceSchedule,
entity_class_list=[Device],
score_director_factory_config=ScoreDirectorFactoryConfig(
constraint_provider_function=define_constraints
),
termination_config=TerminationConfig(
spent_limit=Duration(seconds=60)
)
)
)
У меня есть следующие классы домена:

Код: Выделить всё

from dataclasses import dataclass, field
from typing import Annotated, Set, List
from timefold.solver.domain import PlanningId, planning_entity, planning_solution, PlanningVariable, \
PlanningEntityCollectionProperty, ProblemFactCollectionProperty, ValueRangeProvider, PlanningScore
from timefold.solver.score import HardSoftScore

@dataclass
class Technician:
id: Annotated[int, PlanningId]
name: str
rbh_do_zaplanowania: float
rbh_przydzielone: float
iums: Set[str]

def has_ium(self, ium: str) -> bool:
return ium in self.iums

@dataclass
class Device:
index: Annotated[int, PlanningId]
ium: str
nazwa: str
typ: str
nr_fabryczny: str
rbh_norma: float
dni_w_om: int
uzytkownik: str
technician: Annotated[Technician | None, PlanningVariable(allows_unassigned=True)] = field(default=None)

@dataclass
@planning_solution
class DeviceSchedule:
id: str
technician_list: Annotated[List[Technician], ProblemFactCollectionProperty, ValueRangeProvider]
device_list: Annotated[List[Device], PlanningEntityCollectionProperty]
score: Annotated[HardSoftScore, PlanningScore] = field(default=None)
А это мой файл ограничений.py:

Код: Выделить всё

from timefold.solver.score import constraint_provider, HardSoftScore, ConstraintFactory

@constraint_provider
def define_constraints(constraint_factory: ConstraintFactory):
return [
technician_capacity_hard(constraint_factory),
technician_skill_conflict(constraint_factory),
]

def technician_skill_conflict(constraint_factory: ConstraintFactory):
return (
constraint_factory.for_each(Device)
.filter(lambda device: device.technician is not None and not device.technician.has_ium(device.ium))
.penalize(HardSoftScore.ONE_HARD)
.as_constraint("Technician skill conflict")
)

def technician_capacity_hard(constraint_factory: ConstraintFactory):
return (
constraint_factory.for_each(Device)
.group_by(lambda device: device.technician, sum(lambda device: device.rbh_norma))
.filter(lambda technician, total_rbh_norma: total_rbh_norma > technician.rbh_do_zaplanowania)
.penalize(HardSoftScore.ONE_HARD, lambda technician, total_rbh_norma: total_rbh_norma - technician.rbh_do_zaplanowania)
.as_constraint("Technician capacity")
)
Я подозреваю, что проблема может быть связана с тем, как я использую SolverFactory.create() или с моей конфигурацией, но я не знаю, как ее решить. Я просмотрел документацию Timefold Solver, но не могу точно определить причину этой ошибки.
Кто-нибудь сталкивался с этой проблемой раньше или кто-нибудь знает, что может быть не так?< /п>

Подробнее здесь: https://stackoverflow.com/questions/790 ... ts-but-got

Вернуться в «Python»