Re: [R] Solving an optimization problem: selecting an " optimal" subset

2010-02-02 Thread Hans W Borchers
Erwin Kalvelagen-2 wrote: > > Hans W Borchers googlemail.com> writes: >> # Prepare inputs for MILP solver >> obj <- c(rep(0, n), 0, 1, 1, 0) >> typ <- c(rep("B", n), "B", "C", "C", "B") >> mat <- matrix(c(s, -z, -1, 1, 0,# a = a_p + a_m >> rep(0,

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-02-01 Thread Hans W Borchers
Dimitri Shvorob gmail.com> writes: > > Given vector of numbers x, I wish to select an n-subset with sum closest > fixed value s. Can anyone advise me how to approach this, in R? > > I have considered Rcplex package, which handles integer/binary > linear/quadratic optimization problems, but have d

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-31 Thread Erwin Kalvelagen
Dimitri Shvorob gmail.com> writes: > > > Thank you very much, Erwin. If I may ask some follow-up questions > 1. GAMS <> R, ad it's just not entirely clear how to move the soltion to R. > (At most trivial, how do I "bring in" the subsettable vector into the > solver?") > 2. "The quadratic object

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-31 Thread Dimitri Shvorob
> To replace an absolute value by two binary variables is an old trick in optimization modeling. I am having trouble Googling it: can anyone suggest a reference, or just explain? Thank you. -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optim

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-31 Thread Dimitri Shvorob
Thank you very much, Erwin. If I may ask some follow-up questions 1. GAMS <> R, ad it's just not entirely clear how to move the soltion to R. (At most trivial, how do I "bring in" the subsettable vector into the solver?") 2. "The quadratic objective can be replaced by a linear one by minimizing th

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-31 Thread Hans W Borchers
Dimitri Shvorob wrote: > > Same request to Hans: > I am afraid I need a little more spoon-feeding following > >> I sent a GAMS script modeling this problem to the NEOS solvers > > Thanks a lot! > If you have access to CPLEX (I mean the commercial program, not Rcplex which is just an interfa

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Erwin Kalvelagen
Dimitri Shvorob gmail.com> writes: > > > ?!! Erwin, may I ask for a working code sample? (Including appropriate > package(s)) > > Thank you. I used GAMS + CPlex. The models are here: http://yetanothermathprogrammingconsultant.blogspot.com/2010/01/solving- optimization-problem-selecting.html

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
Same request to Hans: I am afraid I need a little more spoon-feeding following > I sent a GAMS script modeling this problem to the NEOS solvers Thanks a lot! -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1457747.htm

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
?!! Erwin, may I ask for a working code sample? (Including appropriate package(s)) Thank you. -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1457746.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Hans W Borchers
Dimitri Shvorob gmail.com> writes: > > > This is a "subset sum" problem and has been discussed here in December > > Thanks a lot! Will investigate. > > > Can you settle for an approximate solution? > > Absolutely. You can use the script from the thread "subset sum problem" to find approxima

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Erwin Kalvelagen
Dimitri Shvorob gmail.com> writes: > > > A 40-element subset proves too much :( > > > Error: cannot allocate vector of size 554.1 Mb > > Thanks, Bart! I could solve a problem with n=200, k=40 with Cplex's MIQP solver in less than a minute, but that may depend heavily on the data. The mode

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
A 40-element subset proves too much :( > Error: cannot allocate vector of size 554.1 Mb Thanks, Bart! -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1457597.html Sent from the R help mailing list archive at Nabble.com

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Bart Joosen
Here some kind of a brute force attack: #brute force solution, only working with relative small subsets: n <- 200 elem <- 3 target <- 200 x <- rnorm(n,100,10) x.combinations <- combn(x,elem) sums <- apply(x.combinations,2,function(x) (sum(x)-target)^2) ans <- (x.combinations[,which.min(sums)])

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
Found this http://n4.nabble.com/Subset-sum-problem-td954423.html#a954423 http://n4.nabble.com/The-subset-matching-challenge-td861840.html#a861840 and learnt/remebered about 'subset sum' and 'knapsack' problems. My case is different (simpler) in that subset size is fixed. -- View this message

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
> This is a "subset sum" problem and has been discussed here in December Thanks a lot! Will investigate. > Can you settle for an approximate solution? Absolutely. > Rcplex: This is a combinatorial problem and cannot be formulated as a > quadratic optimization problem. If the objective func

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Dimitri Shvorob
> Is it a subset of a vector containing 100 elements, or 1ths? I need to pick 2-40 elements out of a 50-200-element-long vector. > A random number of elements that should be chosen, or the best 10 values > which sums up to a defined value? The best 10 values. I still think that Rcplex

Re: [R] Solving an optimization problem: selecting an "optimal" subset

2010-01-30 Thread Bart Joosen
Could you please specifiy your problem, if possible with some data? Is it a subset of a vector containing 100 elements, or 1ths? A random number of elements that should be chosen, or the best 10 values which sums up to a defined value? Bart -- View this message in context: http://n4.nabble.

[R] Solving an optimization problem: selecting an "optimal" subset

2010-01-29 Thread Dimitri Shvorob
Given vector of numbers x, I wish to select an n-subset with sum closest to fixed value s. Can anyone advise me how to approach this, in R? I have considered Rcplex package, which handles integer/binary linear/quadratic optimization problems, but have difficulty setting up the quadratic form for