Dynamical polysystems and optimization