Decision Central で Red Hat Business Optimizer の従業員の勤務表問題を作成し解決する方法
概要
前書き
ビジネスルールの作成者は、Red Hat Decision Manager ディストリビューションに同梱されている、事前設定済みの employee-rostering サンプルプロジェクトを使用して、Red Hat Business Optimizer の機能をテストおよび操作できます。
employee-rostering サンプルプロジェクトは、Decision Central にビルドしてデプロイできます。このプロジェクトは、シフト勤務の計画問題を解決するのに必要な Decision Central の各アセットを作成し、Red Hat Business Optimizer を使用して実現可能な最適解を見つける方法を示します。本書を参考に、事前設定した employee-rostering プロジェクトを Decision Central にデプロイするか、Decision Central を使用してプロジェクトを作成します。
Decision Central の employee-rostering サンプルプロジェクトには、データセットが含まれていません。
前提条件
- Red Hat JBoss Enterprise Application Platform 7.1.0 がインストールされている。『Red Hat JBoss EAP 7.1.0 インストールガイド』を参照してください。
- Red Hat Decision Manager がインストールされている。詳細は『Red Hat Decision Manager のオンプレミスインストール』を参照してください。
-
Red Hat Decision Manager が実行していて、
adminロールで Decision Central にログインできる。詳細は『Red Hat Decision Manager のオンプレミスインストール』を参照してください。 - Red Hat Business Optimizer に Red Hat Decision Manager が設定されている。必要な設定については『Red Hat Business Optimizer のインストールおよび設定』を参照してください。
- このサンプルを修正してデータを最適化する場合は、修正したプロジェクトを Decision Central からサーバーにデプロイし、Decision Server で最適なタスクを実行するためのデータセットが必要です。
第1章 Decision Central への従業員勤務表サンプルプロジェクトのデプロイメント
Decision Central には、製品と機能に慣れるために使用できるサンプルプロジェクトが多数あります。従業員の勤務表サンプルプロジェクトは、Red Hat Business Optimizer でシフト勤務のユースケースを示すために計画され作成されました。以下の手順に従って、従業員の勤務表サンプルを Decision Central にデプロイして実行します。
前提条件
- Red Hat Decision Manager がダウンロードされ、インストールされている。
-
デシジョンサーバーを起動し、
admin権限を持つユーザーで Decision Central にログインしている。 - インストールの詳細は『Red Hat Decision Manager のオンプレミスインストール』を参照してください。
- 使用方法の詳細は『デシジョンサービスの使用ガイド』を参照してください。
手順
- Decision Central で Menu → Design → Projects の順にクリックします。
-
事前に設定した
myteamスペースで Try Samples をクリックします。 - サンプルプロジェクトの一覧から employee-rostering を選択し、右上の OK をクリックして、プロジェクトをインポートします。
- アセットリストをコンパイルし、Build & Deploy をクリックして、従業員の勤務表サンプルをデプロイします。
本書は、各プロジェクトアセットと、その設定を説明します。
第2章 従業員の勤務表サンプルプロジェクトの設定
従業員の勤務表サンプルプロジェクトは、Decision Central で使用できる事前設定のプロジェクトです。このプロジェクトをデプロイする方法は「1章Decision Central への従業員勤務表サンプルプロジェクトのデプロイメント」を参照してください。
本章は、従業員の勤務表サンプルを設定する方法を説明します。このワークフローに従って、Decision Central に同じようなプロジェクトを作成できます。
前提条件
- Red Hat Decision Manager がダウンロードされ、インストールされている。
-
Decision Central をデプロイし、
adminロールを持つユーザーでログインしている。
手順
- Menu → Design → Projects → Add Project をクリックして、Decision Central に新しいプロジェクトを作成します。
Add Project ウィンドウで、以下のフィールドに入力します。
-
Name:
employee-rostering - Description(任意): Business Optimizer を使用した従業員の勤務表問題の最適化。スキルに基づいて、従業員をシフトに割り当てます。
任意で、Show Advanced Options をクリックして、
Group ID、Artifact ID、およびVersionに情報を追加します。-
Group ID:
employeerostering -
Artifact ID:
employeerostering -
Version:
1.0.0-SNAPSHOT
-
Name:
- Add をクリックして、Decision Central プロジェクトリポジトリーにプロジェクトを追加します。
第3章 プロジェクトファクトおよびプランニングエンティティー
従業員勤務表の計画問題の各ドメインクラスは、以下のいずれかに分類できます。
- 関連性のないクラス: どのスコア制約にも使用されません。計画に関して言えば、このデータは使用されません。
-
問題ファクト クラス: スコア制約に使用されますが、(問題が変わらない限り) 計画時には変化しません (例:
Shift、Employeeなど)。問題ファクトクラスのプロパティーはすべて問題のプロパティーです。 プランニングエンティティークラス クラス: スコア制約に使用され、計画時に変化します (例:
ShiftAssignment)。計画時に変更するプロパティーは プランニング変数 です。その他のプロパティーは問題プロパティーです。以下の点についてお考え下さい。
- どのクラスを、計画時に変更しますか?
どのクラスに、
Solverで変更する変数がありますか?そのクラスが、プランニングエンティティーです。
プランニングエンティティークラスは、
@PlanningEntityアノテーションでアノテートする必要があります。または、ドメインデザイナーで Red Hat Business Optimizer ドックを使用して Decision Central に定義する必要があります。各プランニングエンティティークラスには、1 つ以上の プランニング変数 があり、1 つ以上の定義プロパティーが必要です。
多くのユースケースには、プランニングエンティティークラスが 1 つだけあり、1 つのプランニングエンティティークラスに対してプランニング変数が 1 つだけ含まれます。
第4章 従業員の勤務表プロジェクトへのデータモデルの作成
このセクションでは、Decision Central で従業員の勤務表サンプルプロジェクトを実行するのに必要なデータオブジェクトを作成します。
前提条件
「2章従業員の勤務表サンプルプロジェクトの設定」に従ってプロジェクトを設定している。
手順
- 新規プロジェクトで、プロジェクトパースペクティブの Data Object をクリックするか、Create New Asset → Data Object をクリックして、新しいデータオブジェクトを作成します。
最初のデータオブジェクトの名前を
Timeslotとし、パッケージ でemployeerostering.employeerosteringを選択します。OK をクリックします。
-
Data Objects パースペクティブで +add field をクリックして、
Timeslotデータオブジェクトにフィールドを追加します。 -
id フィールドで
endTimeと入力します。 -
Type の横にあるドロップダウンメニューをクリックし、
LocalDateTimeを選択します。 - Create and continue を別のフィールドに追加します。
-
id
startTimeおよび TypeLocalDateTimeを使用して、フィールドを追加します。 - Create をクリックします。
-
右上の Save をクリックして、
Timeslotデータオブジェクトを保存します。 - 右上の x をクリックして、Data Objects パースペクティブを閉じ、Assets メニューに戻ります。
前述の手順で、以下のデータオブジェクトとその属性を作成します。
表4.1 Skill
id タイプ nameString表4.2 Employee
id タイプ nameStringskillsemployeerostering.employeerostering.Skill[List]表4.3 Shift
id タイプ requiredSkillemployeerostering.employeerostering.Skilltimeslotemployeerostering.employeerostering.Timeslot表4.4 DayOffRequest
id タイプ dateLocalDateemployeeemployeerostering.employeerostering.Employee表4.5 ShiftAssignment
id タイプ employeeemployeerostering.employeerostering.Employeeshiftemployeerostering.employeerostering.Shift
データオブジェクトの詳細は『デシジョンサービスの使用ガイド』を参照してください。
4.1. 従業員の勤務表プランニングエンティティーの作成
従業員勤務表の計画問題を解決するには、プランニングエンティティーと Solver を作成する必要があります。プランニングエンティティーは、Red Hat Business Optimizer ドックで利用可能な属性を使用して、ドメインデザイナーに定義します。
以下の手順に従って、従業員の勤務表サンプルに、ShiftAssignment データオブジェクトをプランニングエンティティーとして定義します。
前提条件
- 従業員の勤務表サンプルを実行するには、「4章従業員の勤務表プロジェクトへのデータモデルの作成」の手順に従って、関連するデータオブジェクトとプランニングエンティティーを作成する必要があります。
手順
-
プロジェクトの Assets メニューから、
ShiftAssignmentデータオブジェクトを開きます。 -
Data Objects パースペクティブで、右側の
をクリックして Red Hat Business Optimizer ドックを開きます。
- Planning Entity を選択します。
-
ShiftAssignmentデータオブジェクトのフィールドリストでemployeeを選択します。 Red Hat Business Optimizer ドックで Planning Variable を選択します。
Value Range Id 入力フィールドに
employeeRangeを入力します。これにより、@ValueRangeProviderアノテーションがプランニングエンティティーに追加され、デザイナーのSourceタブをクリックすると表示されます。プランニング変数の値の範囲は
@ValueRangeProviderアノテーションで定義されます。@ValueRangeProviderアノテーションにはidプロパティーが常にあり、@PlanningVariableのvalueRangeProviderRefsプロパティーから参照されます。- ドックを閉じ、Save をクリックして、データオブジェクトを保存します。
4.2. 従業員の勤務表プランニングソリューションの作成
従業員勤務表の問題は、定義したプランニングソリューションに依存します。プランニングソリューションは、Red Hat Business Optimizer ドックで利用可能な属性を使用してドメインデザイナーで定義されます。
前提条件
- 「4章従業員の勤務表プロジェクトへのデータモデルの作成」および 「従業員の勤務表プランニングエンティティーの作成」 の手順に従って、従業員の勤務表サンプルを実行するのに必要なデータオブジェクトおよびプランニングエンティティーを作成している。
手順
-
識別子
EmployeeRosterでデータオブジェクトを新規作成します。 以下のフィールドを作成します。
表4.6 EmployeeRoster
id タイプ dayOffRequestListemployeerostering.employeerostering.DayOffRequest[List]shiftAssignmentListemployeerostering.employeerostering.ShiftAssignment[List]shiftListemployeerostering.employeerostering.Shift[List]skillListemployeerostering.employeerostering.Skill[List]timeslotListemployeerostering.employeerostering.Timeslot[List]-
Data Objects パースペクティブで、右側の
をクリックして Red Hat Business Optimizer ドックを開きます。
- プランニングソリューション を選択します。
-
Solution Score Type は、デフォルトの
Hard soft scoreのままにします。これにより、タイプが ソリューションスコアとなるEmployeeRosterデータオブジェクトに、scoreフィールドが自動的に生成されます。 次の属性で新しいフィールドを追加します。
id タイプ employeeListemployeerostering.employeerostering.Employee[List]employeeListフィールドを選択した状態で、Red Hat Business Optimizer ドックを開いて、Planning Value Range Provider ボックスを選択します。id フィールドに
employeeRangeを入力し、ドックを閉じます。- 右上で Save をクリックし、アセットを保存します。
第5章 従業員勤務表の制約
従業員の勤務表はプランニングソリューションです。すべての計画問題には、最適解を得るのに必要な制約が含まれます。
Decision Central の従業員の勤務表サンプルプロジェクトには、以下のハード制約およびソフト制約が含まれます。
- ハード制約
- 従業員に割り当てられるシフトの数は、1 日 1 つまで。
- 特別な従業員スキルが必要なすべてのシフトは、そのスキルを持つ従業員に割り当てられる。
- ソフト制約
- すべての従業員がシフトに割り当てられている。
- 従業員が休暇を取った場合は、シフトを別の従業員に再割り当て可能。
ハード制約およびソフト制約は、フリーフォーム DRL デザイナー、またはガイド付きルールを使用して Decision Central で定義できます。
ハード制約およびソフト制約の詳細は「Red Hat Business Optimizer のインストールおよび設定」を参照してください。
5.1. DRL ルール
DRL ルールは、.drl テキストファイルに直接定義するビジネスルールです。このような DRL ファイルは、Decision Central の他のすべてのルールアセットが最終的にレンダリングされるソースとなります。DRL ファイルを Decision Central インターフェースで作成および管理したり、外部の Red Hat Developer Studio、Java オブジェクト、Maven アーキタイプを使用して作成したりできます。DRL ファイルには、最低限、ルールの条件 (when) およびアクション (then) を定義するルールを 1 つ以上追加できます。Decision Central の DRL デザイナーでは、Java、DRL、および XML の構文が強調表示されます。
DRL ルールに関連するデータオブジェクトはすべて、DRL ルールと同じ Decision Central プロジェクトパッケージに置く必要があります。同じパッケージのアセットはデフォルトでインポートされます。その他のパッケージの既存アセットは、DRL ルールを使用してインポートできます。
5.2. DRL デザイナーを使用した従業員の勤務表の制約定義
Decision Central でフリーフォーム DRL デザイナーを使用して、従業員の勤務表サンプルに制約の定義を作成できます。
この手順を使用して、シフトが終わってから 10 時間以上経たないと従業員をシステムに割り当てられない ハード制約 を作成します。
手順
- Menu → Design → Projects に移動して、プロジェクト名をクリックします。
- Create New Asset → DRL file をクリックします。
-
DRL file 名前フィールドに、
ComplexScoreRulesと入力します。 -
employeerostering.employeerosteringパッケージを選択します。 - +Ok をクリックして DRL ファイルを作成します。
DRL デザイナーの Editor タブで、
Employee10HourShiftSpaceルールを DRL ファイルとして定義します。package employeerostering.employeerostering; rule "Employee10HourShiftSpace" dialect "mvel" when $shiftAssignment : ShiftAssignment( $employee : employee != null, $shiftEndDateTime : shift.timeslot.endTime) ShiftAssignment( this != $shiftAssignment, $employee == employee, $shiftEndDateTime <= shift.timeslot.endTime, $shiftEndDateTime.until(shift.timeslot.startTime, java.time.temporal.ChronoUnit.HOURS) <10) then scoreHolder.addHardConstraintMatch(kcontext, -1); end- Save をクリックして、DRL ファイルを保存します。
DRL ファイルの作成方法は「DRL ルールを使用したデシジョンサービスの作成」を参照してください。
第6章 ガイド付きルールを使用して従業員の勤務表にルールの作成
Decision Central でガイド付きルールデザイナーを使用して、従業員の勤務表にハード制約およびソフト制約を定義するルールを作成できます。
6.1. ガイド付きルール
ガイド付きルールは、ルール作成のプロセスを提供する、Decision Central の UI ベースのガイド付きルールデザイナーで作成するビジネスルールです。ガイド付きルールデザイナーを使用すると、ルールを定義するデータオブジェクトに基づいて、可能なインプットにフィールドおよびオプションを提供します。定義したガイド付きルールは、その他のすべてのルールアセットとともに Drools Rule Language (DRL) ルールにコンパイルされます。
ガイド付きルールに関連するすべてのデータオブジェクトは、ガイド付きルールと同じプロジェクトパッケージに置く必要があります。同じパッケージに含まれるアセットはデフォルトでインポートされます。必要なデータオブジェクトとガイド付きルールを作成したら、ガイド付きルールデザイナーの Data Objects タブから、必要なデータオブジェクトがすべてリストされていることを検証したり、 新規アイテム を追加してその他の既存データオブジェクトをインポートしたりできます。
6.2. 従業員のシフト数のバランスを取るガイド付きルールの作成
ガイド付きルール BalanceEmployeesShiftNumber は、可能な限りバランスを取るように従業員にシフトを割り当てるソフト制約を作成します。これは、シフトの分配が平等でなくなると増えるスコアペナルティーを作成することで行います。ルールによって実装されたスコア式により、Solver がよりバランスの取れるようにシフトを分散させます。

