Description Usage Arguments Details Note Author(s) See Also Examples

Uses simulated annealing to find the ‘best’ permissible board, using any objective function

1 |

`x` |
A board |

`func` |
The objective function, with default |

`n` |
Maximum number of attempts (passed to |

`...` |
Further arguments passed to |

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()`

).

Function `randomprobs()`

also takes a `func`

argument and
can be used to find an optimal board, by generating random permissible
boards and finding the best one. 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.

Robin K. S. Hankin

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
a <- matrix(0,5,5)
diag(a) <- NA
a[cbind(1:5 , c(2:5,1))] <- 4
## Not run:
best(a,control=list(maxit=10)) ## Answer should be all ones except the diagonal
## End(Not run)
# Now a non-default function; SANN should be able to get func(x) down to
# zero pretty quickly:
## Not run:
best(a,func=function(x){x[1,2]},control=list(maxit=100))
## End(Not run)
# The 'dontrun' is needed because sometimes the method needs a bigger n
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.