1. A two dimensional compaction method implemented in a computer, comprising: receiving a plurality of layout elements; determining and allocating one or more position variables to each of the plurality of layout elements, wherein the position variables determine the location of the edges or points of the plurality of layout elements and are used to update the layout; constructing a linear system of constraints using the position variables, wherein the constraints describe the relationships between edges or points of the plurality of layout elements; establishing a linear objective function that will be optimized as part of the two dimensional compaction that is a weighted sum of the allocated position variables; and solving the linear system of constraints to compact and optimize in two dimensions simultaneously.