Tags:
create new tag
view all tags
---+<a name="top"></a> Constraints in AMPL 1 [[#describe][Description]] 1 [[#define][Defining a Constraint]] 1 [[#bounded][Bounded Constraints]] 1 [[#examine][Examining Constraints]] 1 [[#change][Changing Constraints]] ---++<a name="describe"></a> Description Mathematical programmes use constraints to describe the relationships that define a _feasible_ set of decision variables. [[#top][Return to top]] ---++<a name="define"></a> Defining a Constraint Constraints are defined using the =subject to= keywords, a label and possibly and indexing set, the =:= operator, two [[ExpressionsInAMPL][expressions]] and a [[LogicInAMPL][relational operator]]: <pre> subject to <conname> [{conset}] : <lhs_expression> <relational operator> <rhs_expression>; </pre> ---+++ Examples <pre> subject 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]; </pre> [[#top][Return to top]] ---++<a name="bounded"></a> Bounded Constraints AMPL 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 right-hand-side expressions.) <pre> subject to MeetRequirement {r in REQUIREMENTS}: Min[r] <= sum {i in INGREDIENTS} Contributes[i, r] * Amount[i] <= Max[r]; </pre> [[#top][Return to top]] ---++<a name="examine"></a> Examining Constraints We have already seen how to observe the value of variables using [[Variables in AMPL#examine][<tt>display <varname>;</tt>]]. For constraints, we can look at the value of the expression involving the variables (known as the _body_) by using <pre> display <conname>.body; </pre> 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 left-hand side. You can see the constraints in modified form by using <pre> expand <conname>; </pre> <img src="%ATTACHURLPATH%/examine_constraint.jpg" alt="examine_constraint.jpg" width='669' height='302' /> [[#top][Return to top]] ---++<a name="change"></a>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= keyword and the constraint name. <pre> drop <conname>; </pre> If you decide to reinstate the constraint, you can restore it. To restore a constraint, use the =restore= keyword and the constraint name. <pre> restore <conname>; </pre> [[#top][Return to top]] -- Main.MichaelOSullivan - 02 Mar 2008
E
dit
|
A
ttach
|
Watch
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-03-02
-
MichaelOSullivan
Home
Site map
Forum web
Main web
NDSG web
ORUA web
OpsRes web
Sandbox web
TWiki web
OpsRes Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
E
dit
A
ttach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback