为基准测试实施SolutionIO接口

时间:2016-05-25 18:56:17

标签: java optaplanner

我试图在我的项目中实现基准配置,无论我做什么,我似乎遇到了某种错误。在从文档中读取一些内容后,我发现我需要实现一个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>标记(见帖子末尾)。

这是我的CustomBenchmarkIO(Custom SolutionIO):

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);
}

这里我有一个实现该接口的类:

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) {

}

}

我尝试过使用类和接口,但我仍然遇到同样的错误。

以下是完整的错误日志:

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

我发布这个问题是因为我不知道自己没有尝试过什么,因为我不了解实施基准测试的所有可能方法。

1 个答案:

答案 0 :(得分:1)

您需要从optaplanner本身实现一个名为SolutionFileIO的界面:您不需要定义自己的界面。它现在在optaplanner-persistence-common罐子里。