A variational solution of unsteady state optimization problems in complex chemical plants