首页 > 解决方案 > optaplanner 矩阵基准测试失败原因:在行号 (40) 上对 benchmarkConfigResource 进行解组失败

问题描述

我之前成功地使用了没有基于模板的基准测试的基准,但是基于模板的基准测试在这里不能工作。我使用https://docs.optaplanner.org/中的测试用例

<plannerBenchmark>
  <benchmarkDirectory>local/data</benchmarkDirectory>
  <parallelBenchmarkCount>(availableProcessorCount / 2)+1</parallelBenchmarkCount>
  <warmUpSecondsSpentLimit>60</warmUpSecondsSpentLimit>
  <inheritedSolverBenchmark>
    ...
  </inheritedSolverBenchmark>

<#list [5, 7, 11, 13] as entityTabuSize>
<#list [500, 1000, 2000] as acceptedCountLimit>
  <solverBenchmark>
    <name>Tabu Search entityTabuSize ${entityTabuSize} acceptedCountLimit ${acceptedCountLimit}</name>
    <solver>
      <localSearch>
        <unionMoveSelector>
          <changeMoveSelector/>
          <swapMoveSelector/>
        </unionMoveSelector>
        <acceptor>
          <entityTabuSize>${entityTabuSize}</entityTabuSize>
        </acceptor>
        <forager>
          <acceptedCountLimit>${acceptedCountLimit}</acceptedCountLimit>
        </forager>
      </localSearch>
    </solver>
  </solverBenchmark>
</#list>
</#list>
</plannerBenchmark>

好像里面有问题

<#list [5, 7, 11, 13] as entityTabuSize>

optaPlanner 版本是 7.43.0 xstream 版本是 1.4.14

有一些错误信息

Caused by: com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : com.thoughtworks.xstream.io.StreamException
cause-message       : 
class               : org.optaplanner.benchmark.config.PlannerBenchmarkConfig
required-type       : org.optaplanner.benchmark.config.PlannerBenchmarkConfig
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : 40
version             : 1.4.14
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:77)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:72)
    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:1404)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1383)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1268)
    at org.optaplanner.benchmark.config.PlannerBenchmarkConfig.createFromXmlReader(PlannerBenchmarkConfig.java:228)
    at org.optaplanner.benchmark.config.PlannerBenchmarkConfig.createFromXmlInputStream(PlannerBenchmarkConfig.java:204)
    at org.optaplanner.benchmark.config.PlannerBenchmarkConfig.createFromXmlResource(PlannerBenchmarkConfig.java:140)
    ... 21 more
Caused by: com.thoughtworks.xstream.io.StreamException: 
    at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:135)
    at com.thoughtworks.xstream.io.xml.AbstractPullReader.hasMoreChildren(AbstractPullReader.java:87)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:329)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:277)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    ... 32 more
Caused by: org.xmlpull.v1.XmlPullParserException: unexpected character in markup # (position: END_TAG seen ...</inheritedSolverBenchmark>\r\n\r\n\r\n<#... @40:3) 
    at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1261)
    at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
    at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)
    ... 38 more

标签: optaplannerxstream

解决方案


根据堆栈跟踪,您使用的是PlannerBenchmarkConfig.createFromXmlResource(),可用于读取基准配置 XML,但不能用于读取 FreeMarker 模板。要阅读基准配置 FreeMarker 模板,请使用其中一种PlannerBenchmarkConfig.createFromFreemarkerXmlResource()方法。有关更多详细信息,请参阅基于模板的基准测试


推荐阅读