Professional Documents
Culture Documents
Christian Valente
Agenda
• Introduction
Introduction
• Simple introductory LP model
Example
– Mathematical representation
Syntax – AMPL representation
Architecture • Exploring AMPL syntax
– Modelling constructs
– Others...
• AMPL/AMPL Studio Architecture
1
Introduction
• Mathematical Programming:
– Modeler’s understanding of the problem leads to
Introduction “modeler’s form”
Example
– Solvers accept a different format: “algorithm’s
Syntax
form”
Architecture
– -> algebraic languages, AMPL being one of those
• It allows a separation between model and data,
recommended for most applications
AMPL
Model AMPL Model
Instance
Data
2
Simple LP model - Algebraic
• Maximizing profits of a steel company
Variables
Introduction
Maximize : c Xj
j P
j
Parameters
Indexing
Example Subject to : ( 1/a )X
jP
j j b
expressions
Syntax
Architecture
0 Xj uj j p
Where : P the types of products
aj tons of product j/hour produced
b hours available at the mill
cj profit per ton of product j
uj maximum tons of product j
Simple LP model-Components
• Set: PROD, identifies different products
• Parameters:
Introduction
– ratePROD: production rate
Example
Syntax
– profitPROD: profit rate
Architecture
– avail: availability of the mill
– marketPROD: upper limit in production
• Variables: MakePROD, values to be determined
• Objective function to be maximized
• Constraints to be satisfied
3
AMPL preliminary concepts
• Distinction between declarations and
definitions
Introduction • set PROD; declares the set
Example • set PROD := bands coils; defines set’s membership
Syntax
• It allows a separation between model and
Architecture
data, recommended for most applications
AMPL
Model Model
AMPL
Instance
Data
4
Simple LP model – AMPL data
Example
bands 200 25 6000
Syntax coils 140 30 4050 ;
Architecture param avail := 40;
Architecture
• There is a broad variety of set types and
operations:
• Members can be strings or numbers
• Ordered or unordered
• Can be defined by listing or computing their
members
5
AMPL syntax : sets of strings
• Set declaration:
set PROD;
Introduction • Usually all of the strings in a set of strings are
Example
representing the instances of the same kind of
Syntax
entity
Architecture
Unordered set of strings definition, data file:
set PROD := bands coils;
Unordered set of strings definition, model file:
set PROD := {“bands”, “coils”};
• Parametric:
param start integer; #defined in the data file
param end integer;
param interval integer;
set years := start .. end by interval;
6
AMPL syntax: set operations
• New sets can be created from existing ones:
set A := 1990 .. 2020 by 5;
Introduction set B := 2000 .. 2025 by 5;
Example
Syntax
A union B; # union of the two sets
Architecture
7
AMPL syntax: parameters
• In the models, only a symbolic description of
numerical values appears: a parameter
Introduction
• They can be scalar numbers matrices, or vectors
Example
indexed over an arbitrary amount of sets
Syntax • Data consistency checks can be integrated in the
Architecture parameters declarations:
param T > 1 integer; # will refuse any data that is not
integer or <=1
or in a separate statement:
check {p in PROD } : sum {i in ORIG} supply[i,p] =
sum {j in DEST} demand [j,p];
AMPL syntax:
indexing expressions
• Used whenever we specify the set over which
Introduction a model component is indexed, or the set over
Example which a summation runs
Syntax
• Simplest form:
Architecture
param a {P}; # will be referred as a[p]
param b {1 .. 4}; # will be referred as b[number]
param c {1 .. T}; # will be referred as c[number]
8
AMPL syntax:
indexing expressions
• Dummy indexes, to refer to the instances:
Introduction param f_min {FOOD} >=0;
Example variable X {p in PROD} >= 0, <= market[p];
Syntax
• Dummy indexes, used for index constraints
Architecture
and summations:
maximize Profit: sum { j in PROD} c[ j ] * x[ j ];
subject to limit { j in PROD} : 0 <= x[ j ] <= u[ j ];
AMPL syntax:
indexing expressions
• Conditional indexing:
Introduction • In declarations:
Example var amounthold {a in ASSETS : ifhold[a] =1} >= 0;
Syntax
Architecture
• In indexing:
subject to:
limitexpprod{ j in PROD : price[j] >= PRICELIMIT } :
0 <= buy[ j ] <= UPPERLIMIT;
9
AMPL syntax: scripting..
• AMPL is an interpreted language
• Thus there are commands that are not used to
Introduction define models, but that control options and the
Example
execution flow of the system
Syntax
Architecture
• Some of those commands are having an
equivalent in AMPLDev GUI
• Sequences of these commands can be into the
model file or in separate script files
10
AMPL syntax: display..
Example
• AMPL and AMPLDEV offer some data exploring
Syntax
facilities, but the use of display and indexed
Architecture
expression enables much more customized data
visualization
11
AMPL syntax: display..
• Displaying variables and parameters:
– display varname, ... , varname;
Introduction • Displaying indexed expressions:
Example
– display sum{p in PROD, t in 1..T}
Syntax revenue[p, t] * Sell[p, t];
Architecture
• Indexing display command:
– display {p in PROD}: {i in ORIG},
{j in DEST} Trans[i, j, p];
12
AMPL syntax: Modifying the
model
• Looping
– for {indexing exp} { body }
Introduction
Example
• Fix a variable to a value
Syntax – fix variablename := value;
Architecture • Drop constraint
– drop constraintname;
13
AMPL/AMPLDev Architecture
Script file
Introduction
AMPL
Example
AMPL Solver
Syntax
Models
Architecture
AMPL
Data
AMPL matrix
language DB (MPS or binary)
algebraic model
model instance
14