Text this: Graph contraction for physical optimization methods