LINGO Part III (IE 311 – Lab)

23
LINGO Part III (IE 311 – Lab) Spring ‘07

description

LINGO Part III (IE 311 – Lab). Spring ‘0 7. Variables Doma in Function. Variables in a LINGO model default to being nonnegative and continuous. LINGO provides four variable domain function that allow you to override the default domain of a variable. - PowerPoint PPT Presentation

Transcript of LINGO Part III (IE 311 – Lab)

Page 1: LINGO Part  III (IE 311 – Lab)

LINGO

Part III (IE 311 – Lab)

Spring ‘07

Page 2: LINGO Part  III (IE 311 – Lab)

Variables Domain Function Variables in a LINGO model default to

being nonnegative and continuous.

LINGO provides four variable domain function that allow you to override the default domain of a variable.

@GIN Restricts a variable to being an integer value.

@BIN Makes a variable binary (i.e. 0 or 1).

@FREE Allows a variable to assume any real value, positive or negative.

@BND Limits a variable to fall within a finite range.

Page 3: LINGO Part  III (IE 311 – Lab)

@GIN By default, LINGO assume all variables in a model are continuous. In many

applications, fractional values may be undesirable. For example, you won’t be able two hire two-third of a person, or sell half an automobile.

In these instances, you will want to make use of the general integer variable domain function, @GIN.

@GIN(variable_name);

Page 4: LINGO Part  III (IE 311 – Lab)

i.e.:@GIN(X) makes the scalar variable X general integer

@GIN(Produce(5)) makes the variable Produce(5) general

integer

