当前位置: 首页 > 知识库问答 >
问题:

两个计划实体类的求解器配置问题

暴阳州
2023-03-14

我正在研究一个问题的解决方案,这个问题与optaplanner中的护士名册示例很接近。

似乎都不起作用,我总是遇到这种例外

Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of solverConfigResource (org/optaplanner/examples/nurserostering/solver/nurseRosteringSolverConfig.xml) fails.

以下是我一直尝试使用的配置:

配置1:

在此配置中,默认的移动选择器用于本地搜索中的规划实体shift assignment类,并且为规划实体类“EmployeeSkillRequirement”添加了移动选择器,所有的东西都在a中组合,构造启发式用合并到的移动选择器替换。

<?xml version="1.0" encoding="UTF-8"?>
<solver>
<!--<environmentMode>FAST_ASSERT</environmentMode> -->
<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster
</solutionClass>
<entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
</entityClass>
<entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
</entityClass>
<scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
    <scoreDrl>org/optaplanner/examples/nurserostering/solver/nurseRosteringScoreRules.drl
    </scoreDrl>
</scoreDirectorFactory>

<termination>
    <!-- Official benchmark secondsSpentLimit allowed on: - ge0ffrey's main 
        pc: sprint 11, medium 700, long 42000 -->
    <secondsSpentLimit>700</secondsSpentLimit>
    <!--<bestScoreLimit>-0hard/-999999soft</bestScoreLimit> -->
</termination>
<constructionHeuristic>
    <queuedEntityPlacer>
        <unionMoveSelector>
            <changeMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </changeMoveSelector>
            <swapMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </swapMoveSelector>
            <changeMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <variableName>employee</variableName>
                </valueSelector>
            </changeMoveSelector>
            <swapMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <variableName>employee</variableName>
                </valueSelector>
            </swapMoveSelector>
        </unionMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>
<localSearch>
    <unionMoveSelector>

        <!-- Move Selectors for ShiftAssignment this was the default configuration 
            from the example -->
        <moveListFactory>
            <cacheType>PHASE</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.EmployeeChangeMoveFactory
            </moveListFactoryClass>
        </moveListFactory>
        <moveListFactory>
            <cacheType>PHASE</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentSwapMoveFactory
            </moveListFactoryClass>
        </moveListFactory>
        <moveListFactory>
            <cacheType>STEP</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentPillarPartSwapMoveFactory
            </moveListFactoryClass>
        </moveListFactory>


        <!-- The move selectors for the second plannig entity class EmployeeSkillRequirement -->
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>employee</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </entityClass>
            </entitySelector>
            <valueSelector>
                <variableName>employee</variableName>
            </valueSelector>
        </swapMoveSelector>
    </unionMoveSelector>
    <acceptor>
        <entityTabuSize>7</entityTabuSize>
    </acceptor>
    <forager>
        <acceptedCountLimit>800</acceptedCountLimit>
    </forager>
</localSearch>

配置2:

其次,我查看了文档,发现了这样的提示:如果每个规划实体类都有两个不同的构造启发部分,那么处理多个规划实体类会更容易一些http://docs.jboss.org/optaplanner/release/6.3.0.final/optaplanner-docs/html_single/index.html#AllocateEntityFromQueueEmultipleEntityClasss,所以我也尝试了这种配置

<?xml version="1.0" encoding="UTF-8"?>
<solver>
<!--<environmentMode>FAST_ASSERT</environmentMode> -->
<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster
</solutionClass>
<entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
</entityClass>
<entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
</entityClass>
<scoreDirectorFactory>
    <scoreDefinitionType>HARD_SOFT</scoreDefinitionType>
    <scoreDrl>org/optaplanner/examples/nurserostering/solver/nurseRosteringScoreRules.drl
    </scoreDrl>
</scoreDirectorFactory>

<termination>
    <!-- Official benchmark secondsSpentLimit allowed on: - ge0ffrey's main 
        pc: sprint 11, medium 700, long 42000 -->
    <secondsSpentLimit>700</secondsSpentLimit>
    <!--<bestScoreLimit>-0hard/-999999soft</bestScoreLimit> -->
</termination>
<constructionHeuristic>
    <queuedEntityPlacer>
        <unionMoveSelector>
            <changeMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </changeMoveSelector>
            <swapMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </swapMoveSelector>
        </unionMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>
<constructionHeuristic>
    <queuedEntityPlacer>
        <unionMoveSelector>
            <changeMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </changeMoveSelector>
            <swapMoveSelector>
                <entitySelector>
                    <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </entityClass>
                </entitySelector>
                <valueSelector>
                    <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                    </downcastEntityClass>
                    <variableName>employee</variableName>
                </valueSelector>
            </swapMoveSelector>
        </unionMoveSelector>
    </queuedEntityPlacer>
