Adding multi-concept constraints and custom decisions: shift assignment
Adding multi-concept constraints and custom decisions: Decision
Optimization shift
assignment
Last updated: Nov 21, 2024
Creating constraints and custom decisions with the Decision Optimization Modeling Assistant
This Decision
OptimizationModeling 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
Copy link to section
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
Optimizationexperiment.
Deployment space
You must have a deployment space that is associated with your Decision
Optimizationexperiment. You can choose a deployment space when
you create a Decision
Optimizationexperiment.
About this task
Copy link to section
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
Optimizationexperiment, 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.
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 Solve optimization
problems 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
Copy link to section
In the Prepare dataview of the
AssignmentWithOnCallDutiesScenario, 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
Copy link to section
About this task
Copy link to section
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
Copy link to section
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
Copy link to section
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
Copy link to section
About this task
Copy link to section
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
Copy link to section
To define custom decisions, follow these steps.
Click Build model
to see the model formulation of the AssignmentWithOnCallDutiesScenario.
The custom decision OnCallDuties is used in the second objective. This objective
ensures that the number of on-call duties are balanced over Employees.
The constraint ensures that the on-call duty requirements that are listed in the Day table
are satisfied.
The following steps show you how this custom decision OnCallDuties was
defined.
Open the Settings pane and notice that the Visualize
and edit decisions is set to true (or set it to true if it is set to
the default false).
This setting adds a Decisions tab to your Add to
model window.
Here you can see OnCallDuty is specified as an assignment decision (to assign
employees to on-call duties). Its two dimensions are defined with reference to the data tables
Day and Employee. This means that your model will also assign
on-call duties to employees. The Employee-Shift assignment decision is specified from the original
intent.
Optional: Enter your own text to describe the OnCallDuty in
the [to be documented] field.
Optional: To create your own decision in the Decisions
tab, click the enter name, type in a name and click enter.
A new decision (intent) is created with that name with some highlighted fields to
be completed by using the drop-down menus. If you, for example, select assignment
as the decision type, two dimensions are created. As assignment
involves assigning at least one thing to another, at least two dimensions must be defined. Use
select a table fields to define the dimensions.
Results
Copy link to section
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
Copy link to section
About this task
Copy link to section
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
Copy link to section
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
Copy link to section
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.
About cookies on this siteOur websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising.For more information, please review your cookie preferences options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.