Drools Planner 在创建配置器时遇到问题:如何调试

发布于 2024-12-29 20:03:50 字数 2687 浏览 4 评论 0原文

我尝试从 XML 配置创建一个求解器。但整个过程会返回一条毫无意义的神秘错误消息。

我该如何解决这个问题?我怎样才能理解这一点以实际解决类似的问题?

jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java App 
Exception in thread "main" java.lang.NullPointerException
    at org.drools.planner.core.domain.solution.SolutionDescriptor.processPropertyAnnotations(SolutionDescriptor.java:69)
    at org.drools.planner.core.domain.solution.SolutionDescriptor.<init>(SolutionDescriptor.java:61)
    at org.drools.planner.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:197)
    at org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:167)
    at org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
    at App.createSolver(App.java:62)
    at App.main(App.java:40)

此处列出了抛出该异常的函数。该行当然是return configurer.buildSolver();

private static Solver createSolver(){
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
File file = new File("solver.xml");
FileInputStream fin = null;
try{
    fin = new FileInputStream(file);    
}
catch(IOException e){
     System.out.println("Unable to read drl");
}
configurer.configure(fin);
    //configurer.configure("/home/jesvin/dev/drools/sudoku/solver.xml");
    return configurer.buildSolver();
}

XML 的内容:

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <environmentMode>DEBUG</environmentMode>

  <solutionClass>domain.Sudoku</solutionClass>
  <planningEntityClass>domain.Digit</planningEntityClass>
  <scoreDrl>score.drl</scoreDrl>
  <scoreDefinition>
    <scoreDefinitionType>SIMPLE</scoreDefinitionType>
  </scoreDefinition>

  <termination>
    <scoreAttained>0</scoreAttained>
  </termination>
  <!--
  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
    <constructionHeuristicPickEarlyType>FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING</constructionHeuristicPickEarlyType>
</constructionHeuristic> -->
  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT</constructionHeuristicType>

      <moveFactoryClass>solution.RowChangeMoveFactory</moveFactoryClass>
    </selector>
    <acceptor>
      <completeSolutionTabuSize>1000</completeSolutionTabuSize>
    </acceptor>
    <forager>
      <!-- Real world problems require to use of <minimalAcceptedSelection> -->
    </forager>
  </localSearch>
</solver>

I tried to create a solver from XML configuration. But the entire process returns a cryptic error message that makes no sense.

How do I fix this? And how can I make sense of this to actually solve similar problems like this?

jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java App 
Exception in thread "main" java.lang.NullPointerException
    at org.drools.planner.core.domain.solution.SolutionDescriptor.processPropertyAnnotations(SolutionDescriptor.java:69)
    at org.drools.planner.core.domain.solution.SolutionDescriptor.<init>(SolutionDescriptor.java:61)
    at org.drools.planner.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:197)
    at org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:167)
    at org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
    at App.createSolver(App.java:62)
    at App.main(App.java:40)

The function that throws it is listed here. The line is of course return configurer.buildSolver();.

private static Solver createSolver(){
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
File file = new File("solver.xml");
FileInputStream fin = null;
try{
    fin = new FileInputStream(file);    
}
catch(IOException e){
     System.out.println("Unable to read drl");
}
configurer.configure(fin);
    //configurer.configure("/home/jesvin/dev/drools/sudoku/solver.xml");
    return configurer.buildSolver();
}

The content of the XML:

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <environmentMode>DEBUG</environmentMode>

  <solutionClass>domain.Sudoku</solutionClass>
  <planningEntityClass>domain.Digit</planningEntityClass>
  <scoreDrl>score.drl</scoreDrl>
  <scoreDefinition>
    <scoreDefinitionType>SIMPLE</scoreDefinitionType>
  </scoreDefinition>

  <termination>
    <scoreAttained>0</scoreAttained>
  </termination>
  <!--
  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
    <constructionHeuristicPickEarlyType>FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING</constructionHeuristicPickEarlyType>
</constructionHeuristic> -->
  <constructionHeuristic>
    <constructionHeuristicType>FIRST_FIT</constructionHeuristicType>

      <moveFactoryClass>solution.RowChangeMoveFactory</moveFactoryClass>
    </selector>
    <acceptor>
      <completeSolutionTabuSize>1000</completeSolutionTabuSize>
    </acceptor>
    <forager>
      <!-- Real world problems require to use of <minimalAcceptedSelection> -->
    </forager>
  </localSearch>
</solver>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

躲猫猫 2025-01-05 20:03:50

OP 的补充:

该问题与无意的只写属性有关。其中有 setBlockListgetBlocklist(getter 中的小“l”),这是一个拼写错误。 Drools 抱怨是因为它检测到两个属性,其中之一是只写的。

另一个不匹配是 isFixedsetFixed。它适用于内置的 boolean ,但不适用于 Boolean 对象。

我在 邮件列表帖子。

OP's addition:

The issue was related to an inadvertent write-only property. There was setBlockList and getBlocklist (small 'l' in the getter), which was a typo. Drools complained because it detected two properties, one of which was write-only.

The other mismatch was isFixed and setFixed. It works for boolean built-in, but not for Boolean object.

I solved the issue in a mailing list post.

寂寞清仓 2025-01-05 20:03:50

神秘错误消息在 5.4.0.Beta1(已发布)中得到修复:https://issues.jboss .org/browse/JBRULES-3247

Cryptic error message is fixed in 5.4.0.Beta1 (already released): https://issues.jboss.org/browse/JBRULES-3247

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文