Application of a Heuristic Model (PSO—Particle Swarm Optimization) for Optimizing Surface Water Allocation in the Machángara River Basin, Ecuador
Abstract
1. Introduction
2. Materials and Methods
2.1. Study Area
2.1.1. The Machángara River Basin
2.1.2. Reservoirs, Electricity Production, and Other Uses of Water
2.2. PSO Model for Optimization
2.2.1. Overview of PSO
- where
- w is the inertia weight,
- and are cognitive and social coefficients,
- and are random values between 0 and 1,
- is the best position found by particle i,
- is the best position found by the entire swarm.
2.2.2. Constraint Handling in PSO
2.2.3. Problem Modeling with Pymoo
2.3. Justification for Using PSO
Preprocessing Techniques for PSO Implementation
- Data Filtering and Temporal Segmentation: Hydrological data provided by PROMAS were segmented into three distinct periods—calibration (1998–2001), validation (2002–2003), and execution (2004–2005). This ensured temporal consistency and allowed each phase to be modeled independently within realistic boundaries.
- Variable Encoding and Structure Mapping: The river basin configuration, reservoir characteristics, and water demands were encoded using dictionaries and lists in Python. Each variable was indexed to facilitate rapid access and constraint formulation during the runtime.
- Dimensional Scaling: Variables such as daily water flow rates and reservoir levels were normalized based on statistical ranges derived from historical data. This prevented numerical instability during the swarm evaluations and improved the efficiency of parameter tuning.
- Matrix Construction for Particle Evaluation: A multidimensional matrix (X) was constructed, with each row representing a particle and each column corresponding to a problem variable. This structure was essential for performance tracking and memory management during PSO iterations.
- Constraint Encoding: Equality and inequality constraints were algorithmically structured as vectorized functions in Python. This enabled fast evaluation and seamless integration with Pymoo’s repair function, which attempts to restore feasibility in violated constraint sets.
- Boundary Definition and Search Space Restriction: Each variable was assigned upper and lower bounds informed by operational ranges and ArcSWAT benchmarks. These bounds were strictly enforced to reduce unnecessary exploration and enhance convergence reliability.
2.4. Implementation Details
2.4.1. Variable Structure and Encoding
- Matrix Representation: The swarm is represented as a matrix X, where each row corresponds to a particle and each column to a decision variable.
- Variable Indexing: Python dictionaries are used to map variable positions, enabling efficient access and constraint construction. This is particularly important given the high dimensionality—up to 590,338 variables in the calibration stage.
- Time-Dependent Modeling: Variables were indexed by time step, sector, and spatial unit, allowing dynamic modeling of water allocation throughout the study period.
2.4.2. PSO Configuration
2.4.3. Constraint Handling
- Equality Constraints: Represented as , these include mass balance equations and policy requirements.
- Inequality Constraints: Represented as , these encompass capacity limits, minimum flow thresholds, and sectoral priorities.
- Repair Function: A custom repair function modifies infeasible solutions by adjusting variable values to better satisfy constraints. While this improves feasibility, it does not guarantee full compliance.
2.4.4. Computational Considerations
2.5. PSO Extension with Mixed Integer Linear Programming (MILP)
- Embedding MILP solvers for local refinement of PSO-generated solutions.
- Designing cooperative frameworks, where MILP handles discrete decisions and PSO optimizes continuous variables.
- Implementing adaptive control mechanisms to switch between MILP and PSO based on convergence diagnostics or constraint satisfaction metrics.
2.5.1. Defining Candidate Reservoir Locations
2.5.2. Modeling the MILP Problem with PSO
- Storage capacity
- Minimum volume required to ensure sustainable operation
2.5.3. Water Input, Reservoir Characteristics, and Water Demand
3. Results
3.1. Calibration, Validation, and Application of the Model
- Intel® Core™ i7-7700HQ CPU @ 2.80GHz
- 32 GB RAM
- Operating System: Windows
- Programming Language: Python 3.13.5
- PSO Implementation Package: Pymoo [15]
- Number of particles: 25
- Number of iterations: 30
- Number of threads: 16
3.1.1. Calibration
3.1.2. Validation
3.1.3. Execution
3.1.4. Penalties
Summary of Key Findings
- Extreme penalty costs: The PSO model resulted in a total penalty of approximately EUR 165 billion, indicating major failures in satisfying water allocation constraints.
- Main contributors to penalty accumulation:
- –
- Overflow in demand segments generated the highest penalty: over EUR 71 billion.
- –
- Flooding claims and flooding in river sections together exceeded EUR 76 billion.
- –
- Violations of reservoir capacity constraints added more than EUR 6.5 billion.
- Unmet water demand:
- –
- Approximately 3696 of demand went unsatisfied.
- –
- Although relatively small in volume, these unmet demands still contributed to penalties and reflect PSO’s limitations in constraint handling.
- Mismatch with seasonal behavior:
- –
- Reservoir volumes failed to reflect realistic hydrological patterns, suggesting poor adaptability of PSO under time-dependent dynamics.
- Constraint violation issues:
- –
- PSO struggled with equality constraints, even when repair functions were applied, leading to frequent violations across multiple stages.
- Comparison with LP/MILP:
- –
- Linear and MILP models performed significantly better in constraint compliance and penalty minimization.
- –
- PSO’s attempt to construct additional reservoirs paradoxically increased the total penalty, a counterintuitive and unresolved outcome.
3.1.5. Convergence Analysis
4. Discussion
4.1. Definition of Statistical Indicators for Model Comparison
- Average and RMSD of constraint violations at each stage (calibration, validation, and execution).
- Total RMSD in each stage for the volume of water in river segments, compared to the values simulated by ArcSWAT.
- Average volume of unmet demand and corresponding penalty value in euros.
4.2. Comparison of PSO with Exact Mathematical Models (LP and MILP)
4.2.1. Comparison with LP
4.2.2. Comparison with MILP and PSO: Number of Optimal Reservoirs
4.3. Benchmarking Framework for PSO-Based Water Allocation Optimization
4.3.1. Benchmark Function Suite
- Unimodal functions (e.g., Sphere, Schwefel 2.22) assess convergence speed and exploitation capability.
- Multimodal functions (e.g., Rastrigin, Ackley, Griewank) evaluate exploration behavior and resilience to local optima.
- Hybrid composition functions simulate real-world complexity by combining multiple landscape features.
4.3.2. Performance Metrics
- Best-so-far fitness value: Tracks the minimum objective value achieved over time.
- Mean and standard deviation of final fitness: Reflects consistency and robustness across multiple runs (typically 30).
- Convergence speed: Defined as the number of iterations required to reach 90% of the best-known solution.
- Swarm diversity: Quantified using positional entropy and average pairwise Euclidean distance among particles, providing insight into the balance between exploration and exploitation.
4.3.3. Comparative Metaheuristic Context
- Identical benchmark functions and dimensionality
- Consistent stopping criteria and population sizes
- Parameter tuning via grid search or adaptive schemes
4.3.4. Visualization and Diagnostic Tools
- Convergence plots: Illustrate the trajectory of the best fitness value across iterations, revealing phases of rapid improvement, stagnation, or oscillation.
- Diversity overlays: Superimpose swarm diversity metrics (e.g., positional entropy, pairwise distances) to identify transitions from exploration to exploitation.
- Annotated transitions: Highlight key behavioral shifts, such as clustering around local optima or re-exploration events triggered by repair or mutation strategies.
5. Conclusions
- Quantifying PSO’s limitations across calibration, validation, and execution phases.
- Evaluating constraint-handling strategies, such as repair functions, within high-dimensional search spaces.
- Establishing empirical benchmarks to inform the development of future hybrid or adaptive heuristic models.
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Liu, P.; Zou, H.; Guo, S.; Zeng, Y.; Shen, Y.; Liu, D.; Zhang, J.; Xiong, L.; Tian, J. Optimisation of water-energy nexus based on its diagram in cascade reservoir system. J. Hydrol. 2018, 569, 347–358. [Google Scholar] [CrossRef]
- Yang, Y.; Luo, Q.; Ye, G. Optimization of water allocation system at the river basins. In Proceedings of the 2018 14th International Conference on Natural Computation, Fuzzy Systems and Knowledge Discovery (ICNC-FSKD), Huangshan, China, 28–30 July 2018; pp. 482–488. [Google Scholar] [CrossRef]
- Haro, D.; Paredes, J.; Solera, A.; Andreu, J. A Model for Solving the Optimal Water Allocation Problem in River Basins with Network Flow Programming When Introducing Non-Linearities. Water Resour. Manag. 2012, 26, 4059–4071. [Google Scholar] [CrossRef]
- Veintimilla-Reyes, J.; Meyer, A.D.; Cattrysse, D.; Tacuri, E.; Vanegas, P.; felipe Cisneros; Orshoven, J.V. MILP for Optimizing Water Allocation and Reservoir Location: A Case Study for the Machángara River Basin, Ecuador. Water 2019, 11, 1011. [Google Scholar] [CrossRef]
- Lindfield, G.; Penny, J. Numerical Methods Using MATLAB®; IEEE: New York, NY, USA, 2009. [Google Scholar]
- Labadie, J.W. Optimal Operation of Multireservoir Systems: State-of-the-Art Review. J. Water Resour. Plan. Manag. 2004, 130, 93–111. [Google Scholar] [CrossRef]
- Veintimilla-Reyes, J. Mathematical programming for the support of river water management: Water allocation and reservoir location. KULeuven 2022. [Google Scholar]
- PROMAS. Programa para el Manejo del Agua y el Suelo. 2019. [Google Scholar]
- ETAPA, E.P. ETAPA EP—ETAPA EP—Servicios de Telefonía, Televisión, Internet, Agua Potable, Alcantarillado de Cuenca—Ecuador > Principal > Agua Potable, n.d. 2022. [Google Scholar]
- Villavicencio Riera, V.E.; Chávez Ochoa, L.M. Estudio Arqueológico en las Cuencas Media y Bajas del río Machángara. Available online: https://repositorioslatinoamericanos.uchile.cl/handle/2250/1110239?show=full (accessed on 18 June 2025).
- Jerves-Cobo, R.; Everaert, G.; Iñiguez-Vela, X.; Córdova-Vela, G.; Díaz-Granda, C.; Cisneros, F.; Nopens, I.; Goethals, P.L.M. A methodology to model environmental preferences of EPT taxa in the Machangara River Basin (Ecuador). Water 2017, 9, 195. [Google Scholar] [CrossRef]
- Kennedy, J.; Eberhart, R. bls gov. In Particle Swarm Optimization; Technical report; 1995. [Google Scholar]
- Shi, Y.; Eberhart, R. Modified particle swarm optimizer. In Proceedings of the IEEE Conference on Evolutionary Computation, ICEC, Anchorage, AK, USA, 4–9 May 1998; IEEE: New York, NY, USA, 1998; pp. 69–73. [Google Scholar] [CrossRef]
- Clerc, M.; Kennedy, J. The particle swarm—Explosion, stability, and convergence in a multidimensional complex space. IEEE Trans. Evol. Comput. 2002, 6, 58–73. [Google Scholar] [CrossRef]
- Blank, J.; Deb, K. Pymoo: Multi-Objective Optimization in Python. IEEE Access 2020, 8, 89497–89509. [Google Scholar] [CrossRef]
- Lin, I.L.; Fraser, S. Particle swarm optimization for solving constraint satisfaction problems. 2002. [Google Scholar]
- Veintimilla-Reyes, J.; Meyer, A.D.; Cattrysse, D.; Orshoven, J.V. From Linear Programming Model to Mixed Integer Linear Programming Model for the Simultaneous Optimisation of Water Allocation and Reservoir Location in River Systems. Proceedings 2018, 2, 594. [Google Scholar] [CrossRef]
- Talbi, E.G. Metaheuristics: From Design to Implementation; John Wiley & Sons: Hoboken, NJ, USA, 2009; p. 593. [Google Scholar]
- Boussaïd, I.; Lepagnot, J.; Siarry, P. A survey on optimization metaheuristics. Inf. Sci. 2013, 237, 82–117. [Google Scholar] [CrossRef]
- Veintimilla-Reyes, J.; Meyer, A.D.; Cattrysse, D.; Orshoven, J.V. A linear programming approach to optimise the management of water in dammed river systems for meeting demands and preventing floods. Water Sci. Technol. Water Supply 2017, 18, 713–722. [Google Scholar] [CrossRef]
- Jayaram, M.A. How should I design PSO particles for large number of decision variables? 2024. [Google Scholar]
- Aguilar, A.S. GUIA PRACTICA “CONSTRUCCIÓN E INTERPRETACIÓN DE INDICADORES ESTADÍSTICOS” Preparado por: Mg. Aníbal Sánchez Aguilar. 2004. [Google Scholar]
- Indicadores. Indicadores. 2024. [Google Scholar]
- Li, X.; Omidvar, M.N.; Qin, K.; Tang, K.; Omidvar, M.N.; Yang, Z. Benchmark Functions for the CEC’2013 Special Session and Competition on Large-Scale Global Optimization; Technical report; 2013. [Google Scholar]
- Liang, J.; Runarsson, T.P.; Mezura-Montes, E. Problem Definitions and Evaluation Criteria for the CEC 2006 Special Session on Constrained Real-Parameter Optimization; Technical report; 2006. [Google Scholar]
- Eiben, A.E.; Smith, J.E. Introduction to Evolutionary Computing; Springer: Berlin/Heidelberg, Germany, 2003. [Google Scholar] [CrossRef]
- Das, S.; Suganthan, P.N. Differential evolution: A survey of the state-of-the-art. IEEE Trans. Evol. Comput. 2011, 15, 4–31. [Google Scholar] [CrossRef]
- Derrac, J.; García, S.; Molina, D.; Herrera, F. A practical tutorial on the use of nonparametric statistical tests as a methodology for comparing evolutionary and swarm intelligence algorithms. Swarm Evol. Comput. 2011, 1, 3–18. [Google Scholar] [CrossRef]
- Zhang, J.; Zhan, Z.h.; Lin, Y.; Chen, N.; Gong, Y.j.; Zhong, J.h.; Chung, H.S.; Li, Y.; Shi, Y.h. Evolutionary Computation Meets Machine Learning: A Survey. IEEE Comput. Intell. Mag. 2011, 6, 68–75. [Google Scholar] [CrossRef]
- Lai, V.; Huang, Y.F.; Koo, C.H.; Ahmed, A.N.; El-Shafie, A. A Review of Reservoir Operation Optimisations: From Traditional Models to Metaheuristic Algorithms. Arch. Comput. Methods Eng. 2022, 29, 3435–3457. [Google Scholar] [CrossRef] [PubMed]
Stage | Variables | Equality Constraints (=0) | Inequality Constraints () |
---|---|---|---|
Calibration (1998–2001) | 590,338 | 280,615 | 46,462 |
Validation (2002–2003) | 293,552 | 139,532 | 23,070 |
Execution (2004–2005) | 293,974 | 139,725 | 23,102 |
Parameter | Value | Description |
---|---|---|
Swarm Size | 25 particles | Number of candidate solutions evaluated per iteration |
Inertia Weight (w) | 0.7 | Balances global exploration and local exploitation |
Cognitive Coefficient () | 1.5 | Influence of the particle’s personal best position |
Social Coefficient () | 1.5 | Influence of the global best position across the swarm |
Max Iterations | 293,974 | Termination criterion based on iteration count |
Node | Type | Initial Volume [hm3] | Max Capacity [hm3] | Min Capacity [hm3] | Cost (€/2 years) |
---|---|---|---|---|---|
1, 2, 3 | Candidate | 2.6 | 13 | 1.3 | 195,000 |
4–16 | Candidate | 2.6 | 13 | 2.0 | 195,000 |
17 | R1 | 5.0 | 6.15 | 1.23 | 150,000 |
18 | R2 | 15.0 | 16.3 | 3.26 | 215,000 |
19 | R3 | 0.7 | 1.0 | 0.2 | 100,000 |
20 | R4 | 0.7 | 1.0 | 0.2 | 100,000 |
Parameter | Default Value |
---|---|
Loss () | 0.001 |
Loss in flooded water () | 0.01 |
Time delays () | |
Time delays in flooded water () | 0.001 |
Minimum water to stay () | 0.01 |
Maximum water to stay () | 0.1 |
Loss in reservoirs () | 0.001 |
Node | Use | Value (hm3/day) |
---|---|---|
D1 | Saucay Central | 0.6208 |
D2 | Machángara Irrigation System | 0.0432 |
D3 | Saymirín Central | 0.6912 |
D4 | Tixán Drinking Water System | 0.12096 |
D5 | Ricaurte Irrigation System | 0.02592 |
D6 | Ecosystem Functioning | 0.01728 |
Node | Reservoir | Min Capacity (hm3) | Max Capacity (hm3) |
---|---|---|---|
17 | R1 | 1.23 | 6.15 |
18 | R2 | 3.26 | 16.3 |
19 | R3 | 0.2 | 1.0 |
20 | R4 | 0.2 | 1.0 |
Cause of Penalty | Volume [hm3] | Value [€] |
---|---|---|
(A) Unmet water demand | 3696.02 | 3696.02 |
(B) Flooding claims | 3656.93 | 73,138,624,526.29 |
(C) Flooding in river sections | 725.61 | 2,902,452,589.12 |
(D) Violation of minimum river section capacity | 717.12 | 3,585,641,307.33 |
(E) Flooding in reservoirs | 434.52 | 3,041,687,022.49 |
(F) Violation of minimum reservoir capacity | 437.34 | 3,498,729,001.97 |
(G) Violation of minimum demand segment capacity | 3721.47 | 7,442,948,422.93 |
(H) Flooding in demand segments | 3567.04 | 71,340,813,841.23 |
Total | 16,956.08 | 164,950,900,407.42 |
Constraints | Average [hm3] | RMSD [hm3] |
---|---|---|
Related to water losses | 0.6959 | 2.7893 |
Related to demand nodes | 5.4570 | 24.1480 |
Related to losses and delays in demand nodes | 0.2434 | 0.0829 |
Related to the minimum and maximum capacities | ||
of a reservoir, as well as the loss of water in them | 4.0308 | 24.3690 |
Related to flow capabilities | 1472.31 | 7,191,836.09 |
Related to water flow delays | 0.6272 | 0.3027 |
Related the maximum continuity of water | 0.00 | 0.00 |
Related the minimum continuity of water | 3.2254 | 7.5282 |
Related to water flow balance | 3.4434 | 10.6633 |
Constraints | Average [hm3] | RMSD [hm3] |
---|---|---|
Related to water losses | 0.7292 | 2.9718 |
Related to demand nodes | 7.3565 | 65.3583 |
Related to losses and delays in demand nodes | 0.1856 | 0.0514 |
Related to the minimum and maximum capacities | ||
of a reservoir, as well as the loss of water in them | 4.1350 | 25.9639 |
Related to flow capabilities | 1473.4771 | 7,201,984.0736 |
Related to water flow delays | 0.6226 | 0.2987 |
Related to the maximum continuity of water | 0.00 | 0.00 |
Related to the minimum continuity of water | 3.2288 | 7.5350 |
Related to water flow balance | 3.4912 | 11.4564 |
Constraints | Average [hm3] | RMSD [hm3] |
---|---|---|
Related to water losses | 0.7090 | 2.8252 |
Related to demand nodes | 5.4424 | 23.9631 |
Related to losses and delays in demand nodes | 0.2417 | 0.0819 |
Related to the minimum and maximum capacities | ||
of a reservoir, as well as the loss of water in them | 3.9599 | 23.6774 |
Related to flow capabilities | 1473.4720 | 7,201,962.6121 |
Related to water flow delays | 0.6318 | 0.3054 |
Related to the maximum continuity of water | 0.00 | 0.00 |
Related to the minimum continuity of water | 3.2033 | 7.4270 |
Related to water flow balance | 5.0226 | 40.2664 |
Stage | LP | PSO |
---|---|---|
Calibration | 48.34 | 25.44 |
Validation | 45.77 | 29.52 |
Cause of the Penalty | PSO Vol. [hm3] | PSO Val. [€] | LP Vol. [hm3] | LP Val. [€] |
---|---|---|---|---|
(A) Sanction for not meeting demands | 3696.02 | 3696.02 | 50.96 | 50.96 |
(B) Penalty for flooding claims | 3656.93 | 73,138,624,526.29 | 0.00 | 0.00 |
(C) Penalty for flooding in river sections | 725.61 | 2,902,452,589.12 | 0.00 | 0.00 |
(D) Sanction for not complying with the minimum capacity in the river sections | 717.12 | 3,585,641,307.33 | 0.00 | 0.00 |
(E) Penalty for flooding in reservoirs | 434.52 | 3,041,687,022.49 | 0.00 | 0.00 |
(F) Sanction for not complying with the minimum capacity in reservoirs | 437.34 | 3,498,729,001.97 | 0.20 | 1.60 |
(G) Penalty for not meeting the minimum capacity in demand segments | 3721.47 | 7,442,948,422.93 | 0.00 | 0.00 |
(H) Penalty for flooding in demand segments | 3567.04 | 071,340,813,841.23 | 0.00 | 0.00 |
Total (A) + (B) + (C) + (D) + (E) + (F) + (G) + (H) | 16,956.08 | 164,950,900,407.42 | 51.16 | 52.56 |
Reservoirs | Cost of Construction and Maintenance | Penalty [euros] |
---|---|---|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 | 2,145,000.00 | 168,196,407,013.80862 |
Reservoirs | Cost of Construction and Maintenance | Penalty [euros] |
---|---|---|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 | 100,000.00 | 166,428,876,847.78842 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Veintimilla-Reyes, J.; Guerrero, B.; Maldonado-Segarra, D.; Ortíz-Gaona, R. Application of a Heuristic Model (PSO—Particle Swarm Optimization) for Optimizing Surface Water Allocation in the Machángara River Basin, Ecuador. Water 2025, 17, 2481. https://doi.org/10.3390/w17162481
Veintimilla-Reyes J, Guerrero B, Maldonado-Segarra D, Ortíz-Gaona R. Application of a Heuristic Model (PSO—Particle Swarm Optimization) for Optimizing Surface Water Allocation in the Machángara River Basin, Ecuador. Water. 2025; 17(16):2481. https://doi.org/10.3390/w17162481
Chicago/Turabian StyleVeintimilla-Reyes, Jaime, Berenice Guerrero, Daniel Maldonado-Segarra, and Raúl Ortíz-Gaona. 2025. "Application of a Heuristic Model (PSO—Particle Swarm Optimization) for Optimizing Surface Water Allocation in the Machángara River Basin, Ecuador" Water 17, no. 16: 2481. https://doi.org/10.3390/w17162481
APA StyleVeintimilla-Reyes, J., Guerrero, B., Maldonado-Segarra, D., & Ortíz-Gaona, R. (2025). Application of a Heuristic Model (PSO—Particle Swarm Optimization) for Optimizing Surface Water Allocation in the Machángara River Basin, Ecuador. Water, 17(16), 2481. https://doi.org/10.3390/w17162481