Numerical Methods for Simulation and Optimization of Piecewise Deterministic Markov Processes