没有entityClass,因为entityClassSet里面有多个,所以不能自动推导出 [英] No entityClass, and because there are multiple in the entityClassSet, it can not be deduced automatically
问题描述
我正在尝试使用多个实体类实现解决方案,但失败并显示以下错误消息:
I'm trying to implement a solution with multiple entity classes, and it fails with the following error message:
没有配置 entityClass (null) 并且因为有多个entityClassSet ([class com.myspace.wla.JobA, classcom.myspace.wla.JobB]),不能自动推导
no entityClass (null) configured and because there are multiple in the entityClassSet ([class com.myspace.wla.JobA, class com.myspace.wla.JobB]), it can not be deduced automatically
这是求解器配置:
<?xml version="1.0" encoding="UTF-8"?>
<solver xStreamId="1">
<solutionClass>com.myspace.wla.AllocationSolution</solutionClass>
<entityClass>com.myspace.wla.JobA</entityClass>
<entityClass>com.myspace.wla.JobB</entityClass>
<scoreDirectorFactory xStreamId="3"/>
<termination xStreamId="4">
<millisecondsSpentLimit>0</millisecondsSpentLimit>
<secondsSpentLimit>30</secondsSpentLimit>
<minutesSpentLimit>0</minutesSpentLimit>
<hoursSpentLimit>0</hoursSpentLimit>
<daysSpentLimit>0</daysSpentLimit>
</termination>
<constructionHeuristic xStreamId="5">
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
<entitySorterManner>NONE</entitySorterManner>
</constructionHeuristic>
<localSearch xStreamId="6">
<unionMoveSelector>
<changeMoveSelector>
<entitySelector>
<entityClass>com.myspace.wla.JobA</entityClass>
</entitySelector>
<valueSelector>
<variableName>Computer</variableName>
<selectionOrder>SORTED</selectionOrder>
</valueSelector>
</changeMoveSelector>
<changeMoveSelector>
<entitySelector>
<entityClass>com.myspace.wla.JobB</entityClass>
</entitySelector>
<valueSelector>
<variableName>Computer</variableName>
<selectionOrder>SORTED</selectionOrder>
</valueSelector>
</changeMoveSelector>
</unionMoveSelector>
</localSearch>
</solver>
这是解决方案实体:
package com.myspace.wla;
import java.util.List;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
@PlanningSolution
@javax.xml.bind.annotation.XmlRootElement
@javax.xml.bind.annotation.XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
public class AllocationSolution implements java.io.Serializable {
static final long serialVersionUID = 1L;
@javax.annotation.Generated({"org.optaplanner.workbench.screens.domaineditor.client.widgets.planner.PlannerDataObjectEditor"})
@javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter(org.optaplanner.persistence.jaxb.api.score.buildin.hardsoft.HardSoftScoreJaxbXmlAdapter.class)
@org.kie.api.definition.type.Label("Generated Planner score field")
private org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore score;
private java.util.List<com.myspace.wla.Computer> computerList;
private java.util.List<com.myspace.wla.JobA> jobAList;
private int id;
private java.util.List<com.myspace.wla.JobB> jobBList;
public AllocationSolution() {
}
@PlanningScore
public org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore getScore() {
return this.score;
}
public void setScore(
org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore score) {
this.score = score;
}
@ValueRangeProvider(id = "computerRange")
@ProblemFactCollectionProperty
public java.util.List<com.myspace.wla.Computer> getComputerList() {
return this.computerList;
}
public void setComputerList(
List<com.myspace.wla.Computer> computerList) {
this.computerList = computerList;
}
@PlanningEntityCollectionProperty
@ValueRangeProvider(id = "jobARange")
public List<com.myspace.wla.JobA> getJobAList() {
return this.jobAList;
}
public void setJobAList(java.util.List<com.myspace.wla.JobA> jobAList) {
this.jobAList = jobAList;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@PlanningEntityCollectionProperty
@ValueRangeProvider(id = "jobBRange")
public List<com.myspace.wla.JobB> getJobBList() {
return this.jobBList;
}
public void setJobBList(java.util.List<com.myspace.wla.JobB> jobBList) {
this.jobBList = jobBList;
}
public AllocationSolution(
org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore score,
java.util.List<com.myspace.wla.Computer> computerList,
java.util.List<com.myspace.wla.JobA> jobAList, int id,
java.util.List<com.myspace.wla.JobB> jobBList) {
this.score = score;
this.computerList = computerList;
this.jobAList = jobAList;
this.id = id;
this.jobBList = jobBList;
}
}
这是事实实体:
package com.myspace.wla;
public class Computer implements java.io.Serializable {
static final long serialVersionUID = 1L;
private int id;
private int color;
public Computer() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public int getColor() {
return this.color;
}
public void setColor(int color) {
this.color = color;
}
public Computer(int id, int color) {
this.id = id;
this.color = color;
}
}
这是第一个规划实体(第二个相同但名称不同):
This is the first planning entity (the second one is identical with a different name):
package com.myspace.wla;
import org.optaplanner.core.api.domain.solution.drools.ProblemFactCollectionProperty;
import org.optaplanner.core.api.domain.entity.PlanningEntity;
import org.optaplanner.core.api.domain.variable.PlanningVariable;
@PlanningEntity
public class JobA implements java.io.Serializable {
static final long serialVersionUID = 1L;
private int id;
private com.myspace.wla.Computer computer;
private int color;
public JobA() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
@PlanningVariable(valueRangeProviderRefs = {"computerRange"})
public com.myspace.wla.Computer getComputer() {
return this.computer;
}
public void setComputer(com.myspace.wla.Computer computer) {
this.computer = computer;
}
public int getColor() {
return this.color;
}
public void setColor(int color) {
this.color = color;
}
public JobA(int id, com.myspace.wla.Computer computer, int color) {
this.id = id;
this.computer = computer;
this.color = color;
}
}
谢谢,埃利泽
推荐答案
配置中有问题的部分是
阶段.您需要使用 高级配置,运行一个构造启发式每个规划实体类型的阶段.在您的情况下,它应该类似于:
The problematic part of the configuration is the <constructionHeuristic>
phase. You need to use an advanced configuration, that runs one Construction Heuristic phase per each planning entity type. In your case, it should look similar to this:
<constructionHeuristic>
<entitySorterManner>NONE</entitySorterManner>
<valueSorterManner>NONE</valueSorterManner>
<queuedEntityPlacer>
<entitySelector id="jobAEntitySelector">
<cacheType>PHASE</cacheType>
<entityClass>com.myspace.wla.JobA</entityClass>
</entitySelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="jobAEntitySelector"/>
</changeMoveSelector>
</queuedEntityPlacer>
</constructionHeuristic>
<constructionHeuristic>
<entitySorterManner>NONE</entitySorterManner>
<valueSorterManner>NONE</valueSorterManner>
<queuedEntityPlacer>
<entitySelector id="jobBEntitySelector">
<cacheType>PHASE</cacheType>
<entityClass>com.myspace.wla.JobB</entityClass>
</entitySelector>
<changeMoveSelector>
<entitySelector mimicSelectorRef="jobBEntitySelector"/>
</changeMoveSelector>
</queuedEntityPlacer>
</constructionHeuristic>
请注意,不能将 constructionHeuristicType=FIRST_FIT
与高级配置一起使用,但使用 entitySorterManner=NONE
和 valueSorterManner=NONE
等效于 FIRST_FIT
.
Note that it's not possible to use constructionHeuristicType=FIRST_FIT
with advanced configuration but using entitySorterManner=NONE
and valueSorterManner=NONE
is equivalent to FIRST_FIT
.
也可以不使用 entitySorterManner 和 valueSorterManner,在这种情况下,它们将默认为 entitySorterManner=DECREASING_DIFFICULTY_IF_AVAILABLE
和 valueSorterManner=INCREASING_STRENGTH_IF_AVAILABLE
.
It's also possible to leave entitySorterManner and valueSorterManner out, in which case they'll default to entitySorterManner=DECREASING_DIFFICULTY_IF_AVAILABLE
and valueSorterManner=INCREASING_STRENGTH_IF_AVAILABLE
.
这篇关于没有entityClass,因为entityClassSet里面有多个,所以不能自动推导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!