0 / 0
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 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:

  1. Download the ShiftAssignment.zip file from the Model_Builder subfolder in the DO-samples. Select the relevant product and version subfolder.
  2. Open your project or create an empty project.
  3. Select the Assets tab.
  4. Select New asset > Solve optimization problems in the Work with models section.
  5. Click Local file in the Solve optimization problems window that opens.
  6. Browse locally to find and choose the ShiftAssignment.zip archive that you downloaded. Click Open. Alternatively use drag and drop.
  7. 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.
  8. Click Create.
    A Decision Optimization model is created with the same name as the sample.
  9. 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.

Prepare data view showing  Staff Assignment data

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.

Several constraints, one for each day, to formulate only one shift per employee per day

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.

  1. 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.
  2. Expand the constraint For each Employee-Day combination , number of associated Employee-Shift assignments is less than or equal to 1.

Results

Employee-day combination constraint expanded

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.

  1. Click Build model to see the model formulation of the AssignmentWithOnCallDuties Scenario.
    Build model view showing Shift Assignment formulation

    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 On call duty 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.

  2. 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.

    Decisions tab of the Add to Model pane showing two intents

    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.

  3. Optional: Enter your own text to describe the OnCallDuty in the [to be documented] field.
  4. 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

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:

  1. Look at the constraint Logical constraint suggestion
    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.
  2. 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.

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more