手順
- Menu → Design → Projects に移動して、プロジェクト名をクリックします。
- Create New Asset → Guided Rule をクリックします。
-
Guided Rule 名 に
BalanceEmployeesShiftNumberを入力し、Package でemployeerostering.employeerosteringを選択します。 - OK をクリックして、ルールアセットを作成します。
-
WHEN フィールドで
をクリックして、WHEN 条件を追加します。
-
Add a condition to the rule ウィンドウで
Employeeを選択し、+Ok をクリックします。 -
Employee条件でクリックして制約を修正し、変数名$employeeを追加します。 WHEN 条件
From Accumulateを追加します。-
From Accumulate条件の上で click to add pattern をクリックし、ドロップダウンリストでファクトタイプNumberを選択します。 -
変数名
$shiftCountをNumber条件に追加します。 -
From Accumulate条件の下で click to add pattern をクリックして、ドロップダウンリストでShiftAssignmentファクトタイプを選択します。 -
変数名
$shiftAssignmentをShiftAssignmentファクトタイプに追加します。 -
ShiftAssignment条件を再度クリックし、Add a restriction on a field ドロップダウンリストでemployeeを選択します。 -
employee制約の横にあるドロップダウンリストでequal toを選択します。 -
ドロップダウンボタンの横の
アイコンをクリックして変数を追加し、Field value ウィンドウで Bound variable をクリックします。
-
ドロップダウンリストで
$employeeを選択します。 -
Function ボックスに
count($shiftAssignment)と入力します。
-
-
THEN フィールドで
をクリックして、THEN 条件を追加します。
Add a new action ウィンドウで
Modify Soft Scoreを選択し、+Ok をクリックします。-
ボックスに
-($shiftCount.intValue()*$shiftCount.intValue())と入力します。
-
ボックスに
- 右上の Validate をクリックし、ルール条件がすべて有効であることを確認します。ルールの妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、ルールの全コンポーネントを見直し、エラーが表示されなくなるまでルールの妥当性確認を行います。
- Save をクリックして、ルールを保存します。
ガイド付きルールの作成方法は『ガイド付きルールを使用したデシジョンサービスの作成』を参照してください。
6.3. 同じ日に複数のシフトを割り当てないようにするガイド付きルールの作成
ガイド付きルール OneEmployeeShiftPerDay は、同じ日の複数のシフトに従業員を割り当てないようにするハード制約を作成します。従業員の勤務表サンプルでは、このガイド付きルールデザイナーを使用してこの制約が作成されます。

