实施用于基准化的SolutionIO接口 [英] Implementing a SolutionIO Interface for Benchmarking

查看:102
本文介绍了实施用于基准化的SolutionIO接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在项目中实现基准配置,无论我做什么,我似乎都遇到了某种错误.从文档中读了几遍之后,我发现我需要实现一个SolutionIO接口来读取输入并将其变成解决方案.

I'm trying to implement a benchmark configuration in my project, and whatever I do, I seem to encounter some sort of error. After a few reads from the Documentation I discovered that I need to implement a SolutionIO interface to read the input and make it into a solution.

这是我没有求解器的配置:

This is my configuration without the solver:

<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>标记处(请参阅文章结尾).

The error I'm getting is at the <problemIOClass> tag (see end of post).

这是我的CustomBenchmarkIO(Custom SolutionIO):

This is my 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);
}

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

And here I have a class that implements that interface:

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

}

}

我尝试使用类和接口,但是仍然遇到相同的错误.

I have tried using the class and the interface, but I still get the same error.

这是完整的错误日志:

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

我发布此问题是因为我不知道自己没有尝试过什么,因为我不知道实现基准的所有可能方式.

I'm posting this question because I don't know what I haven't tried, as I don't know all the possible ways of implementing a benchmark.

推荐答案

您需要从optaplanner本身实现一个称为

You need to implement an interface from optaplanner itself, called SolutionFileIO: you don't need to define your own interface. It's in the jar optaplanner-persistence-common these days.

这篇关于实施用于基准化的SolutionIO接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