ALTER Command
The ALTER command is used to edit the current model. The syntax of ALTER is:
ALTER [line_number | line_range | ALL] 'old_string'new_string'
where,
line_number | is the index of a single line to edit, |
line_range | is a range of lines to edit, |
ALL | means edit all the lines in the model, |
old_string | is the old string to search for and replace, and |
new_string | is the string to replace all occurrences of old_string with in the specified line range. |
In the following sample session, we read in a small knapsack model and perform two ALTER commands to modify the model:
: TAKE ALTER.LNG
: LOOK ALL
1]SETS:
2] THINGS /1..4/: VALUE, WEIGHT, X;
3]ENDSETS
4]DATA:
5] VALUE = 8 6 4 3;
6] WEIGHT = 66 44 35 24;
7]ENDDATA
8] MAX = @SUM( THINGS: VALUE * X);
9] @SUM( THINGS: WEIGHT * X) >= 100;
10] @FOR( THINGS: @BIN( X));
: !Change the direction of the constraint
: ALTER 9 '>='<='
9] @SUM( THINGS: WEIGHT * X) <= 100;
: !Change 'THINGS' to 'ITEMS' in ALL rows
: ALTER ALL 'THINGS'ITEMS'
2] ITEMS /1..4/: VALUE, WEIGHT, X;
8] MAX = @SUM( ITEMS: VALUE * X);
9] @SUM( ITEMS: WEIGHT * X) <= 100;
10] @FOR( ITEMS: @BIN( X));
: LOOK ALL
1]SETS:
2] ITEMS /1..4/: VALUE, WEIGHT, X;
3]ENDSETS
4]DATA:
5] VALUE = 8 6 4 3;
6] WEIGHT = 66 44 35 24;
7]ENDDATA
8] MAX = @SUM( ITEMS: VALUE * X);
9] @SUM( ITEMS: WEIGHT * X) <= 100;
10] @FOR( ITEMS: @BIN( X));
:
Note: | In addition to the single quote character (‘), LINGO also allows the use of the double quote character (") for delimiting the text fields of the ALTER command. |