Encoding cloth manipulations using a graph of states and transitions