[R] Combinatorial Optimisation

Adrian Trapletti adrian.trapletti at lmttrading.com
Fri Oct 25 09:46:21 CEST 2002

> Date: Thu, 24 Oct 2002 08:58:08 +0200 (CEST)
> From: Detlef Steuer <Detlef.Steuer at unibw-hamburg.de>
> Subject: RE: [R] Combinatorial Optimisation
> This thread missed me somehow.
> If not mentioned before:
> simulated annealing is implemented in optim().

The current implementation of simulated annealing in optim() has been designed for a continuos parameter space. The next candidate
point in the parameter space is generated from a Gaussian Markov kernel with scale proportional to the actual temperature. However,
it is quite simple to change this for a combinatorial optimization:

in the R source tree, see the file src/main/optim.c, function samin:

What you need to change are the four lines, that are responsible for generating a new candidate point:

for (i = 0; i < n; i++)
  dp[i] = scale * t * norm_rand();  /* random perturbation */
for (i = 0; i < n; i++)
  ptry[i] = p[i] + dp[i];  /* new candidate point */

You could, e.g., replace them by a call to an R function, which randomly selects a new candidate point of a finite set of points.
Hence, to quickly get SA for combinatorial optimization:

Copy and paste samin from optim.c
Change the four lines
Write an R wrapper for this new function


PS: TO R-DEVEL: What about having this behaviour in optim (default as is, optional a function argument which selects a candidate

Dr. Adrian Trapletti             Phone :             +41 (0) 1 994 5631
Trapletti Statistical Computing  Mobile:             +41 (0)76 370 5631
Wildsbergstrasse 31              Fax   :             +41 (0) 1 994 5631
CH-8610 Uster                    Email :  mailto:a.trapletti at bluewin.ch
Switzerland                      WWW   : http://trapletti.homelinux.com

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list