@FOR(DAY(I):@GIN(START(I))makes all the variables of the START attribute general integer

Page 5: LINGO Part  III (IE 311 – Lab)

@BIN

A binary variable is a special case of an integer variable .

@BIN(variable_name);

i.e.:

@BIN(X) makes the scalar variable, X, a binary integer

@BIN(Produce(5))

makes the variable Produce(5) variable binary

@FOR(DAY(I):@BIN(START(I))

makes all the variables of the START attribute

binary

Page 6: LINGO Part  III (IE 311 – Lab)

@FREE

It removes the lower bound of zero and lets a variable take negative value.

@FREE(variable_name);

i.e.:

@FREE(X)makes the scalar variable, X, free

@FREE(Produce(5))

makes the variable Produce(5) free

@FOR(DAY(I):@FREE(START(I))

makes all the variables of the START attribute

free

Page 7: LINGO Part  III (IE 311 – Lab)

@BND

It lets you, set specific upper and lower bounds on a variable.

@BND(lower_bound, variable_name, upper_bound);

i.e

@BND(-1,X,1) constrains X to lie in the interval

[-1,1]

@BND(100, QUANTITY(4),200)

constrains QUANTITY(4) to fall within

100 to 200

Page 8: LINGO Part  III (IE 311 – Lab)

@SUM Consider the following set:

SETS:VENDORS/V1,V2,V3,V4,V5/:DEMAND;

ENDSETSDATA:

DEMAND=5 1 3 4 6;ENDDATA

We could sum up the values of the DEMAND attribute by adding the following expression after the ENDDATA statement:

TOTAL_DEMAND = @SUM(VENDORS(J):DEMAND(J));

Page 9: LINGO Part  III (IE 311 – Lab)

LINGO evaluates the @SUM function by first initializing an internal accumulator zero.

Then, it begins looping over the members in the VENDORS set. The set index variable J, is set to the first member of VENDORS (i.e., V1) and DEMAND(V1) is then added to the accumulator …

The value of the sum is then stored into the TOTAL_DEMAND variable.

Suppose we want to sum the first three elements of DEMAND:

DEMAND_3 = @SUM(VENDORS(J)|J #LE# 3: DEMAND(J));

Page 10: LINGO Part  III (IE 311 – Lab)

@MIN & @MAX

@MIN and @MAX functions are used to find the minimum and maximum of an expression over members of a set.

Again, consider the following set:

SETS:VENDORS/V1,V2,V3,V4,V5/:DEMAND;

ENDSETSDATA:

DEMAND=5 1 3 4 6;ENDDATA

Page 11: LINGO Part  III (IE 311 – Lab)

@MIN & @MAX (cont).

To find the minimum and the maximum DEMAND, the following two lines are needed:

MIN_DEMAND = @MIN(VENDORS(J):DEMAND(J));

MAX_DEMAND = @MAX(VENDORS(J):DEMAND(J));

Suppose we had just wanted to compute the minimum and maximum values of the first three elements of DEMAND:

MIN_3 = @MIN(VENDORS(J) |J #LE# 3 : DEMAND(J));

MAX_3 = @MAX(VENDORS(J) |J #LE# 3 : DEMAND(J));

Page 12: LINGO Part  III (IE 311 – Lab)

Example:

Suppose you run the popular Pluto Dogs hot dog stand that is open seven days a week. You hire employees to work a five-day workweek with two consecutive days off. Each employee receives the same weekly salary. Some days of the week are busier than others and, based on past experience, you know how many workers are required on a given day of the week. In particular, your forecast calls for these staffing requirements:

Day Mon. Tue. Wed. Thu. Fri. Sat. Sun

Staff Required 20 16 13 16 19 14 12

Page 13: LINGO Part  III (IE 311 – Lab)

Example: (cont)

You need to determine how many employees to start on each day of the week in order to minimize the total number of required employees, while still meeting or exceeding staffing requirements.

Page 14: LINGO Part  III (IE 311 – Lab)

Solution: What are the relevant sets and their attributes:

We have a single primitive set, the days of the weeks We will concerned with two attributes of the DAY set:

The number of staff required on each day The number of staff to start on each day

Page 15: LINGO Part  III (IE 311 – Lab)

DATA:

REQUIRED = 20 16 13 16 19 14 12;

ENDDATA

It’s useful to determine what attributes are data and what are decision variables.

REQUIRED attribute is given to us Data START attribute is something we need to

determine Decision Variable

SETS:

DAYS / MON, TUE, WED, THU, FRI, SAT, SUN / : REQUIRED, START;

ENDSETS

Solution (cont.):

Page 16: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

Objective:

Our objective is to minimize the sum of the total number of employees we start during the week.

MIN = @SUM(DAYS(I) : START(I));

i

iSTARTMinimize

Page 17: LINGO Part  III (IE 311 – Lab)

Solution (cont.): Constraint:

We must have enough staff on duty each day to meet or exceed staffing requirements.

Staff on duty today Staff required today

for each day of the week

RHS = The quantity REQUIRED(I)

LHS = No. starting today + No. starting 1 day

ago + No. starting 2 days ago +No. starting 3

days ago + No. starting 4 days ago

Page 18: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

It says, for each day of a week, the sum of the employees starting over the five day period beginning four days ago and ending today must be greater than or equal to the required number of staff for the day.

@FOR(DAYS(J):@SUM(DAYS(I)|I#LE#5:START(J-I+1))>=REQUIRED(J));

DAYSjforREQUIREDSTARTjji

ji ,4

Page 19: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

IF you try to solve our model, we get the error message:

To see why we get this error message, consider what happens on Thursday (Index 4 in our DAYS set):

Page 20: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

START(4-1+1) + START(4-2+1) + START(4-3+1) + START(4-4+1) + START(4-5+1) >= REQUIRED(4);

START(4) + START(3) + START(2) + START(1) + START(0) >= REQUIRED(4)

We would like to have any indices less than or equal to 0

wrap around to the end of the week. (0 would correspond

to Sunday (7), -1 to Saturday (6) and so on)

Page 21: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

LINGO has a function called @WRAP. It takes two argument:

INDEX

LIMIT

@WRAP will subtract or add LIMIT to INDEX until it falls in the range 1 to LIMIT:

@FOR(DAYS(J):@SUM(DAYS(I)| I #LE# 5 :

START(@WRAP(J-I+1,7))) >= REQUIRED(J));

Page 22: LINGO Part  III (IE 311 – Lab)

Solution (cont.):

Page 23: LINGO Part  III (IE 311 – Lab)

Solution (cont.):