# Problem with soft constraints in RBDO

**URL:** <https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718>\
**Category:** Community Q&A and How To\
**Tags:** rbdo\
**Created:** [July 3, 2020, 3:39pm UTC](https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718 "2020-07-03T15:39:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soheil\_Radfar](https://uqworld.org/user_avatar/uqworld.org/soheil_radfar/32/460_2.png) [@Soheil\_Radfar](https://uqworld.org/u/Soheil_Radfar)\
**Post date:** [July 3, 2020, 3:39pm UTC](https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718/1 "2020-07-03T15:39:30Z")

</div>

Hello everyone  
Following my previous questions on implementing the RBDO problem, I have trouble defining soft constraints.  
We know that in an optimization problem, in addition to the inequality constraints, there are also **equality constraints**. But I don’t know how to define such constraints?  
Also, in one of my soft constraints, the **MATLAB max function** is used, but there is a problem with this part when running the program.  
I have attached the MATLAB codes and I have specified these constraints in “uq\_RubBreakwat\_SoftCon.m” as comments.

**Does anyone have a suggestion to solve this problem?**  
**The zip version of all code files is also attached.**  
[RBDO.zip](https://uqworld.org/uploads/short-url/bPnMG6xngE1rNJM0ioa86UXgMPP.zip) (3.6 KB)

---

<div class="post-metadata">

**Author:** ![moustapha](https://uqworld.org/user_avatar/uqworld.org/moustapha/32/226_2.png) [@moustapha](https://uqworld.org/u/moustapha)\
**Post date:** [July 17, 2020, 9:37am UTC](https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718/2 "2020-07-17T09:37:57Z")

</div>

Hi @Soheil_Radfar

Unfortunately equality constraints are not supported in the current version of the RBDO module. I would however suggest the following two options:

1. Define two inequality constraints to form an equalitiy one e.g. X \<= a and X \>= a. I am not sure if the algorithm would perform well with such a trick though. It’s probably not the best approach but may be it will help.
2. Alternatively, I would suggest you hard-code your equality constraints in UQLab. If you are using an `fmincon`-based solver, you can go in the file uq\_matlabnonlconwrapper.m and add the constraint directly at the end of the file. At line 67, you will see  
`ceq = [];`  
You can then write your equality soft constraints there a few lines above and save the result (as a row vector if you have many) in the variable `ceq` which will then be carried out in `fmincon` as equality constraint.

Regarding the max constraint, I am not sure what you actually tried to achieve. Your max constraint has three arguments, two of which are constant. So you can simply remove the smallest of the two:  
This  
`Y(:,17) = max(2 .* X(:,13), 0.4 * 4.91, 3 * 0.384) - X(:,9)`  
becomes this  
`Y(:,17) = max(2 .* X(:,13), 0.4 * 4.91) - X(:,9)`  
… or may be I am mistaken you were trying to do something else. In any case, the `max` function does not take three arguments. If you have more than two arguments, you need to put everything in a single matrix and then use the max operator in the appropriate dimension.

Cheers,  
Moustapha

---

<div class="post-metadata">

**Author:** ![Soheil\_Radfar](https://uqworld.org/user_avatar/uqworld.org/soheil_radfar/32/460_2.png) [@Soheil\_Radfar](https://uqworld.org/u/Soheil_Radfar)\
**Post date:** [July 17, 2020, 4:35pm UTC](https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718/3 "2020-07-17T16:35:27Z")

</div>

Dear @moustapha

As always, your solutions are very effective.  
I checked the first proposed solution and the answers were obtained with a very good approximation.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![damarginal](https://uqworld.org/user_avatar/uqworld.org/damarginal/32/73_2.png) [@damarginal](https://uqworld.org/u/damarginal)\
**Post date:** [July 17, 2020, 6:02pm UTC](https://uqworld.org/t/problem-with-soft-constraints-in-rbdo/718/4 "2020-07-17T18:02:24Z")

</div>


