实现用于基准测试的 SolutionIO 接口
Implementing a SolutionIO Interface for Benchmarking
我正在尝试在我的项目中实施基准配置,但无论我做什么,我似乎都遇到了某种错误。在阅读了几次文档后,我发现我需要实现一个 SolutionIO
接口来读取输入并将其转化为解决方案。
这是我没有解算器的配置:
<benchmarkDirectory>local/data/nurserostering/folder</benchmarkDirectory>
<inheritedSolverBenchmark>
<problemBenchmarks>
----> <problemIOClass>org.optaplanner.examples.nurserostering.persistence.CustomBenchmarkIO</problemIOClass> <-----
<inputSolutionFile>data/nurserostering/import/importTest/Input0.xml</inputSolutionFile>
</problemBenchmarks>
我得到的错误是在 <problemIOClass>
标记处(见 post 的末尾)。
这是我的 CustomBenchmarkIO(自定义解决方案 IO):
package org.optaplanner.examples.nurserostering.persistence;
import java.io.File;
import org.optaplanner.core.api.domain.solution.Solution;
public interface CustomProblemIOInterface {
String getFileExtension();
Solution read(File inputSolutionFile);
void write(Solution solution, File outputSolutionFile);
}
这里我有一个实现该接口的 class:
package org.optaplanner.examples.nurserostering.persistence;
import java.io.File;
import org.optaplanner.core.api.domain.solution.Solution;
import org.optaplanner.persistence.common.api.domain.solution.SolutionFileIO;
public class CustomBenchmarkIOClass implements CustomProblemIOInterface{
public String getInputFileExtension() {
return null;
}
public String getOutputFileExtension() {
// TODO Auto-generated method stub
return null;
}
public Solution read(File inputSolutionFile) {
return null;
}
public void write(Object solution, File outputSolutionFile) {
}
}
我已经尝试使用 class 和界面,但我仍然遇到同样的错误。
这是完整的错误日志:
Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of benchmarkConfigResource (org/optaplanner/examples/nurserostering/benchmark/monetBenchmarkConfig.xml) fails.
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:105)
at org.optaplanner.benchmark.api.PlannerBenchmarkFactory.createFromXmlResource(PlannerBenchmarkFactory.java:46)
at org.optaplanner.examples.common.app.CommonBenchmarkApp$ArgOption.buildPlannerBenchmarkFactory(CommonBenchmarkApp.java:105)
at org.optaplanner.examples.common.app.CommonBenchmarkApp.buildAndBenchmark(CommonBenchmarkApp.java:66)
at org.optaplanner.examples.nurserostering.app.NurseRosteringBenchmarkApp.main(NurseRosteringBenchmarkApp.java:24)
Caused by: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.optaplanner.benchmark.config.ProblemBenchmarksConfig.problemIOClass
---- Debugging information ----
field : problemIOClass
class : org.optaplanner.benchmark.config.ProblemBenchmarksConfig
required-type : org.optaplanner.benchmark.config.ProblemBenchmarksConfig
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number : 6
class[1] : org.optaplanner.benchmark.config.SolverBenchmarkConfig
class[2] : org.optaplanner.benchmark.config.PlannerBenchmarkConfig
version : 1.4.7
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:495)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:351)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1169)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1040)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:133)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:123)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:103)
... 4 more
我post回答这个问题是因为我不知道我还没有尝试过什么,因为我不知道实施基准测试的所有可能方法。
您需要从 optaplanner 本身实现一个接口,称为 SolutionFileIO
:您不需要定义自己的接口。这些天它在罐子里 optaplanner-persistence-common
。
我正在尝试在我的项目中实施基准配置,但无论我做什么,我似乎都遇到了某种错误。在阅读了几次文档后,我发现我需要实现一个 SolutionIO
接口来读取输入并将其转化为解决方案。
这是我没有解算器的配置:
<benchmarkDirectory>local/data/nurserostering/folder</benchmarkDirectory>
<inheritedSolverBenchmark>
<problemBenchmarks>
----> <problemIOClass>org.optaplanner.examples.nurserostering.persistence.CustomBenchmarkIO</problemIOClass> <-----
<inputSolutionFile>data/nurserostering/import/importTest/Input0.xml</inputSolutionFile>
</problemBenchmarks>
我得到的错误是在 <problemIOClass>
标记处(见 post 的末尾)。
这是我的 CustomBenchmarkIO(自定义解决方案 IO):
package org.optaplanner.examples.nurserostering.persistence;
import java.io.File;
import org.optaplanner.core.api.domain.solution.Solution;
public interface CustomProblemIOInterface {
String getFileExtension();
Solution read(File inputSolutionFile);
void write(Solution solution, File outputSolutionFile);
}
这里我有一个实现该接口的 class:
package org.optaplanner.examples.nurserostering.persistence;
import java.io.File;
import org.optaplanner.core.api.domain.solution.Solution;
import org.optaplanner.persistence.common.api.domain.solution.SolutionFileIO;
public class CustomBenchmarkIOClass implements CustomProblemIOInterface{
public String getInputFileExtension() {
return null;
}
public String getOutputFileExtension() {
// TODO Auto-generated method stub
return null;
}
public Solution read(File inputSolutionFile) {
return null;
}
public void write(Object solution, File outputSolutionFile) {
}
}
我已经尝试使用 class 和界面,但我仍然遇到同样的错误。
这是完整的错误日志:
Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of benchmarkConfigResource (org/optaplanner/examples/nurserostering/benchmark/monetBenchmarkConfig.xml) fails.
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:105)
at org.optaplanner.benchmark.api.PlannerBenchmarkFactory.createFromXmlResource(PlannerBenchmarkFactory.java:46)
at org.optaplanner.examples.common.app.CommonBenchmarkApp$ArgOption.buildPlannerBenchmarkFactory(CommonBenchmarkApp.java:105)
at org.optaplanner.examples.common.app.CommonBenchmarkApp.buildAndBenchmark(CommonBenchmarkApp.java:66)
at org.optaplanner.examples.nurserostering.app.NurseRosteringBenchmarkApp.main(NurseRosteringBenchmarkApp.java:24)
Caused by: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.optaplanner.benchmark.config.ProblemBenchmarksConfig.problemIOClass
---- Debugging information ----
field : problemIOClass
class : org.optaplanner.benchmark.config.ProblemBenchmarksConfig
required-type : org.optaplanner.benchmark.config.ProblemBenchmarksConfig
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number : 6
class[1] : org.optaplanner.benchmark.config.SolverBenchmarkConfig
class[2] : org.optaplanner.benchmark.config.PlannerBenchmarkConfig
version : 1.4.7
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:495)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:351)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:474)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:406)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:257)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1185)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1169)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1040)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:133)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:123)
at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:103)
... 4 more
我post回答这个问题是因为我不知道我还没有尝试过什么,因为我不知道实施基准测试的所有可能方法。
您需要从 optaplanner 本身实现一个接口,称为 SolutionFileIO
:您不需要定义自己的接口。这些天它在罐子里 optaplanner-persistence-common
。