[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Newbie question - sqp solver equality constraints function
From: |
Juan Pablo Carbajal |
Subject: |
Re: Newbie question - sqp solver equality constraints function |
Date: |
Wed, 21 Jun 2017 23:01:20 +0200 |
On Wed, Jun 21, 2017 at 6:40 PM, alexegin <address@hidden> wrote:
> Hello all!
> I am trying to use *sqp* solver to find optimal vector *X*. All of the
> vector elements /must/ meet the following constraints:
> # 1. All of the elements must be more than -1.0 and less than 1.0-1.0 < X(i)
> < 1.0# 2.1 Sum of all elements those are _less than zero_ must be equal to
> -1.0# 2.2 Sum of all the elements those are _more than zero_ must be equal
> to 1.0dMinuses = 0.0;dPluses = 0.0;for i = 1:rows( X ) if ( X( i ) < 0.0
> ) dMinuses += X( i ); else dPluses += X( i ); endif;endfor;bResult =
> ( ( dMinuses + 1.0 ) == 0.0 ) && ( ( dPluses - 1.0 ) == 0.0 );
> The first constraint -1.0 < X(i) < 1.0 can be easily passed to *sqp* solver
> by upper and lower bounds.But I do not know how to pass the second ones
> *simultaneously*:
> SUM( X( i ) ) - 1.0 = 0.0, X( i ) >= 0.0SUM( X( i ) ) + 1.0 = 0.0, X( i ) <
> 0.0
> Thank you very much in advance.
>
Hi,
As you said the range of X should be passed using UB, LB arguments.
The others you can pass using the equality constraints
function E = eq_cons (X)
E = [sum(X(X<0)); sum(X(X>0))] - [-1; 1];
endfunction
Note that this function is problematic because of the jump introduced
when an element changes signs, but give it a try.
I am not sure but this alternative might be more suited for sqp (but
problably slower due to the copy of X)
function E = eq_cons (X)
Y = X;
Y(Y<0) *= -1;
E = sum([X Y]).' - [0; 2];
endfunction
I get the same results for dim(x) = 10,..,100 with little difference
sin perfomrnace, but maybe your cost is more complex than my test:
g =@(X) [sum(X(X<0)); sum(X(X>0))] - [-1; 1];
c =@(x) sumsq(x);
x0 = 2*rand(100,1)-1;
tic; [x obj info iter nf l] = sqp(x0,c,g,[],-1,1); toc
- Newbie question - sqp solver equality constraints function, alexegin, 2017/06/21
- Re: Newbie question - sqp solver equality constraints function,
Juan Pablo Carbajal <=
- Re: Newbie question - sqp solver equality constraints function, alexegin, 2017/06/22
- Re: Newbie question - sqp solver equality constraints function, Juan Pablo Carbajal, 2017/06/22
- Re: Newbie question - sqp solver equality constraints function, alexegin, 2017/06/22
- Re: Newbie question - sqp solver equality constraints function, Juan Pablo Carbajal, 2017/06/22
- Re: Newbie question - sqp solver equality constraints function, alexegin, 2017/06/22
- Re: Newbie question - sqp solver equality constraints function, Juan Pablo Carbajal, 2017/06/24
- Re: Newbie question - sqp solver equality constraints function, alexegin, 2017/06/29
- Re: Newbie question - sqp solver equality constraints function, Juan Pablo Carbajal, 2017/06/29
- Re: Newbie question - sqp solver equality constraints function, alexegin, 2017/06/29
- Re: Newbie question - sqp solver equality constraints function, Juan Pablo Carbajal, 2017/06/29