A master-slave algorithm for the optimal control of continuous-time switched affine systems