N-body optimization