yalmip / YALMIP

MATLAB toolbox for optimization modeling
https://yalmip.github.io/
Other
478 stars 137 forks source link

During the solving process in YALMIP, a certain constraint was bypassed without any error message, and an optimal solution was given, but the solution does not satisfy the aforementioned constraint. #1341

Closed fishlovesoup closed 11 months ago

fishlovesoup commented 11 months ago

I wrote a constraint in YALMIP, but during the solving process, this constraint was ignored without any error message, and an optimal solution was given. When I verified it, I found that the above constraint was ignored and did not function. I would like to know why this happened. Because in previous optimization processes, this problem has never occurred. If you could help me solve this problem, I would be very grateful. I am looking forward to your reply. Thank you very much.

johanlofberg commented 11 months ago

You would have to supply reproducible code, because there is no way that a constraint you have stated would not have been sent to the solver, i.e. there is a bug in your code (or you've missed this https://yalmip.github.io/faq/solutionviolated/)

johanlofberg commented 11 months ago

As I said, you would have to supply reproducible code (your code does not run as it is not pasted into a code block and is therefore butchered, and it uses external data)

johanlofberg commented 11 months ago

As I said, you have to use code blocks

bad and broken

y=10x

What you have to do (<>)

y = 10*x

Copy your code back to matlab and you will see that it is broken and does not run

fishlovesoup commented 11 months ago

Hello, my code has become garbled during the copy-pasting process. If possible, could you provide your email address so I can send it to you? Thank you for your response.

johanlofberg commented 11 months ago

Open a code block, paste into it. Done

johanlofberg commented 11 months ago

All constraints are satisfied (and not even close to being infeasible), as easily seen by giving them a name and check them after solving the problem

...
Qssconstraints = []
for t = 1:Horizon
    Qssconstraints = [Qssconstraints,10*P_D_Miss(t) - sum(P_G_PFR(:,t)) - sum(P_W_PFR(:,t)) -sum(P_CSP_PFR(:,t)) <= f_QSS*D*P_Load_total_Fore(t)];
end
constraints = [constraints,Qssconstraints ]
...
check(Qssconstraints)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|    ID|               Constraint|   Primal residual|   Dual residual|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|    #1|   Elementwise inequality|             222.8|             NaN|
|    #2|   Elementwise inequality|             2.664|             NaN|
|    #3|   Elementwise inequality|               156|             NaN|
|    #4|   Elementwise inequality|              2.56|             NaN|
|    #5|   Elementwise inequality|             206.6|             NaN|
|    #6|   Elementwise inequality|             2.508|             NaN|
|    #7|   Elementwise inequality|               200|             NaN|
|    #8|   Elementwise inequality|             2.456|             NaN|
|    #9|   Elementwise inequality|             145.6|             NaN|
|   #10|   Elementwise inequality|             2.456|             NaN|
|   #11|   Elementwise inequality|             163.5|             NaN|
|   #12|   Elementwise inequality|             2.508|             NaN|
|   #13|   Elementwise inequality|             166.4|             NaN|
|   #14|   Elementwise inequality|             2.664|             NaN|
|   #15|   Elementwise inequality|             197.6|             NaN|
|   #16|   Elementwise inequality|             2.976|             NaN|
|   #17|   Elementwise inequality|             326.2|             NaN|
|   #18|   Elementwise inequality|             3.262|             NaN|
|   #19|   Elementwise inequality|               344|             NaN|
|   #20|   Elementwise inequality|              3.47|             NaN|
|   #21|   Elementwise inequality|             327.3|             NaN|
|   #22|   Elementwise inequality|             3.574|             NaN|
|   #23|   Elementwise inequality|             317.5|             NaN|
|   #24|   Elementwise inequality|               3.6|             NaN|
|   #25|   Elementwise inequality|          274.8606|             NaN|
|   #26|   Elementwise inequality|             3.574|             NaN|
|   #27|   Elementwise inequality|               260|             NaN|
|   #28|   Elementwise inequality|               3.6|             NaN|
|   #29|   Elementwise inequality|               360|             NaN|
|   #30|   Elementwise inequality|               3.6|             NaN|
|   #31|   Elementwise inequality|             321.9|             NaN|
|   #32|   Elementwise inequality|             3.522|             NaN|
|   #33|   Elementwise inequality|             299.2|             NaN|
|   #34|   Elementwise inequality|             3.496|             NaN|
|   #35|   Elementwise inequality|             349.6|             NaN|
|   #36|   Elementwise inequality|             3.496|             NaN|
|   #37|   Elementwise inequality|             328.8|             NaN|
|   #38|   Elementwise inequality|             3.418|             NaN|
|   #39|   Elementwise inequality|             339.2|             NaN|
|   #40|   Elementwise inequality|             3.392|             NaN|
|   #41|   Elementwise inequality|             339.2|             NaN|
|   #42|   Elementwise inequality|             3.392|             NaN|
|   #43|   Elementwise inequality|             341.8|             NaN|
|   #44|   Elementwise inequality|             3.418|             NaN|
|   #45|   Elementwise inequality|               315|             NaN|
|   #46|   Elementwise inequality|             3.262|             NaN|
|   #47|   Elementwise inequality|             287.2|             NaN|
|   #48|   Elementwise inequality|             2.872|             NaN|
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| A primal-dual optimal solution would show non-negative residuals.  |
| In practice, many solvers converge to slightly infeasible          |
| solutions, which may cause some residuals to be negative.          |
| It is up to the user to judge the importance and impact of         |
| slightly negative residuals (i.e. infeasibilities)                 |
| https://yalmip.github.io/command/check/                            |
| https://yalmip.github.io/faq/solutionviolated/                     |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fishlovesoup commented 11 months ago

Thank you. My junior female colleague and I have solved the problem together. Thank you for your help!!!