Entanglement cooling algorithm