如何修复分数DRL和kmodule.xml错误

时间:2019-06-21 09:57:11

标签: drools optaplanner

我想将optaplanner 7.23.0.Final嵌入我的项目中,以通过对其中一个示例进行一些修改来解决优化问题。我可以通过手动运行IntelliJ中的主类来运行所有示例,而不会出现问题。在下一步中,我尝试从我的实际项目中调用这样一个未经修改的示例主类。在这里,一些kie.conf服务已加载,我在分数DRL错误中运行,但我无法解决。请参阅下面的日志和错误。

我认为.drl文件没有错误,因为该示例在手动启动时运行。

我还假定求解器配置中的所有引用都设置正确,因为更改会立即导致错误。

在某些示例中,除“ Score DRL”方法外,还有“ EasyScore”方法。该错误绝对是指分数DRL,因为将分数计算方法更改为“ EasyScore”方法之一,优化过程就不会出错。但是,我希望使用DRL,因为它速度更快,并且已经可以用于我想要的示例。

似乎错误与“ kmodule.xml”链接。不幸的是,我没有这样的文件,但是看来解决示例不是必需的。

我尝试在pom文件中实现所有可能的“ optaplanner”,“ drools”和“ kie”依赖项,但错误仍然存​​在。

在我的项目中,我只是尝试使用以下主要方法调用optaplanner:

  public static void main(String[] args) {
        org.optaplanner.examples.nqueens.app.NQueensHelloWorld.main(args);
  }

在NQueensHelloWorld-Example的main方法中构建求解器时发生错误:

 SolverFactory<NQueens> solverFactory = SolverFactory.createFromXmlResource(
                "org/optaplanner/examples/nqueens/solver/nqueensSolverConfig.xml");
        Solver<NQueens> solver = solverFactory.buildSolver();

日志和错误:

2019-06-21 11:50:28,951 INFO  ServiceDiscoveryImpl.java:105 - Loading kie.conf from  jar:file:/C:/Users/s2932/.m2/repository/org/optaplanner/optaplanner-core/7.23.0.Final/optaplanner-core-7.23.0.Final.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2019-06-21 11:50:28,953 INFO  ServiceDiscoveryImpl.java:139 - Adding Service +org.optaplanner.core.impl.solver.kie.KieSolverAssemblerService

2019-06-21 11:50:28,953 INFO  ServiceDiscoveryImpl.java:105 - Loading kie.conf from  jar:file:/C:/Users/s2932/.m2/repository/org/drools/drools-decisiontables/7.23.0.Final/drools-decisiontables-7.23.0.Final.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2019-06-21 11:50:28,954 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.decisiontable.DecisionTableProviderImpl

2019-06-21 11:50:28,955 INFO  ServiceDiscoveryImpl.java:105 - Loading kie.conf from  jar:file:/C:/Users/s2932/.m2/repository/org/drools/drools-compiler/7.23.0.Final/drools-compiler-7.23.0.Final.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2019-06-21 11:50:28,960 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.compiler.kie.builder.impl.KieServicesImpl

2019-06-21 11:50:28,962 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl

2019-06-21 11:50:28,962 INFO  ServiceDiscoveryImpl.java:105 - Loading kie.conf from  jar:file:/C:/Users/s2932/.m2/repository/org/drools/drools-core/7.23.0.Final/drools-core-7.23.0.Final.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2019-06-21 11:50:28,963 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.core.io.impl.ResourceFactoryServiceImpl

2019-06-21 11:50:28,964 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.core.marshalling.impl.MarshallerProviderImpl

2019-06-21 11:50:28,965 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.drools.core.concurrent.ExecutorProviderImpl

2019-06-21 11:50:28,965 INFO  ServiceDiscoveryImpl.java:105 - Loading kie.conf from  jar:file:/C:/Users/s2932/.m2/repository/org/kie/kie-internal/7.23.0.Final/kie-internal-7.23.0.Final.jar!/META-INF/kie.conf in classloader sun.misc.Launcher$AppClassLoader@18b4aac2
2019-06-21 11:50:28,966 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.kie.internal.services.KieAssemblersImpl

2019-06-21 11:50:28,966 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.kie.internal.services.KieRuntimesImpl

2019-06-21 11:50:28,967 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.kie.internal.services.KieWeaversImpl

2019-06-21 11:50:28,967 INFO  ServiceDiscoveryImpl.java:139 - Adding Service org.kie.internal.services.KieBeliefsImpl

Exception in thread "main" java.lang.IllegalStateException: There are errors in a score DRL:
Error Messages:
Message [id=1, level=ERROR, path=kmodule.xml, line=0, column=0
   text=kmodule.xml found, but unable to read
]
---
Warning Messages:
---
Info Messages:

    at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:607)
    at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:410)
    at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:334)
    at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
    at org.optaplanner.examples.nqueens.app.NQueensHelloWorld.main(NQueensHelloWorld.java:33)
    at main.main(main.java:13)

1 个答案:

答案 0 :(得分:0)

如果在SolverFactory.create方法上使用“ Kiecontainer”替代方法(提示:几乎没有人这么做),或者在使用kie-server(某些情况下这样做),则仅在类路径中需要

kmodule.xml这个)。否则,最好不要将其完全放在类路径中。