Text this: Optimal control of switched dynamic systems and the method of moments