OptaPlanner examples その12

Employee rostering


http://docs.jboss.org/optaplanner/release/latest/optaplanner-docs/html_single/index.html#nurseRostering

従業員のシフト最適化です。"Nurse Rostering Competition" ていう競技があって (http://www.kuleuven-kulak.be/nrpcompetition)、その問題を実装しています。

  • NurseRoster : @PlanningSolution
  • ShiftAssignment : @PlanningEntity
    • Employee : @PlanningVariable
    • Shift shift
    • int indexInShift

@PlanningEntity、@PlanningVariable がひとつずつなので比較的シンプルです。Skill や Contract など Employee に関する属性はいろいろあって、制約に使われます。Soft制約がかなりたくさんある。。。けど特筆するものは無いかな。

では が使われています。

  <localSearch>
    <unionMoveSelector>
      <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>
      <!--<moveListFactory>-->
        <!--<cacheType>STEP</cacheType>-->
        <!--<moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentSequenceSwitchLength2MoveFactory</moveListFactoryClass>-->
      <!--</moveListFactory>-->
      <!--<moveListFactory>-->
        <!--<cacheType>STEP</cacheType>-->
        <!--<moveListFactoryClass>org.optaplanner.examples.nurserostering.solver.move.factory.ShiftAssignmentSequenceSwitchLength3MoveFactory</moveListFactoryClass>-->
      <!--</moveListFactory>-->
    </unionMoveSelector>
    <acceptor>
      <entityTabuSize>7</entityTabuSize>
    </acceptor>
    <forager>
      <acceptedCountLimit>800</acceptedCountLimit>
    </forager>
  </localSearch>

は単純に で指定したクラスに Move の List を返させます。

http://docs.jboss.org/optaplanner/release/latest/optaplanner-docs/html_single/index.html#moveListFactory

指定された EmployeeChangeMoveFactory, ShiftAssignmentSwapMoveFactory, ShiftAssignmentPillarPartSwapMoveFactory は基本的に MovableShiftAssignmentSelectionFilter を使って isInPlanningWindow、つまり現在プランニング対象の期間のシフトだけ、Move の対象にしています。

あと、ShiftAssignmentPillarPartSwapMoveFactory は複雑です。。。ぐぬぬ、自信が無いが、同じ Employee のシフトをまとめて動かして CompositeMove にしているようです。