protected void CreateBoxMatrixCore()
{
// The total number of boxes
var num = GetNumBoxes();
// calculate shortest paths
var itineraryMatrix = CalcItineraryMatrix(num);
// "Compress" the distance matrix into the box matrix format used
// by the engine. The format is like this:
// For each box (from 0 to num) there is first a byte with value 0xFF,
// followed by an arbitrary number of byte triples; the end is marked
// again by the lead 0xFF for the next "row". The meaning of the
// byte triples is as follows: the first two bytes define a range
// of box numbers (e.g. 7-11), while the third byte defines an
// itineray box. Assuming we are in the 5th "row" and encounter
// the triplet 7,11,15: this means to get from box 5 to any of
// the boxes 7,8,9,10,11 the shortest way is to go via box 15.
// See also getNextBox.
var boxMatrix = new List<byte>();
for (byte i = 0; i < num; i++)
{
boxMatrix.Add(0xFF);
for (byte j = 0; j < num; j++)
{
var itinerary = itineraryMatrix[i, j];
if (itinerary != InvalidBox)
{
boxMatrix.Add(j);
while (j < num - 1 && itinerary == itineraryMatrix[i, (j + 1)])
j++;
boxMatrix.Add(j);
boxMatrix.Add(itinerary);
}
}
}
boxMatrix.Add(0xFF);
_boxMatrix.Clear();
_boxMatrix.AddRange(boxMatrix);
}
}