手順
- Menu → Design → Projects に移動して、プロジェクト名をクリックします。
- Create New Asset → Guided Rule をクリックします。
-
Guided Rule 名に
OneEmployeeShiftPerDayと入力し、Package でemployeerostering.employeerosteringを選択します。 - OK をクリックして、ルールアセットを作成します。
-
WHEN フィールドで
をクリックして、WHEN 条件を追加します。
- Add a condition to the rule ウィンドウから Free form DRL を選択します。
フリーフォームの DRL ボックスに、以下の条件を入力します。
$shiftAssignment : ShiftAssignment( employee != null ) ShiftAssignment( this != $shiftAssignment , employee == $shiftAssignment.employee , shift.timeslot.startTime.toLocalDate() == $shiftAssignment.shift.timeslot.startTime.toLocalDate() )
この条件は、同じ日に別のシフトがすでに割り当てられている従業員にはシフトを割り当てることができないことを示しています。
-
THEN フィールドで
をクリックして、THEN 条件を追加します。
- Add a new action ウィンドウから Add free form DRL を選択します。
フリーフォームの DRL ボックスに、以下の条件を入力します。
scoreHolder.addHardConstraintMatch(kcontext, -1);
- 右上の Validate をクリックし、ルール条件がすべて有効であることを確認します。ルールの妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、ルールの全コンポーネントを見直し、エラーが表示されなくなるまでルールの妥当性確認を行います。
- Save をクリックして、ルールを保存します。
ガイド付きルールの作成方法は『ガイド付きルールを使用したデシジョンサービスの作成』を参照してください。
6.4. シフト要件にスキルを一致させるガイド付きルールの作成
ガイド付きルール ShiftReqiredSkillsAreMet は、すべてのシフトが、適切なスキルセットを持つ従業員に割り当てられるのを確認するハード制約を作成します。従業員の勤務表サンプルでは、ガイド付きルールデザイナーを使用してこの制約を作成します。

