Write loop in optimization problem constraint

2 visualizaciones (últimos 30 días)
Sina
Sina el 3 de Mzo. de 2023
Respondida: Harsh el 30 de Mayo de 2025
Hello
I have an optimization problem that needs a loop in it's constraints.
My optimizaton problem constraint: we have some nodes that should preserve a distinct distance among each other, for this goal I've written a loop in constraints include a for loop that measure norm among every pair of nodes that should be greater than a specific 'd', but my constraint including for loop isn't met.
Have you ever used a loop (especially for loop) in constraints section of an opt. problem?

Respuestas (1)

Harsh
Harsh el 30 de Mayo de 2025
Hi @Sina,
You can use "for-loops" within the nonlinear constraint function in MATLAB's Optimization Toolbox, as long as the function returns two outputs: one for inequality constraints ("c", where each element must be ≤ 0) and one for equality constraints ("ceq", where each element must be = 0). This is useful for problems like ensuring that all pairs of nodes maintain a minimum distance—by looping through each pair, computing the Euclidean distance, and constructing the constraint as "d - distance ≤ 0".
Please refer to the MathWorks documentation under “Nonlinear Constraints” at www.mathworks.com/help/optim/ug/nonlinear-equality-and-inequality-constraints.html and in the "fmincon" function reference at www.mathworks.com/help/optim/ug/fmincon.html to understand more regarding this.

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by