I\'ve reduced my problem (table layout algorithm) to the following problem:
Imagine I have N variables X1, X2, ..., XN. I also have some
Minimizing x1 + x2 + ... where the xi satisfy linear constraints is called Linear Programming. It's covered in some detail in Wikipedia