手順
- Menu → Design → Projects に移動して、プロジェクト名をクリックします。
- Create New Asset → Guided Rule をクリックします。
-
Guided Rule 名に
ShiftReqiredSkillsAreMetと入力し、Package でemployeerostering.employeerosteringを選択します。 - OK をクリックして、ルールアセットを作成します。
-
WHEN フィールドで
をクリックして、WHEN 条件を追加します。
-
Add a condition to the rule ウィンドウで
ShiftAssignmentを選択します。+Ok をクリックします。 -
ShiftAssignment条件をクリックし、Add a restriction on a field ドロップダウンリストでemployeeを選択します。 -
デザイナーで、
employeeの横のドロップダウンリストをクリックし、is not nullを選択します。 ShiftAssignment条件をクリックし、Expression editor をクリックします。-
デザイナーで、
[not bound]をクリックし、Expression editor を開き、式と変数$requiredSkillをバインドします。Set をクリックします。 -
デザイナーの
$requiredSkillの横にあるドロップダウンリストでshiftを選択し、その隣のドロップダウンリストでrequiredSkillを選択します。
-
デザイナーで、
ShiftAssignment条件をクリックし、Expression editor をクリックします。-
デザイナーで、
[not bound]の横にあるドロップダウンリストでemployeeを選択し、その隣のドロップダウンリストでskillsを選択します。 -
その隣のドロップダウンリストでは
Chooseを選択したままにします。 -
その隣のドロップダウンボックスで、
please chooseをexcludesに変更します。 -
excludesの隣の
アイコンをクリックし、Field value ウィンドウで New formula ボタンをクリックします。
-
式ボックスに
$requiredSkillを追加します。
-
デザイナーで、
-
THEN フィールドで
をクリックして、THEN 条件を追加します。
-
Add a new action ウィンドウで
Modify Hard Scoreを選択し、+Ok をクリックします。 -
スコアアクションボックスに
-1を入力します。 - 右上の Validate をクリックし、ルール条件がすべて有効であることを確認します。ルールの妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、ルールの全コンポーネントを見直し、エラーが表示されなくなるまでルールの妥当性確認を行います。
- Save をクリックして、ルールを保存します。
ガイド付きルールの作成方法は『ガイド付きルールを使用したデシジョンサービスの作成』を参照してください。
6.5. 休暇申請を管理するガイド付きルールの作成
ガイド付きルール DayOffRequest は、そのシフトに元々割り当てられていた従業員がその日に就業できなくなった場合に、別の従業員にシフトを再割り当てできるようにするソフト制約を作成します。従業員の勤務表サンプルでは、この制約はガイド付きルールデザイナーを使用して作成されます。

