Optimization algorithm with windows