Select Constraints and Variables
In this article we will explore how you can control the constraints or variables used in a math program. Then we’ll show an example of how to use this method to analyze infeasibility of a mathematical program.
A sample declaration of a math program is shown below.
MathematicalProgram Sample_Math_Program {
Objective: ObjFunc;
Direction: minimize;
Constraints: AllConstraints;
Variables: AllVariables;
Type: Automatic;
}
Objectivespecifies which variable is the objective function of the math program.Directionspecifies whether you want to minimize or maximize the objective function.Constraintsspecifies which set of constraints should be considered. In this case,AllConstraintswill be considered.Variablesspecifies which set of variables should be considered. In this case,AllVariableswill be considered.Typespecifies what kind of a problem the math program is, e.g., a linear program, an integer program, and so on. The default optionAutomaticsuffices in most cases and is recommended.
Note
AllConstraints and AllVariables
are model related predeclared identifier Sets,
containing all constraints and all variables defined in your model.
You may have multiple mathematical program identifiers in the same project, subject to different sets of constraints and variables. For example, it can be used in a sequential goal programming problem where the solution of the first problem is provided as input to the second problem.
Default Constraints and Variables
When you solve a mathematical program (or generate it via the GMP functions), AIMMS will use the values of the Constraints and Variables attributes of the mathematical program identifier to determine which symbolic variables and constraints should actually be considered in the model.
The default values of Constraints and Variables attributes are the predefined sets AllConstraints and AllVariables respectively. AllConstraints contains all the constraints declared in your AIMMS project and similarly, AllVariables contains all the variables.
Variables with Definition
For variables with a definition, AIMMS will actually generate both the variable and an additional equality constraint. For example, if you have the variable X that has Y + Z in its definition attribute:
Variable X {
Range: free;
Definition: Y+Z;
}
AIMMS will generate:
Variable
XEquality constraint
X_definitionasX = Y + Z
So, any variable with a definition (like X) will appear in both the predeclared sets AllConstraints and AllVariables.
Selecting Constraints or Variables
To select the constraints to be applied in a math program, you can create a set as a subset of AllConstraints and use that set in the declaration of the math program instead of AllConstraints.
Likewise, you can create a subset of AllVariables and use it in the declaration of the math program.
The example below shows two sets, ModelConstraints and ModelVariables, used in the math program Sample_Math_Program.
Set ModelConstraints {
SubsetOf: AllConstraints;
Definition: AllConstraints*Section_or_Declaration_to_Optimize;
}
Set ModelVariables {
SubsetOf: AllVariables;
Definition: AllVariables*Section_or_Declaration_to_Optimize;
}
MathematicalProgram Sample_Math_Program {
Objective: ObjFunc;
Direction: maximize;
Constraints: ModelConstraints;
Variables: ModelVariables;
Type: Automatic;
}
You can either manually select the constraints and variables to be included in these subsets or use the definition, as shown above, to include all the constraints and variables present in a particular section or declaration section.
Using a definition makes it easy to scale the project: any new constraint or variable added inside Section_or_Declaration_to_Optimize is automatically added to the subset and used in generating the math program. You do not need to select variables with a definition in both the subsets.
Where That Section Name Comes From
Section_or_Declaration_to_Optimize above is not a set you declare. Every Section and
DeclarationSection node you create in the Model Explorer is automatically available inside the model as
a subset of AllIdentifiers, named after the node with spaces replaced by underscores, and
holding every identifier declared beneath it.
That is what makes the model tree itself the selection mechanism. Intersecting the implicit set with
AllConstraints keeps only the constraints declared under that node, and intersecting with
AllVariables keeps only the variables.
The example project linked at the top is built exactly this way. Its Model Explorer holds four declaration sections:
1Input_Declarations
2 s_Products, s_Markets, p_Demand, p_PlantMinCapacity, p_PlantMaxCapacity
3Mathematical_Program_declarations
4 v_obj, v_Produce, v_Deliver
5 c_DeliverDemand, c_PlantMaxCapacity, c_ProductBalance
6 s_mpVars, s_mpCons, mp_produceDeliver
7Attic
8 c_PlantMinCapacity
9Reporting_declarations
10 s_AcceptableSolutionStates
and its two subsets name the second of them:
1Set s_mpVars {
2 SubsetOf : AllVariables;
3 Definition : AllVariables * Mathematical_Program_declarations;
4}
5
6Set s_mpCons {
7 SubsetOf : AllConstraints;
8 Definition : AllConstraints * Mathematical_Program_declarations;
9}
Read line 3 as “the variables among the identifiers declared under
Mathematical_Program_declarations”. Nothing lists the three constraints by name, and nothing needs
updating when a fourth is added: declaring it inside that node is what puts it in the mathematical program.
Because both sets carry a Definition rather than an assignment, AIMMS recomputes them whenever the
model changes. Dragging a declaration from one node to another in the Model Explorer therefore changes
what the mathematical program contains, without touching the mathematical program declaration or any
procedure. That is precisely the move the Attic step below relies on.
Letting End Users Toggle Constraints from the UI
The section-based definition above is a development-time choice. To put the same selection in the hands of an
end user, drive the subset from a binary parameter over AllConstraints instead of from a section:
Parameter p_selectConstraint {
IndexDomain : IndexConstraints;
Range : binary;
}
Set ModelConstraints {
SubsetOf : AllConstraints;
Definition : { IndexConstraints | p_selectConstraint(IndexConstraints) };
}
Expose p_selectConstraint on a WebUI page as a set of toggles (one per constraint you want the user to
control) and the mathematical program’s constraint set follows whatever they switch on, with no change to
the model or to the mathematical program declaration.
The same construction applied to AllVariables toggles variables. Remember, per the section above,
that a variable carrying a Definition also appears in AllConstraints, so switching such a
variable off may require toggling it in both places.
Analyzing Infeasibility of a Mathematical Program
The same method gives you a quick way to find out why a mathematical program is infeasible.
We will use the example project linked at the top of this article. Open it and follow the three steps below.
Run
MainExecution. The Progress Window shows “Model infeasible” and there is a warning in the error/warning window.
Move the declaration of the constraint
c_PlantMinCapacityto the declaration section “Attic” (that famous place where you put stuff you don’t use, but don’t want to throw away).
Run
MainExecutionagain. The Progress Window now shows “Model feasible”.
Under the hood, the set s_mpCons is recomputed removing the constraint c_PlantMinCapacity from the mathematical program.