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
______________________________________________
[email protected] 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.