Optimal Control And Reinforcement Learning Of Switched Systems