Optimal trajectory construction by integration of Hamiltonian dynamics in models of economic growth uder resource constraints