目前我正在OptaPlanner实施我的第二个项目。我正在检索以下错误:
Exception in thread "main" java.lang.IllegalArgumentException:
A planning entity is an instance of a entitySubclass (class com.company.Assignment)
that is not configured as a planning entity.
If that class (Assignment) (or superclass thereof) is not a entityClass
([class com.company.Car]), check your Solution implementation's annotated methods.
If it is, check your solver configuration.
我的SolverConfig.xml是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<solutionClass>com.company.Planning</solutionClass>
<entityClass>com.company.Car</entityClass>
<scoreDirectorFactory>
<scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
<easyScoreCalculatorClass>com.company.PlanningEasyScoreCalculator</easyScoreCalculatorClass>
<initializingScoreTrend>ONLY_DOWN</initializingScoreTrend>
</scoreDirectorFactory>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<termination>
<secondsSpentLimit>10</secondsSpentLimit>
</termination>
<changeMoveSelector>
<entitySelector>
<entityClass>com.company.Car</entityClass>
</entitySelector>
<valueSelector>
<variableName>assignment</variableName>
</valueSelector>
</changeMoveSelector>
<acceptor>
<entityTabuSize>7</entityTabuSize>
</acceptor>
<forager>
<acceptedCountLimit>1000</acceptedCountLimit>
</forager>
</localSearch>
</solver>
“Car”类注释为“@PlanningEntity”。 “Planning”类使用“@PlanningSolution”注释。 Tha“Assignment”课程是我的问题。 解决方案的“@PlanningEntityCollectionProperty”位于运行“Car”列表的getter上。
“Main”类如下所示:
public class Main {
public static final String SOLVER_CONFIG_XML = "com/company/PlanningSolverConfig.xml";
public static ScoreDirector scoreDirector;
public static void main(String[] args) {
// Read data from XLS file and initialize the problem
ReadDataFromXls Reader = new ReadDataFromXls();
Planning planningSituation = new Planning(Reader.ReadAssignments(),Reader.ReadCars());
// Build the solver
Solver solver = SolverFactory.createFromXmlResource(SOLVER_CONFIG_XML).buildSolver();
// Solve the problem and get the best solution
solver.solve(planningSituation);
Planning solvedPlanning = (Planning) solver.getBestSolution();
// Display the result
System.out.println("TODO");
}
}
6.3.0.CR1
的错误消息基本相同+有关SLF4J
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalArgumentException: A planning entity is an instance of an entitySubclass (class com.company.Assignment) that is not configured as a planning entity.
If that class (Assignment) (or superclass thereof) is not a entityClass ([class com.company.Car]), check your Solution implementation's annotated methods.
If it is, check your solver configuration.
编辑:我在OptaPlanner的第一个项目是“一对多”问题(项目有开发人员,开发人员可以有多个项目)。这个项目是一对一的问题(开车到一个任务需要一辆车,一辆汽车可以完成一项任务)。
编辑:我改变了计划问题的模型。现在,“作业”课程是我的“计划实体”,而“汽车”课程则是“计划事实”。错误信息仍然是相同的,除了“Car”和“Assignment”切换位置的事实:)
答案 0 :(得分:0)
我敢打赌,解决方案的@PlanningEntityCollectionProperty
位于运行Assignment
集合(在您的情况下不是实体)而不是Car
的getter上(这是实体)。
但是,类命名令人困惑。我会将课程Assignment
重命名为Task
,将课程Car
重命名为CarAssignment
,因为任何名称分配通常都是规划实体......
答案 1 :(得分:0)
必须以某种方式对您的域名模型进行错误配置。
你完全正确!我打电话给这个构造函数:
public Planning(List<Car> carList, List<Assignment> assignmentList) {
this.carList = carList;
this.assignmentList = assignmentList;
}
有了这个论点:
Planning planningSituation = new Planning(Reader.ReadAssignments(),Reader.ReadCars());
感谢您的帮助!