由于 <solver/> 元素命名空间不匹配,OptaPlanner 基准配置失败

OptaPlanner Benchmark config failing due to <solver/> element namespace mismatch

我正在尝试使用 OptaPlanner 基准测试模块。由于以下错误,我的基准配置文件被拒绝:

The <solver/> element belongs to a different namespace (https://www.optaplanner.org/xsd/benchmark) than expected (https://www.optaplanner.org/xsd/solver).

我从 the example in the docs 获取了配置的基础知识,并且我没有更改任何 xsd / xsi 链接等。该示例在 .我的 IDE 没有给我任何 xml 格式错误。

我已将文件配对到我定义共享模型 类/分数定义的基本部分,它导致了同样的问题。

<?xml version="1.0" encoding="UTF-8"?>
<plannerBenchmark xmlns="https://www.optaplanner.org/xsd/benchmark" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="https://www.optaplanner.org/xsd/benchmark https://www.optaplanner.org/xsd/benchmark/benchmark.xsd">
<benchmarkDirectory>benchmarks</benchmarkDirectory>
<warmUpSecondsSpentLimit>30</warmUpSecondsSpentLimit>

<inheritedSolverBenchmark>
    <solver>
        <solutionClass>my.package.SchedulingSolution</solutionClass>
        <entityClass>my.package.ISchedulable</entityClass>
        <entityClass>my.package.Booking</entityClass>
<scoreDirectorFactory><constraintProviderClass>my.package.SchedulingConstraintProvider</constraintProviderClass></scoreDirectorFactory>
    </solver>
</inheritedSolverBenchmark>

我在 main 方法中使用 var benchmarkFactory = PlannerBenchmarkFactory.createFromSolverConfigXmlResource("config-benchmark.xml"); 调用它。

我是不是做错了什么?

我认为您将 benchmark-config.xml 传递给了错误的方法; createFromSolverConfigXmlResource 期望 solver-config.xml。它根据现有求解器配置创建基本基准。

事实上,求解器配置是基准配置的一个子集,但它们有一个单独的 XML 命名空间。

请看一下方法 createFromXmlResource,它需要 benchmark-config.xml