best
From aylmer v1.0-1
Optimize a board using simulated annealing
Uses simulated annealing to find the `best' permissible board, using any objective function
Usage
best(x, func = NULL, n = 100, ...)
Arguments
- x
- A board
- func
- The objective function, with default
NULL
meaning to use-prob(x)
- n
- Maximum number of attempts (passed to
candidate()
) - ...
- Further arguments passed to
optim()
Details
The help page for optim()
gives an example of simulated
annealing being used to solve the travelling salesman problem and
best()
uses the same technique in which the gr
argument
specifies a function used to generate a new candidate point
(candidate()
).
Note
Function randomprobs()
also takes a func
argument and (if
argument give.best
is TRUE
) will return the optimal
board. But these two functions are very different: best()
uses
optim()
which incorporates highly specific optimization
algorithms to find a global maximum, while randomprobs()
creates a Markov chain and reports the board with the most desirable
objective function.
See Also
Examples
a <- matrix(0,5,5)
diag(a) <- NA
a[cbind(1:5 , c(2:5,1))] <- 4
best(a,control=list(maxit=10)) ## Answer should be all ones except the diagonal
# Now a non-default function; SANN should be able to get func(x) down to
# zero pretty quickly:
best(a,func=function(x){x[1,2]},control=list(maxit=100))
Community examples
Looks like there are no examples yet.