我正在尝试实现具有多个实体类的解决方案,但失败并显示以下错误消息:
未配置entityClass(空),并且因为 entityClassSet([class com.myspace.wla.JobA,class com.myspace.wla.JobB]),则无法自动推断
这是求解器配置:
<?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;
}
}
这是第一个计划实体(第二个相同,但名称不同):
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;
}
}
谢谢, 埃莱泽(Eliezer)
答案 0 :(得分:0)
配置中有问题的部分是<constructionHeuristic>
阶段。您需要使用advanced configuration,每种每种计划实体类型都运行一个构造启发式阶段。在您的情况下,它应类似于以下内容:
<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
。
也可以不使用entitySorterManner和valueSorterManner,在这种情况下,它们将默认为entitySorterManner=DECREASING_DIFFICULTY_IF_AVAILABLE
和valueSorterManner=INCREASING_STRENGTH_IF_AVAILABLE
。