</constructionHeuristic>
<localSearch>
    <unionMoveSelector>

        <!-- Move Selectors for ShiftAssignment this was the default configuration 
            from the example -->
        <moveListFactory>
            <cacheType>PHASE</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.EmployeeChangeMoveFactory
            </moveListFactoryClass>
        </moveListFactory>
        <moveListFactory>
            <cacheType>PHASE</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentSwapMoveFactory
            </moveListFactoryClass>
        </moveListFactory>
        <moveListFactory>
            <cacheType>STEP</cacheType>
            <moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentPillarPartSwapMoveFactory
            </moveListFactoryClass>
        </moveListFactory>
        <!-- besides this default configuration from optaplaner i also tried this here

        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.
                </entityClass>
            </entitySelector>
            <valueSelector>
                <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                </downcastEntityClass>
                <variableName>employee</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                </entityClass>
            </entitySelector>
            <valueSelector>
                <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.ShiftAssignment
                </downcastEntityClass>
                <variableName>employee</variableName>
            </valueSelector>
        </swapMoveSelector>-->


        <!-- The move selectors for the second plannig entity class EmployeeSkillRequirement -->
        <changeMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </entityClass>
            </entitySelector>
            <valueSelector>
                <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </downcastEntityClass>
                <variableName>employee</variableName>
            </valueSelector>
        </changeMoveSelector>
        <swapMoveSelector>
            <entitySelector>
                <entityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </entityClass>
            </entitySelector>
            <valueSelector>
                <downcastEntityClass>org.optaplanner.examples.nurserostering.domain.EmployeeSkillRequirement
                </downcastEntityClass>
                <variableName>employee</variableName>
            </valueSelector>
        </swapMoveSelector>
    </unionMoveSelector>
    <acceptor>
        <entityTabuSize>7</entityTabuSize>
    </acceptor>
    <forager>
        <acceptedCountLimit>800</acceptedCountLimit>
    </forager>
</localSearch>

我也尝试了一些其他的配置,与这些类似,仍然,没有运气。

我怎样才能修好它并使它正常工作呢?

编辑:

Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of solverConfigResource (org/optaplanner/examples/nurserostering/solver/nurseRosteringSolverConfig.xml) fails.
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.configure(XStreamXmlSolverFactory.java:114)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:66)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.createSolver(NurseRosteringApp.java:50)
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:90)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:77)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:73)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.main(NurseRosteringApp.java:38)
Caused by: " com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field   org.optaplanner.core.config.heuristic.selector.move.generic.SwapMoveSelectorConfig.valueSelector
---- Debugging information ----
field               : valueSelector
class               :      org.optaplanner.core.config.heuristic.selector.move.generic.SwapMoveSelect    orConfig
required-type       :     org.optaplanner.core.config.heuristic.selector.move.generic.SwapMoveSelect    orConfig
converter-type      :    com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : 98
class[1]            :       org.optaplanner.core.config.heuristic.selector.move.composite.UnionMoveSel    ectorConfig
class[2]            :    org.optaplanner.core.config.localsearch.LocalSearchPhaseConfig
class[3]            : org.optaplanner.core.config.solver.SolverConfig
version             : 1.4.7
-------------------------------
at org.optaplanner.core.impl.solver.XStreamXmlSolverFactory.configure(XStreamXmlSolverFactory.java:114)
at org.optaplanner.core.api.solver.SolverFactory.createFromXmlResource(SolverFactory.java:66)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.createSolver(NurseRosteringApp.java:50)
at org.optaplanner.examples.common.app.CommonApp.createSolutionBusiness(CommonApp.java:90)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:77)
at org.optaplanner.examples.common.app.CommonApp.init(CommonApp.java:73)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.main(NurseRosteringApp.java:38)

共有1个答案

仲孙子辰
2023-03-14

一个常见的错误是在classname属性中添加未被正确解析的空白。这将在解析期间失败:

<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster
</solutionClass>

但这将成功地进行解析:

<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster</solutionClass>
 类似资料:
  • 在Spring Hibernate XML配置中,我有 我知道SpringJava配置的等价物如下:LocalSessionFactoryBuilder(dataSource())。AddAnnotatedClass(Foo.class)。buildSessionFactory(); 我的问题是,如果我不使用LocalSessionFactoryBuilder类,而是使用HibernateJpaV

  • 我试图将规划实体和一个问题事实加入到约束流中,但我的IDE抛出了一个错误: 我的问题结构和运输问题很相似。我有节点和边,想要计算边的数量。 我的主要问题是: 和规划实体: 约束的代码为: 如果我尝试连接边与边,例如: 这不会出错。原因是,我尝试将节点连接到节点的Edge属性中的Edge中吗?有没有别的办法可以做我想做的事?

  • 我们计划使用液基作为我们的数据库脚本自动化工具,用于维护和应用 ddl 和 dml。 是否有任何库可以读取liquibase配置中定义的ddl并生成jpa实体java类?

  • 我有2个服务(都是在kotlin上的Spring引导)。将其命名为“客户机”和“服务器”,由于某些限制,我必须使用Kafka同步请求-应答模式。所以我尝试使用ReplyingKafkatemplate。我的问题是我需要为多个实体使用。意味着创建多个ReplyingKafkaTemplate,一个用于“foo”,第二个用于“bar”。因此,在我的代码中,我用setup创建了多个KafkaConfig

  • 本文向大家介绍JavaScript两种计时器的实例讲解,包括了JavaScript两种计时器的实例讲解的使用技巧和注意事项,需要的朋友参考一下 通过使用 JavaScript,我们有能力做到在一个设定的时间间隔之后来执行代码,而不是在函数被调用后立即执行。我们称之为计时事件。提供了两种计时器的方法如下: window.setInterval(); 这个方法就是在一个周期内反复执行一直到窗口关闭或者

  • 在Optaplanner中,是否可以在移动中(在分数计算之间)将相同的计划变量分配给不同的计划实体?例如,当客户 A 被分配到一个静止状态时,客户 B 也会被分配到同一个静止状态。感谢任何想法或意见。