我正在研究一个与optaplanner中的Nurse Rostering示例相近的问题的解决方案。
员工被分配到护士名册中的轮班,但主要区别在于,技能要求(作业)最后可以说20分钟。如果员工被分配到涵盖给定技能要求时间的班次,则可以将员工分配到技能要求。假设我们从12点到12点20分对Skill1有一项技能要求,并且员工从08:00到16:00被分配,那么只有具备该技能才能将他分配到该技能要求。 / p>
我有2个计划实体类。示例中的默认移位分配,我已经实现了另外两个类SkillRequirement类,它将在给定的时间范围内保持一个技能要求(这将是一个计划事实),第二个计划实体类将在Employee和SkillRequirement类及其名称为EmployeeSkillRequirement。
到现在为止,我认为我做了一切,我注释了EmployeeSkillRequirement 作为@PlanningEntity的类和具有适当值范围的计划变量,在计划解决方案中,我添加了技能要求列表(这些是事实,也可以用于工作内存)以及有关技能要求的员工列表实体并使用@PlanningEntitySolutionProperty正确注释
我很难配置求解器,我尝试了很多不同的求解器配置,我在文档中读到,当有更多的规划实体和/或规划变量时,应该使用移动选择器的并集。你告诉OptaPlanner计划实体类和计划变量的名称,因为默认情况下它无法找到它。
似乎没有用,我一直得到这个例外
Exception in thread "main" java.lang.IllegalArgumentException: Unmarshalling of solverConfigResource (org/optaplanner/examples/nurserostering/solver/nurseRosteringSolverConfig.xml) fails.
以下是配置i'一直试图使用:
配置1:
在此配置中,默认移动选择器用于 规划实体转移分配类在本地搜索和移动 选择 为计划实体类添加 " EmployeeSkillRequirement"一切都结合在了一起 并且将构造启发式替换为移动选择器组合在一个联合中。
<?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#allocateEntityFromQueueMultipleEntityClasses 所以我也尝试了这个配置。
<?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)
答案 0 :(得分:3)
常见的错误是在classname属性中添加空格,而这些空格无法正确解析。解析期间失败:
<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster
</solutionClass>
但是成功解析了这个:
<solutionClass>org.optaplanner.examples.nurserostering.domain.NurseRoster</solutionClass>