Optimizing thermodynamic trajectories using evolutionary and gradient-based reinforcement learning