Re: [R] Cardinality constraint

From: Patrick Burns <pburns_at_pburns.seanet.com>
Date: Sat 21 Oct 2006 - 09:54:52 GMT

To solve the problem you have in general, you will need something more powerful than 'constrOptim'. This is called a mixed integer problem, and arises in several fields including financial portfolio optimization.

If you really only have 3 variables, then there are only 3 combinations of 2 variables. So just solve the problem with each set and pick the best one.

Patrick Burns
patrick@burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Neuro LeSuperHéros wrote:

>Hello,
>
>How do I implement a cardinality constraint with constrOptim?
>
>I want to minimize (least square) a%*%x = 4
>subject to
>x1<2
>x2<1
>x3<4
>count(x1, x2, x3)= 2 (cardinality constraint)
>
>Is there a way to specify binary integer variables with constrOptim?
>
>Here's my code so far:
>
>a <-matrix(1:3,1,3)
>fr <- function(x) {
>(a%*%x-4)^2
> }
>constrOptim(c(1,0.5,3),fr,grad=NULL,ui=-diag(3), ci=c(-2,-1,-4))
>
>I need the optimization to give me one variable that is zero to satisfy the
>maximum cardinality of 2.
>
>Thanks
>
>_________________________________________________________________
>Voyez vos amis en faisant un appel vidèo dans Windows Live Messenger
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
>
>
>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sat Oct 21 23:34:31 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 21 Oct 2006 - 14:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.