Line: 1 to 1  

Added:  
> > 
Constraints in AMPL
DescriptionMathematical programmes use constraints to describe the relationships that define a feasible set of decision variables.
Defining a Constraint
Constraints are defined using the subject to <conname> [{conset}] : <lhs_expression> <relational operator> <rhs_expression>;
Examplessubject to LimitedResin: sum {s in SURFBOARDS} Resin[s] * Production[s] <= TotalResin; # Must conserve flow in the network (steel cannot disappear!) subject to ConserveFlow {n in NODES}: sum {m in NODES: (m, n) in ARCS} Shipment[m, n] + Supply[n] = sum {p in NODES: (n, p) in ARCS} Shipment[n, p] + Demand[n] + Storage[n];
Bounded ConstraintsAMPL also allows bounded constraints to be defined. These constraints consist of an expression and a lower and upper bound. The lower and upper bounds may also be expressions, but may only involve parameters. (Note Regular constraints may have variables in either the left or righthandside expressions.)subject to MeetRequirement {r in REQUIREMENTS}: Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r];
Examining ConstraintsWe have already seen how to observe the value of variables using display <varname>;. For constraints, we can look at the value of the expression involving the variables (known as the body) by using display <conname>.body; For bound constraints this represents the expression in the middle, for other constraints this represents the value of the constraint expression with all variables shifted to the lefthand side. You can see the constraints in modified form by using expand <conname>;
Changing Constraints
Once constraints have been added to a model you cannot remove them. However, you can drop a given constraint from the model. To drop a constraint, use the drop <conname>;If you decide to reinstate the constraint, you can restore it. To restore a constraint, use the restore keyword and the constraint name.
restore <conname>;  MichaelOSullivan  02 Mar 2008
