Optimal control of a class of piecewise deterministic processes