This paper proposes a two-layer improved invasive weed optimization (TIIWO) algorithm to overcome the disadvantages of the low quality of its initial population and the low optimization performance of IWO. The TIIWO algorithm includes dynamic corridor constraints (in its outer layer) and iterative reciprocating optimization (in its inner layer). The convergence of the TIIWO algorithm is achieved by minimizing the Schaffer function, which is characterized by its strong oscillatory behavior. In addition, the sensitivity of the main TIIWO parameters is analyzed using two methods, namely the revised Morris scheme and the Sobol index method. For experimental assessment, the TIIWO algorithm is firstly applied to a single reservoir. We investigate how the algorithm convergence is affected by four algorithm variants and parameter values. Then, the TIIWO algorithm is used to solve the problem of the optimal operation of cascade reservoirs. The results show that the TIIWO algorithm quickly and efficiently reaches the optimal operation of cascade reservoirs. In addition, this algorithm exhibits superior performance for high-dimensional, nonlinear and multi-constraint problems.