Title: LINGO Part II IE 311 Lab
1LINGOPart II (IE 311 Lab)
Spring 07
2Example I (Sets)
- Consider the following sets section
- SETS
- Product / A B /
- Machine / M N /
- Week / 1..2/
- Allowed (Product, Machine, week)
- ENDSETS
Primitive Sets
Derived Set
Index Member 1 (A, M, 1) 2 (A, M, 2) 3 (A,
N, 1) 4 (A, N, 2)
Index Member 5 (B, M, 1) 6 (B, M, 2) 7 (B,
N, 1) 8 (B, N, 2)
Allowed set membership
3Example II (Explicit member)
- Instead of following statement in Example I
- Allowed (Product, Machine, week)
- Consider the below statement
- Allowed (Product, Machine, week) / A M 1, B N
2/ - Explicit member list method is used to specify a
derived sets member list! - So, Allowed set members would have consisted of
the two members.
Index Member 1 (A, M, 1) 2 (B, N, 2)
Allowed set membership
4Example III (Membership Filter)
- Suppose, you have already defined a set called
TRUCK and each truck has an attribute called
CAPACITY. - You would like to derived a subset from TRUCK
that contain only those trucks capable of hauling
big load (greater than 5000 kg). - The TRUCK set is as following
- TRUCK / 1..100 / CAPACITY
- To define a subset of trucks capable of hauling
big load, you can use a Membership Filter as
follows - Heavy_Duty (TRUCK) CAPACITY (1) GT 5000
5Example III (Membership Filter) (cont.)
- Heavy_Duty (TRUCK) CAPACITY (1) GT 5000
Beginning of the membership filter
Greater than
Derived from
Set name
- Vertical bar character () is used to mark the
beginning of a membership filter. - The 1 symbol in the filter is known as a set
index placeholder. - When building a derived set that uses a
membership filter, LINGO generates all the
combinations of parent set members. Each
combination is then plugged into the membership
condition to see if it passes the test. The first
parent sets value is plugged into 1, the second
into 2, and so on.
6LINGO OPERATORS
- ARITHMETIC OPERATORS
- LINGO has five binary (two-operand)
- arithmetic operators
- Power
- Multiplication
- / Division
- Addition
- - Subtraction
7RELATIONAL LOGICAL OPERATORS
- In LINGO, you use relational and logical
operators to determine set membership and which
elements of a set are included in certain
operation such as summation. - In an expression involving both relational and
logical operators, relational operators have
higher precedence. - (that is, relational operators are evaluated
before logical operators).
8RELATIONAL OPERATORS
- Relational operators have numeric operands and
return logical results (TRUE or FALSE). - All relational operators are binary.
- LINGO has six relational operators.
- All relational operators have the same precedence.
9RELATIONAL OPERATORS
10LOGICAL OPERATORS
- Logical operators have logical operands (the
results of relational operations) and return
logical results. - Logical operators are used to connect relational
and logical expressions. - LINGO has three logical operators, listed here in
descending order of precedence.
11LOGICAL OPERATORS
12GENERAL MATHEMATICAL FUNCTIONS
13SET-LOOPING FUNCTIONS
- Set-Looping Function Operate over an entire set
and, with the exception of the _at_FOR operator,
produce a single result. - The syntax is as follows
set_operator (set_name condition expression)
14SET-LOOPING FUNCTIONS
- The condition part in the specification is
optional. The available functions are listed
below.
15VARIABLE DOMAIN FUNCTIONS
16Example IV(Use of Condition Qualifier )
- Lets use what we have learned till now in an
example. - Consider a direct model, which calculates the
reciprocal of a vector of numbers. Because the
reciprocal of zero is undefined, we want to
attempt the calculation only for nonzero numbers.
The following model accomplishes this by using
conditional qualifiers in the _at_FOR statements. A
conditional qualifier is prefaced by the
symbol.
17- MODEL
- ! The model calculates reciprocals of numbers
- SETS
- ! Ten numbers are in the vector VAL. The
reciprocals - are calculated and stored in the
corresponding elements - of RECIP
- NUM / 1..10 / VAL, RECIP
- ENDSETS
- ! Calculate reciprocal only for nonzero
numbers - _at_FOR (NUM(I) VAL(I) NE 0 RECIP(I) 1 /
VAL(I)) - ! If a number is Zero, make its reciprocal
arbitrarily Zero - _at_FOR (NUM(I) VAL(I) EQ 0 RECIP(I) 0)
- DATA
- ! Numbers for which to calculate the
reciprocals - VAL 2, 0, 8, 40, 1, 0, 0.333333, 50, 3,
0.2
18- The bold text in the model means that for all
members of set NUM whose attribute VAL is not
equal to zero and proceeded with the calculation
of reciprocal of that member (I) and assigning it
to the attribute RECIP(I).
19Example V (The Sailco Problem (page 99))
- MIN Z 400 (x1 x2 x3 x4)
- 450 (y1 y2 y3 y4)
- 20 (i1 i2 i3 i4)
- ST
- x140
- x240
- x340
- x440
- i1 10 x1 y1 40
- i2 i1 x2 y2 60
- i3 i2 x3 y3 75
- i4 i3 x4 y4 25
- it,yt,xt 0 (t 1,2,3,4)
20- xt number of sailboards produced during
regular-time during quarter t. - yt number of sailboards produced during
over-time during quarter t. - it number of sailboards on hand at end of
quarter t.
21(No Transcript)
22- Now, lets write the LP as a LINGO program
- First, we have to define SETS and attributes that
we will use in the model. As you can variables
are defined on quarters by index t. We can say
that our set name is Quarters. Each quarter has
unique regular time production, over-time
production, inventory and demand figures. These
are the attributes of the set Quarters. - Then, objective function and constraints must be
written. In this step, we use set looping
functions which ease our model editing. By this
way, we can write the same constraints in one
line by_at_FOR command. - Its like the FOR loop in PASCAL, with a little
bit different notation. The last part is DATA
section, which contains the figures of the
attributes. Now we are ready to write the model.
23- MODEL
- !SETS part of the model,
- TIMEPRERIOD NUMBER
- DEM DEMAND
- RP REGULAR TIME PRODUCTION
- OP OVER TIME PRODUCTION
- INV INVENTORY
- SETS
- Quarters/ Q1,Q2,Q3,Q4/TIME,DEM,RP,OP,INV
- ENDSETS
- !OBJECTIVE FUNCTION
- MIN_at_SUM (QUARTERS 400RP 450OP 20INV)
- !CONSTRAINTS
- !PRODUCTION CONSTRAINTS
- _at_FOR(QUARTERS (I) RP(I) lt40)
Set declaration part
Objective Function and Constraints part
Data declaration part
24- Thats all. The only difficult thing in this
example is the second constraint set which is
inventory balance constraint set. - In that part we try to say that, for all quarters
greater than 1, current quarters inventory
figure is equal to the last quarters inventory
figure plus regular and over time production
minus demand of current quarter. And if it is
equal to 1, inventory figure is equal to 10 (on
hand inventory) plus regular and over time
production minus demand of 1st quarter.