|
MyObjectiveFunction
Setting It Up
Let's start by looking at how we'll initialize this objective function. The complete source is available, but since it's so big, let's look at it piece by piece again:
The constructor expects to be passed that nx2 matrix of customer locations that we generated in the main program. We then create a matrix of distances among these customers in the createMatrix(...) method. Let's look at that:
In fact we used two methods: createMatrix(...) and norm(...). The second method simply applies the Pythagorean theorem to the two sets of (x,y) coordinates. The matrix is symmetric, so we could get away with creating a double matrix that was not square, but then we'd have to worry about making sure we called for [i][j] instead of [j][i]: too confusing. The little extra memory needed for a full, square matrix is worth the fewer headaches. We still haven't seen how we're going to evaluate a solution, so we'll look at that next. |
||