Mathematical Programming for the Dynamics of Opinion Diffusion