0

目前,我有 30 个轮班和 25 名员工的名册。这 25 名员工将轮班开始和结束时间与员工可用性相匹配。尽管如此,Opta 只分配了 19 个班次,而将所有其他班次留空,并且不分配剩余的 6 名员工。

我的假设是,它应该分配所有 25 名员工,因为他们的时间与班次相匹配。我在这里错过了什么还是应该看看其他方面?

以下是我的 Opta 规则文件,我已删除所有其他规则,因为它们在我的情况下不是必需的。

Opta 员工排班版本目前使用 7.28.0-SNAPSHOT 时间给定名册解决 240 秒。

// ############################################################################
// Hard constraints
// ############################################################################

rule "Unavailable time slot for an employee"
    when
        EmployeeAvailability(
                $e : employee,
                $employeeName : employee.getName(),
                $startDateTime : startDateTime,
                $endDateTime : endDateTime)
        Shift(
                employee == $e,
                !DateTimeUtils.doTimeslotsMatch($startDateTime,$endDateTime, startDateTime, endDateTime, $employeeName))
    then
        scoreHolder.addHardConstraintMatch(kcontext, -100);
end

rule "No overlapping shifts for an employee"
    when
        $s : Shift( employee != null,
                    $e : employee,
                    $employeeName : employee.getName(),
                    $firstStartDateTime: startDateTime,
                    $firstEndDateTime : endDateTime)
        $s2: Shift( employee == $e,
                    this != $s,
                    DateTimeUtils.doTimeslotsMatch($firstStartDateTime,$firstEndDateTime, startDateTime, endDateTime, $employeeName))
    then
        scoreHolder.addHardConstraintMatch(kcontext, -100);
end

// ############################################################################
// Medium constraints
// ############################################################################

rule "Assign every possible shift"
    when
        Shift(employee == null)
    then
        scoreHolder.addMediumConstraintMatch(kcontext, -100);
end

// ############################################################################
// Soft constraints
// ############################################################################

rule "available time slot for an employee"
    when
        $rosterParametrization : RosterParametrization(desiredTimeSlotWeight != 0)
        EmployeeAvailability(
                $e : employee,
                $employeeName : employee.getName(),
                $startDateTime : startDateTime,
                $endDateTime : endDateTime)
        Shift(
                employee == $e,
                DateTimeUtils.doTimeslotsMatch($startDateTime,$endDateTime, startDateTime, endDateTime, $employeeName))
    then
        scoreHolder.addSoftConstraintMatch(kcontext, 100);
end

rule "Skill set preference"
    when
        Shift(employee != null, matchedPreferencedDisciplineCount > 0,$matchedPreferencedDisciplineCount : matchedPreferencedDisciplineCount)
    then
        scoreHolder.addSoftConstraintMatch(kcontext, + $matchedPreferencedDisciplineCount);
end

这是我更新的求解器配置文件。

<?xml version="1.0" encoding="UTF-8"?>
<solver>
  <!--<environmentMode>FAST_ASSERT</environmentMode>-->
  <solutionClass>org.optaweb.employeerostering.domain.roster.Roster</solutionClass>
  <entityClass>org.optaweb.employeerostering.domain.shift.Shift</entityClass>

  <scoreDirectorFactory>
    <scoreDrl>org/optaweb/employeerostering/service/solver/employeeRosteringScoreRules.drl</scoreDrl>
  </scoreDirectorFactory>

  <termination>
    <secondsSpentLimit>240</secondsSpentLimit>
  </termination>

  <localSearch>
    <unionMoveSelector>
      <pillarChangeMoveSelector>
        <subPillarType>SEQUENCE</subPillarType>
      </pillarChangeMoveSelector>
      <pillarSwapMoveSelector>
        <subPillarType>SEQUENCE</subPillarType>
      </pillarSwapMoveSelector>
    </unionMoveSelector>
    <acceptor>
      <entityTabuSize>7</entityTabuSize>
    </acceptor>
    <forager>
      <acceptedCountLimit>800</acceptedCountLimit>
    </forager>
  </localSearch>

</solver>

它还强制我在计划实体转移时实施 Comparable

public class Shift extends AbstractPersistable implements Comparable<Shift> {

    private static final Comparator<Shift> PILLAR_SEQUENCE_COMPARATOR = Comparator
            .comparing((Shift a) -> a.getStartDateTime())
            .thenComparing(a -> a.getEndDateTime());

这是否会解决我的求解器不分配员工的问题,尽管他们是可用的,并且会从局部最优解中移除。

4

1 回答 1

0

使用基于 Pilar 的移动选择器更有效地避开局部最优。

于 2020-07-13T07:10:38.820 回答