3. Provide or clarify parameter values if needed.
4. Edit code to enter actual Python custom code for the constraint using DOcplex API
For the exact and up-to-date step by step instructions to define a sample custom constraint, please refer to the dedicated article in the official IBM Cloud Pak for Data documentation.
Rule specification
Every goal and constraint needs to be displayed in the MA model. The text that is used to display a constraint or goal is called its verbalization. The predefined constraint templates that are available in MA domains already have meaningful verbalizations which describe it with plain English and references to your data model. Verbalizations allow a business user to understand an MA model just by looking at it and reading the goals and constraints.
Predefined constraint templates already come with appropriate verbalizations. For a user-defined custom constraint MA is unable to infer a reasonable verbalization, so it has to be explicitly provided in the first step of completing a custom constraint. Just put a sentence that describes the new constraint well. Parameters are enclosed in square brackets, i.e. [ ]. Any text outside of square brackets does not need to follow any further syntax and will be displayed literally.
Parameters
If you ever used MA before, you are already familiar with parameters. Look at the decision rule above. This is an example of a constraint template instance that has parameters. These pieces of the constraint instance verbalization are displayed in blue, are clickable, and can be changed. When you add a constraint instance from domain templates some parameters are automatically bound with an inferred value. The inference is the secret sauce of Modeling Assistant. When a parameter value cannot be reliably inferred they are displayed underlined in yellow. The user has to provide a value to complete the decision rule, otherwise the MA model is not ready to solve. Some parameters provide context to the decision rule (pointing to a concept within the data model) or exact criteria (e.g. "is less than" "5"). The role of parameters in custom constraints is similar. Some could provide context (reference to data model concepts) or exact criteria (numeric or string literals).
Parameters for custom constraints are defined within square brackets in the rule specification. When editing a rule specification, put in the brackets a phrase that closely describes the intended binding. The value could then be inferred. For example, if you enter "Assign all [subcontractors]" as the rule specification, the following would happen:
- The specification is automatically converted to canonical form with a parameter name and domain concept: "Assign all [parameter1: <Unary Resource>]". Note that the expression for parameter has been expanded. Now the parameter has a name ("parameter1") which is just a default name and an expected domain concept ("<Unary Resource>") inferred from the input for parameter. You don't need to worry about understanding the domain concepts that appear there. These are kind of generic types defined in