Music 270c: assignment 2

ASSIGNMENT 3. (due Monday, May 23): An example of optimization: travelling salesman problem on a series of chords. I've tried to design the proble so that the function to optimize has lots of non-optimal local minima. I started with this
collection of thirty five-note chords.
(these are five inversions each of six chords I chose intuitively, whose pitch classes collectively cover the octave 2-1/2 times.)

To set the problem up, define the "closeness" of any two chords to be the sum of the 25 "closenesses" of each pair of notes (one from the first chord, one from the second. The closeness of two notes is 1 if they're separated by one or two half-steps, but -1 if they're the same (i.e., you're punished for using common notes between successive shords -- this is to make the optimization problem trickier).

For example, the "closeness" of the chord (60 64 67 72 76) with (60 62 69 74 77) is 4: +5 for the pairs (60-62), (64-62), (67-69), (72-74), (76-74) and (76-77), and -1 for the pair (60-60).

In case it helps, my C function to evaluate this was:

#define NNOTE 5
int closeness(int *chord1, int *chord2)
{
    int sum = 0, i, j;
    for (i = 0; i < NNOTE; i++)
    {
        int thisvalue = 0;
        for (j = 0; j < NNOTE; j++)
        {
            if (chord2[j] == chord1[i])
                thisvalue -= 1;
            else if (chord2[j] < chord1[i] + 3 && 
                chord2[j] > chord1[i] - 3 )
                    thisvalue += 1;
        }
        sum += thisvalue;
    }
    return (sum);
}
The total closeness of the original progression is 40. If we permute this in the order
 29  0  9 11  2  6 26 24 25 13 23 17  1 21 15
 28  5  4  8 27 14  7  3 19 12 18 22 16 20 10
we get a sequence with closeness 162. (The chords are the same in a different order as show in this file.)

I was able to get quite a few solutions of goodness 162 and one of 163... how well can you do?