A Command Script Example

Once again, we will make use of the staff scheduling model introduced in Using Sets to illustrate the use of a command script. Suppose, instead of one hot dog stand, our operations have expanded and we now have three hot dog stands: Pluto Dogs, Mars Dogs, and Saturn Dogs. Our staffing requirements at the three sites are:

Site

Mon

Tue

Wed

Thu

Fri

Sat

Sun

Pluto

20

16

13

16

19

14

12

Mars

10

12

10

11

14

16

8

Saturn

8

12

16

16

18

22

19

Running staffing models for all three sites is cumbersome and prone to error. We would like to automate the process by constructing a script file that runs all three staffing models automatically. To do this, we construct the following script file:

! Have LINGO echo input to the screen

SET ECHOIN 1

! Suppresses the standard solution report

SET TERSEO 1

! Begins input of a new model

MODEL:

SETS:

  DAYS / MON TUE WED THU FRI SAT SUN/:

   REQUIRED, START;

ENDSETS

 

DATA:

  REQUIRED = @FILE( 'PLUTO.LDT');

  @TEXT( 'PLUTO.TXT') = START;

ENDDATA

 

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

 

@FOR( DAYS( J):

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

 START( @WRAP( J - I + 1, 7)))

  >= REQUIRED( J)

);

 

@FOR( DAYS: @GIN( START));

END

! Solve Pluto Dogs model

GO

! Alter model for Mars

ALTER ALL 'PLUTO'MARS'

! Solve Mars model

GO

! Alter model for Saturn

ALTER ALL 'MARS'SATURN'

! Solve Saturn model

GO

! Restore parameters

SET TERSEO 0

SET ECHOIN 0

Command Script: DOGS.LTF

We use two SET commands to set two of LINGO's parameters. First, we set ECHOIN to 1, which causes LINGO to echo all command script input to the screen. This can be useful when you are trying to debug a script file. Next, we set TERSEO to 1. This causes LINGO to go into terse output mode, which suppresses the default solution report each time we solve a model.

Next, we include the MODEL: command to put LINGO into model input mode. It is important here to remember the MODEL: statement is a command. When LINGO encounters this command in a script file, it reads all subsequent text in the file as model text until it encounters the END command. This model then becomes the current model in memory.

The key feature to note in our model is the data section:

DATA:

  REQUIRED = @FILE( 'PLUTO.LDT');

  @TEXT( 'PLUTO.TXT') = START;

ENDDATA

We use the @FILE function to include the staffing requirements from an external file and we use the @TEXT function to send the values of the START attribute to a file.

After the END statement, we have a GO command to solve the model for the Pluto stand. We then include an ALTER command to change all occurrences of 'PLUTO' with 'MARS'. This command will change the data section to (changes in bold):

DATA:

  REQUIRED = @FILE( 'MARS.LDT');

  @TEXT( 'MARS.TXT') = START;

ENDDATA

Assuming we have the staffing requirements for the Mars stand in the file MARS.LDT, our model is then ready to run again. However, this time it will solve for the START values for the Mars hot dog stand. We include commands to do the same for the Saturn location as well. Finally, we have two SET commands to restore the modified parameters.

You can run this command script by issuing the File|Take Commands command in Windows versions of LINGO, or you can use the TAKE command in other versions. Once the command script has been executed, you will find the three solution files: PLUTO.TXT, MARS.TXT, and SATURN.TXT. These files will contain the optimal values for the START attribute for each of the three locations.