Immune response-based algorithm for optimization of dynamic environments