手順
- Menu → Design → Projects に移動して、プロジェクト名をクリックします。
- Create New Asset → Guided Rule をクリックします。
-
Guided Rule 名に
DayOffRequestと入力し、Package でemployeerostering.employeerosteringを選択します。 - OK をクリックして、ルールアセットを作成します。
-
WHEN フィールドで
をクリックして、WHEN 条件を追加します。
- Add a condition to the rule ウィンドウから Free form DRL を選択します。
フリーフォームの DRL ボックスに、以下の条件を入力します。
$dayOffRequest : DayOffRequest( ) ShiftAssignment( employee == $dayOffRequest.employee , shift.timeslot.startTime.toLocalDate() == $dayOffRequest.date )
この条件は、休暇申請を行った従業員にシフトを割り当てている場合に、その従業員をその日のシフト割り当てから削除できることを示しています。
-
THEN フィールドで
をクリックして、THEN 条件を追加します。
- Add a new action ウィンドウから Add free form DRL を選択します。
フリーフォームの DRL ボックスに、以下の条件を入力します。
scoreHolder.addSoftConstraintMatch(kcontext, -100);
- 右上の Validate をクリックし、ルール条件がすべて有効であることを確認します。ルールの妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、ルールの全コンポーネントを見直し、エラーが表示されなくなるまでルールの妥当性確認を行います。
- Save をクリックして、ルールを保存します。
ガイド付きルールの作成方法は『ガイド付きルールを使用したデシジョンサービスの作成』を参照してください。
第7章 従業員の勤務表への Solver の設定
Decision Central に Solver 設定を作成して編集することができます。Solver 設定デザイナーは、プロジェクトがデプロイされた後に実行できる Solver 設定を作成します。
前提条件
Red Hat Decision Manager がダウンロードしてインストールされており、従業員の勤務表サンプルに関連するアセットをすべて作成して設定している。
手順
- Decision Central で、Menu → Projects をクリックし、プロジェクトをクリックして開きます。
- Assets パースペクティブで、Create New Asset → Solver configuration をクリックします。
Create new Solver configuration ウィンドウで、Solver の名前
EmployeeRosteringSolverConfigと入力し、Ok をクリックします。これにより、Solver configuration デザイナーが開きます。
Score Director Factory 設定セクションで、スコアリングルール定義を含むナレッジベースを定義します。従業員の勤務表サンプルプロジェクトは
defaultKieBaseを使用します。-
ナレッジベースに定義したナレッジセクションの中から 1 つ選択します。従業員の勤務表サンプルプロジェクトは
defaultKieSessionを使用します。
-
ナレッジベースに定義したナレッジセクションの中から 1 つ選択します。従業員の勤務表サンプルプロジェクトは
- 右上の Validate をクリックし、Score Director Factory 設定が正しいことを確認します。妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、エラーが表示されなくなるまで妥当性確認を行います。
- Save をクリックして、Solver 設定を保存します。
Solver の設定方法は『Red Hat Business Optimizer のインストールおよび設定』を参照してください。
7.1. 従業員の勤務表プロジェクトに対する Solver の終了設定
一定期間が過ぎたら Solver が終了できるように設定できます。デフォルトでは、プランニングエンジンには、時間制限なく問題を解決できるように指定されています。
従業員の勤務表サンプルプロジェクトは、30 秒間実行するように設定されています。
前提条件
従業員の勤務表プロジェクトに、関連するすべてのアセットを作成し、「7章従業員の勤務表への Solver の設定」の手順に従って、Decision Central に Solver 設定 EmployeeRosteringSolverConfig を作成している。
手順
-
Assets パースペクティブで
EmployeeRosteringSolverConfigを開きます。これにより、Solver 設定 デザイナーが開きます。 - Termination セクションで Add をクリックして、選択した論理グループに新しい終了要素を作成します。
-
ドロップダウンリストから、終了タイプ
Time spentを選択します。これは、終了条件の入力フィールドとして追加されます。 - 時間要素の横の矢印を使用して、経過時間を 30 秒に設定します。
- 右上の Validate をクリックし、Score Director Factory 設定が正しいことを確認します。妥当性確認に失敗したら、エラーメッセージに記載された問題に対応し、エラーが表示されなくなるまで妥当性確認を行います。
- Save をクリックして、Solver 設定を保存します。
Solver または Solver の終了を設定する方法は『Red Hat Decision Manager Red Hat Business Optimizer Guide』を参照してください。
7.2. REST API を使用した Solver の登録
Solver 設定を作成し、プロジェクトをデシジョンサーバーにデプロイしたら、Solver を作成してプランニング問題を送信できます。これは、デシジョンサーバーのリモート API からプロジェクトの KIE コンテナーの機能にアクセスして行います。Solver 設定ファイルから Solver を作成し、それにプランニング問題を送信すれば、いつでも最適解をリクエストできます。
各 Solver で、一度に最適化できる計画問題の数は 1 つだけです。
前提条件
-
このサンプルで使用した
admin認証情報を有効にするには、kie-serverロールが必要。kie-serverロールの詳細は『Red Hat Business Optimizer のインストールおよび設定』を参照してください。 - 前章に従って、従業員の勤務表プロジェクトが設定されデプロイされている。
- 「7章従業員の勤務表への Solver の設定」および 「従業員の勤務表プロジェクトに対する Solver の終了設定」 に従って Solver が設定されている。
- 従業員の勤務表プロジェクトが適切にビルドされデプロイされている。 ワークベンチに従業員の勤務表サンプルプロジェクトをデプロイする方法は「1章Decision Central への従業員勤務表サンプルプロジェクトのデプロイメント」を参照してください。
手順
以下のヘッダーを使用して HTTP 要求を作成します。
authorization: admin:admin X-KIE-ContentType: xstream content-type: application/xml
以下の要求を使用して Solver を登録します。
- PUT
-
http://localhost:8080/kie-server/services/rest/server/containers/employeerostering_1.0.0-SNAPSHOT/solvers/EmployeeRosteringSolver - 要求の本文
<solver-instance> <solver-config-file>employeerostering/employeerostering/EmployeeRosteringSolverConfig.solver.xml</solver-config-file> </solver-instance>
Solver に要求を送信します。
- POST
-
http://localhost:8080/kie-server/services/rest/server/containers/employeerostering_1.0.0-SNAPSHOT/solvers/EmployeeRosteringSolver/state/solving - 要求の本文
<employeerostering.employeerostering.EmployeeRoster> <employeeList> <employeerostering.employeerostering.Employee> <name>John</name> <skills> <employeerostering.employeerostering.Skill> <name>reading</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> <employeerostering.employeerostering.Employee> <name>Mary</name> <skills> <employeerostering.employeerostering.Skill> <name>writing</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> <employeerostering.employeerostering.Employee> <name>Petr</name> <skills> <employeerostering.employeerostering.Skill> <name>speaking</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> </employeeList> <shiftList> <employeerostering.employeerostering.Shift> <timeslot> <startTime>2017-01-01T00:00:00</startTime> <endTime>2017-01-01T01:00:00</endTime> </timeslot> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> <employeerostering.employeerostering.Shift> <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> <employeerostering.employeerostering.Shift> <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> </shiftList> <skillList> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/> </skillList> <timeslotList> <employeerostering.employeerostering.Timeslot reference="../../shiftList/employeerostering.employeerostering.Shift/timeslot"/> </timeslotList> <dayOffRequestList/> <shiftAssignmentList/> </employeerostering.employeerostering.EmployeeRoster>
計画問題に最適解をリクエストします。
- GET
応答例
<solver-instance> <container-id>employee-rostering</container-id> <solver-id>solver1</solver-id> <solver-config-file>employeerostering/employeerostering/EmployeeRosteringSolverConfig.solver.xml</solver-config-file> <status>NOT_SOLVING</status> <score scoreClass="org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore">0hard/0soft</score> <best-solution class="employeerostering.employeerostering.EmployeeRoster"> <employeeList> <employeerostering.employeerostering.Employee> <name>John</name> <skills> <employeerostering.employeerostering.Skill> <name>reading</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> <employeerostering.employeerostering.Employee> <name>Mary</name> <skills> <employeerostering.employeerostering.Skill> <name>writing</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> <employeerostering.employeerostering.Employee> <name>Petr</name> <skills> <employeerostering.employeerostering.Skill> <name>speaking</name> </employeerostering.employeerostering.Skill> </skills> </employeerostering.employeerostering.Employee> </employeeList> <shiftList> <employeerostering.employeerostering.Shift> <timeslot> <startTime>2017-01-01T00:00:00</startTime> <endTime>2017-01-01T01:00:00</endTime> </timeslot> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> <employeerostering.employeerostering.Shift> <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> <employeerostering.employeerostering.Shift> <timeslot reference="../../employeerostering.employeerostering.Shift/timeslot"/> <requiredSkill reference="../../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/> </employeerostering.employeerostering.Shift> </shiftList> <skillList> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee/skills/employeerostering.employeerostering.Skill"/> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[3]/skills/employeerostering.employeerostering.Skill"/> <employeerostering.employeerostering.Skill reference="../../employeeList/employeerostering.employeerostering.Employee[2]/skills/employeerostering.employeerostering.Skill"/> </skillList> <timeslotList> <employeerostering.employeerostering.Timeslot reference="../../shiftList/employeerostering.employeerostering.Shift/timeslot"/> </timeslotList> <dayOffRequestList/> <shiftAssignmentList/> <score>0hard/0soft</score> </best-solution> </solver-instance>
デシジョンサーバーの REST API から、コンテナー、Solver を作成し、 問題を送信する方法は『Red Hat Business Optimizer のインストールおよび設定』を参照してください。
付録A バージョン情報
本ドキュメントの最終更新日: 2018 年 7 月 3 日
