Step 6: Define constraints
Constraints restrict the possible values of one or more decision variables. Technically the fact of the value of a decision variable being a non-negative continuous real number, non-negative integer, or binary is a constraint, but this is already declared for the decision variable so you don’t need to do it again.
You create a constraint over specified columns from one or more of your data sources. These columns are called iteration indices. You can set up index filters that compare against a target number to include only those records that need to have a constraint created for them. For example, a filter rule of !=
and a filter target of 0
excludes records with a value of zero.
The expression for a constraint comprises a left hand side, an inequality or equality operator, and a right hand side. The left hand side and right hand side each contain one or more summands, which can each sum up one or more multiplicands. The summands on each side are then summed up (unless you use a constant of -1 to enforce a subtraction), and the sides are compared according to your chosen operator. Here’s how the hierarchy looks:
The multiplicands that go into each summand can be one or more of any combination of these things:
A constant that you’ve defined in your optimization model.
A decision variable that you’ve defined in your optimization model.
A table composed of columns from one of the data sources in your optimization model. The columns must all be in the same data source - if you want to include two different data sources, you need to declare two different multiplicands.
A summand can have one or more indices over which it creates the sum. These columns are called summation indices.
A column that you choose as an iteration index or a summation index must be referenced somewhere in the multiplicands you’re going to use for this sum. So it must either be used in a decision variable that you’re selecting as a multiplicand, or included in a data source that you’re using columns from for a multiplicand. When you define a multiplicand, you need to create an index mapping to identify each column referenced by the multiplicand that’s an iteration index or a summation index.
Important
The more constraints your model has, the longer it takes to solve. Like with decision variables, too many constraints can make the model impossible to solve in a reasonable amount of time.
Before you include a constraint, consider whether you can achieve the effect another way. For example, our Order Allocation use case identifies the day to ship an order. Deliveries can’t be made on weekend days and public holidays, and we could have used a constraint to remove those from the results. Instead, we filtered them out in the data source using PQL filters, so that those days were never considered in the calculations.
Here’s how to define constraints in the Optimization Engine UI:
Go to the section Constraints on the Optimization Engine page.
Click Add Constraints to add a new constraint.
Enter a name for the constraint.
In Iteration Index, enter the names of the columns from your data sources that you’re creating the constraint over. One constraint will be created for each combination of values from the columns that you choose as iteration indices. A column that you choose as an iteration index must be referenced somewhere in the multiplicands you’re going to use for this sum.
To filter the records from your data sources, click Add Index Filter, give the filter a name, and fill in the filter rule and the target number to compare against. You can duplicate and edit an index filter by clicking its context menu (the three vertical dots). You can also rename or delete an index filter from the context menu.
In Constraint Expression, select the operator for the constraint. Choose from
<=
(less than or equal to),==
(equal to), and=>
(greater than or equal to).Next build each summand for the constraint. Click Add Summands On Left Side or Add Summands On Right Side to add each summand, and give the summand a name. You can duplicate and edit a summand by clicking its context menu (the three vertical dots). You can also rename or delete a summand from the context menu.
If you want to create the sum over one or more indices for this summand, click Add Summation Index, and enter the name of a column from your data source. If the column has numeric values, you can enter a filter rule for it under Filter Rule to include only the matching records (if you don’t, all records are considered). A column that you choose as a summation index must be referenced somewhere in the multiplicands you’re going to use for this sum.
Click Add Multiplicands to add each multiplicand for this summand, and give the multiplicand a name. You can duplicate, rename, or delete a multiplicand by clicking its context menu (the three vertical dots). Select the type of multiplicand (constant, decision variable, or table), then fill in the additional information depending on the type:
Constant - Enter the name of a constant that you’ve defined in your optimization model. (Go back to the Constants section if you need to add one.) Use a constant of -1 if you want to turn the summand into a subtraction.
Variable - Enter the name of a decision variable that you’ve defined in your optimization model. (Go back to the Decision Variables section if you need to add one.)
Table - Enter the name of a data source that you’ve defined in your optimization model. (Go back to the Data Sources section if you need to add one.) Enter the name of the column that contains the values for the multiplicand. Then click Add Index Mapping and add each column in the data source that’s used as a summation index in this summand, or as an iteration index in this constraint.
Next step: Step 7: Define the objective function