繁体   English   中英

OptaPlanner:计划实体中的计划变量列表

[英]OptaPlanner: List of a planning variable in a planning entity

我正在尝试使用 OptaPlanner 自动生成时间表,我想根据需要将多个协作者(计划变量)分配给单个活动(计划实体)。 如果我可以使用List作为计划变量,我想我可以做到这一点。 我发现了PlanningListVariable ,但不知道如何使用它,也找不到任何用例。

这就是我使用它的方式:

@PlanningEntity
@Entity
@Table(name = "activity")
public class Activity implements Serializable {

    private static final long serialVersionUID = 1L;

    @PlanningId
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "activity_label")
    private String activityLabel;

//    @PlanningVariable(valueRangeProviderRefs = "locationRange")
    @PlanningListVariable(valueRangeProviderRefs = "locationRange")
    @JsonIgnoreProperties(value = { "resource", "typeOfLocation" }, allowSetters = true)
    @ManyToMany
    private List<Location> location;

    @PlanningListVariable(valueRangeProviderRefs = "collaboratorRange")
    @ManyToMany
    @JsonIgnoreProperties(value = { "resource", "typeOfCollaborator" }, allowSetters = true)
    private List<Collaborator> collaborator;

    @PlanningVariable(valueRangeProviderRefs = "equipmentRange")
    @ManyToOne
    @JsonIgnoreProperties(value = { "resource", "typeOfEquipment" }, allowSetters = true)
    private Equipment equipment;

    ...
}

这是我得到的错误:

15-06-2022 17:00:58.296 DEBUG [restartedMain  ] Identified candidate component class: file [C:\Users\Florent\PlanningGenSp\target\classes\com\planning\sp\domain\TimeTable.class]
15-06-2022 17:00:58.345 DEBUG [restartedMain  ] Identified candidate component class: file [C:\Users\Florent\PlanningGenSp\target\classes\com\planning\sp\domain\Activity.class]
15-06-2022 17:01:02.956  WARN [restartedMain  ] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'probl
emChangedRepositoryEventListener' defined in file [C:\Users\Florent\PlanningGenSp\target\classes\com\planning\sp\config\ProblemChangedRepositoryEventListener.class]: Unsatisfied dependency expressed through constructor parameter 0; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'timeTableResource' defined in file [C:\Users\Florent\PlanningGenSp\target\classes\com\planning\sp\web\rest\TimeTabl
eResource.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solverManager' defined in class path res
ource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org
.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalArgumentException: The config (ValueSelectorConfig(null)) has no configured variableName for entityClass (class com.planning.sp.domain.Activity) and because there are multiple variableNames ([collaborator, equipment, location, period]), it cannot be deduced automatically.
15-06-2022 17:01:03.092 ERROR [restartedMain  ] Application run failed
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'solverManager' defined in class path resource [org/optaplanner/spring/boot/autoconfigure/OptaPlannerAutoConfiguration.class]: Bean in
stantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; 
nested exception is java.lang.IllegalArgumentException: The config (ValueSelectorConfig(null)) has no configured variableName for entityClass (class com.planning.sp.domain.Activity) and because there are multiple variableNames ([collaborator, equipment, location, period]), it cannot be deduced automatically.

我想根据需要将多个协作者(计划变量)分配给单个活动(计划实体)。

不要为此使用@PlanningListVariable ,因为它会强制将协作者分配给一个活动。 您可能不想要不同的列表语义。

为每个活动的每个需要创建一个类ActivitySeat 使 @PlanningEntity 与 @PlanningVariable 成为合作者。 如果 Activity 需要一个List<ActivitySeat> ,事情会变得更加复杂(@DeepPlanningClone、约束等),所以尽量避免这种情况。

理念:不要将每个事物分配给协作者列表(也不将每个协作者分配给一个事物),而是将事物中的每个空缺席位分配给一个协作者。

有关建模指南,请参阅 OptaPlanner 文档章节设计模式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM