Adding multi-concept constraints and custom decisions: Decision Optimization shift assignment
This Decision
Optimization
Modeling Assistant example shows you how to use multi-concept
iterations, the associated
keyword in constraints, how to define your own custom
decisions, and define logical constraints. For illustration, a resource assignment problem,
ShiftAssignment
, is used and its completed model with data is provided in the
DO-samples.
Before you begin
- Requirements
- To edit and run Decision
Optimization models, you must have the following prerequisites:
- Admin or Editor roles
- You must have Admin or Editor roles in the project. Viewers of shared projects can only see experiments, but cannot modify or run them
- watsonx.ai Runtime service
- You must have a watsonx.ai Runtime service that is associated with your project. You can add one when you create a Decision Optimization experiment.
- Deployment space
- You must have a deployment space that is associated with your Decision Optimization experiment. You can choose a deployment space when you create a Decision Optimization experiment.
About this task
This example is about assigning employees to different shifts, and each day requires that a required number of employees must be on-call. The files that are used in this sample are available in the DO-samples.
This video provides a visual method to learn the concepts and tasks in this documentation. After you load the example in your Decision Optimization experiment, you can follow the video.
Video disclaimer: Some minor steps and graphical steps in this video might differ from your platform. The user interface is also frequently improved.
Procedure
To download and open the sample:
- Download the ShiftAssignment.zip file from the Model_Builder subfolder in the DO-samples. Select the relevant product and version subfolder.
- Open your project or create an empty project.
- Select the Assets tab.
- Select New asset > Solve optimization problems in the Work with models section.
- Click Local file in the Create a Decision Optimization experiment window that opens.
- Browse locally to find and choose the ShiftAssignment.zip archive that you downloaded. Click Open. Alternatively use drag and drop.
- If you haven't already associated a watsonx.ai Runtime service with your project, you must first select Add a Machine Learning service to select or create one before you choose a deployment space for your experiment.
- Click Create. A Decision Optimization model is created with the same name as the sample.
- Open the scenario pane and select the
AssignmentWithOnCallDuties
scenario.
Results
In the Prepare data
view of the
AssignmentWithOnCallDuties
Scenario, you can see the data assets imported.
These tables represent the shifts, the employees that need to be assigned to these shifts and days
with their required on-call duties.
Using multi-concept iteration
About this task
Suppose that you want your model formulation to express the rule that each employee can’t work more than one shift per day. For example, an employee cannot be assigned two shifts on the same day. You might use, as shown in this model formulation, a constraint for each day of the week.
But listing constraints for each day of the week is cumbersome: if your model were based on days
in the year, you must then list hundreds of these type of constraints. The following procedure shows
you how to use multi-concept iteration and the associated
keyword to express
iteration over more than one concept. Thus, you can express such a rule with just one phrase.
Procedure
To use multi-concept iteration, follow these steps.
-
Click Build model in the
sidebar to view your model formulation.
The model formulation shows the intent as being to assign employees to shifts, with its objectives and constraints.
- Expand the constraint
For each Employee-Day combination , number of associated Employee-Shift assignments is less than or equal to 1
.
Results
This constraint combines
employees and days with the keyword associated
so that the expression iterates over
both employee and day. You can see that the employee in the employee-day combination is mapped to
the employee in the employee-shift assignment. Also the day in the employee-day combination is
mapped to the day property of the assigned shift. Thus, the combinations are correctly and
automatically handled for you.
With this multi-concept iteration, you can specify new groups of rules that combine different concepts.
Defining custom decisions
About this task
Suppose that you also want to assign on-call duties. You might create another model with the
intent to assign employees to on-call duties, but then you would not be able to state dependency
rules between the two models. By adding custom decisions to your existing model, as demonstrated in
this example, you can define dependencies between shift assignment and on-call duties. Here the
custom decision is called OnCallDuties
.
Procedure
To define custom decisions, follow these steps.
Results
You are no longer restricted to using only decisions deduced from your intent. You can now define your own custom decisions by using the advanced settings and decision tabs, where you can select your decision type and its dimensions (data table or column). You can then configure new rules and objectives that use your newly defined decision.
Using logical constraints
About this task
Suppose that you want to ensure that the assigned on-call duties do not occur when an employee is on vacation. You can achieve this by using logical constraints as follows.
Procedure
To use logical constraints:
- Look at the constraint
This constraint ensures that, for each employee and day combination, when no associated assignments exist (for example, the employee is on vacation on that day), that no on-call duties are assigned to that employee on that day. Note the use of the
if...then
keywords to define this logical constraint. - Optional: Add other logical constraints to your model by searching in the suggestions.
Results
This constraint links the assignment of employees to shifts with on-call duties. With separate models, one for the original shift assignment and another for the on-call duties you can't achieve this linking.
By using logical constraints, together with the associated
keyword, you can
specify that if one constraint applies, then another constraint also applies. The necessary logical
connection between the concepts that you are referring to, are made automatically, without you
having to use more complicated join expressions.