[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: qp(): how do I get a simple inequality constraint?
From: |
Leo Butler |
Subject: |
Re: qp(): how do I get a simple inequality constraint? |
Date: |
Sat, 24 Sep 2011 12:12:17 -0400 |
User-agent: |
Gnus/5.110018 (No Gnus v0.18) Emacs/23.2 (gnu/linux) |
forkandwait <address@hidden> writes:
> Leo Butler <l.butler <at> cmich.edu> writes:
>
>>
>> forkandwait <forkandwait <at> gmail.com> writes:
>> >
>> > min (p'*G*p)/2 + f'*p
>> >
>> > subject to C*p <= b
>>
>> In my first post, I should have said to use A_lb, A_in and A_ub to
>> enforce the inequallity on your slack variable, as you divined.
>>
>
> Like this? --
>
> phat = qp(x0, G, f, [], [], [], [], [], C, b)
Let me explain with an example:
Suppose you want to minimize
x^2 + y^2 + x subject to
x <= 0
We can do the following:
H = 2*eye(2);
q = [1;0];
A = [];
b = [];
lb = [];
ub = [];
A_lb = [];
A_ub = [0];
A_in = [1,0];
[x, obj, info, lambda] = qp ([0;0], H, q, A, b, lb, ub, A_lb, A_in,
A_ub)
You can verify that the objective function is
(x+1/2)^2 + y^2 - 1/4
which has a global minimum at x=-1/2, and that qp finds that.
--------------------
[You can probably ignore the following comment]
Alternatively, *if we could only put lower bounds on variables*, we
could add a slack variable, s, and re-write the program as
x^2+y^2+x s.t. x+s=0, s>=0.
Here:
H = 2*[1,0,0;0,1,0;0,0,0];
q = [1;0;0];
A = [1,0,1];
b = [0];
lb = [];
ub = [];
A_lb = [0];
A_ub = [];
A_in = [0,0,1];
[x, obj, info, lambda] = qp ([0;0;0], H, q, A, b, lb, ub, A_lb, A_in,
A_ub)
Again, qp finds the global minimum.
>
> This is what I have, and I get a very different answer than the book. See
> below
> for my inputs (phat is the result, book_phat is what the book has, etc).
>
> I will continue hacking and reading (can you recommend a book?).
>
> (The difficulty in posing the question is that the algorithm munges a bunch of
> stuff before calling qp, so determining whether the problem is in the set up
> or
> my call to qp() is not so trivial, at least for an optimization ignoramus like
> myself.)
>
> The full qp reference is this: qp(x0, H, q, A, b,lb, ub, A_lb, A_in, A_ub)
>
> My inputs and outputs:
>
> phat =
> 0.00000
> 1.00000
> 0.00000
> 1.00000
> 0.01673
> 1.00000
>
> book_phat =
> 0.00000
> 1.00000
> 0.45000
> 0.54000
> 0.01000
> 0.97000
>
> G =
> 1.4151e+002 0.0000e+000 0.0000e+000 0.0000e+000 3.0723e+003 0.0000e+000
> 0.0000e+000 1.4151e+002 6.6074e+002 0.0000e+000 0.0000e+000 0.0000e+000
> 0.0000e+000 6.6074e+002 3.0851e+003 0.0000e+000 0.0000e+000 0.0000e+000
> 0.0000e+000 0.0000e+000 0.0000e+000 3.0851e+003 0.0000e+000 1.4345e+004
> 3.0723e+003 0.0000e+000 0.0000e+000 0.0000e+000 6.6701e+004 0.0000e+000
> 0.0000e+000 0.0000e+000 0.0000e+000 1.4345e+004 0.0000e+000 6.6701e+004
>
> f =
> -5.1391e+001
> -2.7590e+002
> -1.2882e+003
> -5.1457e+004
> -1.1157e+003
> -2.3926e+005
>
> C =
> -1 0 0 0 0 0
> 0 -1 0 0 0 0
> 0 0 -1 0 0 0
> 0 0 0 -1 0 0
> 0 0 0 0 -1 0
> 0 0 0 0 0 -1
> 1 1 0 0 0 0
> 0 0 1 1 0 0
> 0 0 0 0 0 1
>
> b =
> 0
> 0
> 0
> 0
> 0
> 0
> 1
> 1