Placing Songs on a Cassette Tape Model: SONGS
In this model, we have seven songs, each with a different length, that must be placed on a cassette tape. The goal is to maximize the number of songs on one side of the tape without exceeding half of the total time of the music on the other side.
MODEL:
SETS:
SONG/1..7/: LENGTH, Y;
ENDSETS
! Maximize number of songs on short side;
MAX = @SUM( SONG: Y);
! It must contain at most half the music;
@SUM( SONG: LENGTH * Y) <= HALF;
! Compute half the length;
HALF = @SUM( SONG: LENGTH)/ 2;
! We want the Y's to be 0/1;
@FOR( SONG: @BIN( Y));
DATA:
LENGTH = 7, 5, 2, 2, 2, 2, 2;
ENDDATA
END
Model: SONGS