Optaplanner:计划实体中的计划变量列表
我正在尝试使用optaplanner自动生成一个时间表,我想根据需要将多个合作者(计划变量)分配给单个活动(计划实体)。我想如果我可以将list
用作计划变量,我可以做到这一点。我发现了有关plannIstvariable
的信息,但无法弄清楚如何使用它,也找不到任何用例。
这就是我的使用方式:
@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.
I'm trying to generate a timetable automatically using OptaPlanner, I want to assign more than one collaborator(planning variable) to a single activity(planning entity) depending on a need. I guess I could do that if I could use a List
as planning variable. I found out about the PlanningListVariable
but can't figure out how to use it and can't find any use case with that.
This is how I used it:
@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;
...
}
And this is the error I get:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,不要使用
@planninglistvariable
,因为它会迫使合作者被分配给恰好一个活动。您可能不需要不同的列表语义。为每个活动创建一个类
ActiveSeat
。将其@planningentity与@planningvarion进行合作者。如果活动需要具有list&lt; activityseat&gt;
的a,事情变得更加复杂(@deepplanningclone,限制等),请尝试避免这种情况。哲学:不要将每件事分配给合作者列表(也不将每个合作者分配给事物),而是将事物中的每个开放座位分配给合作者。
请参阅“模型指南”的Optaplanner Docs章节设计模式。
Don't use a
@PlanningListVariable
for this, because it will force that a collaborator is assigned to exactly one activity. You probably don't want distinct-list semantics.Create a class
ActivitySeat
for each need per activity. Make that the @PlanningEntity with a @PlanningVariable to collaborator. If Activity needs to have a ofList<ActivitySeat>
, things get more complex (@DeepPlanningClone, constraints etc), so try to avoid that.Philosophy: don't assign each thing to a list of collaborators (nor assign each collaborator to a thing) but instead assign each open seat in the thing to a collaborator.
See OptaPlanner docs chapter design patterns for the modelling guide.