2

I've picked up Programming Challenges and found a Yahtzee! problem which I will simplify:

  • There are 13 scoring categories
  • There are 13 rolls by a player (comprising a play)
  • Each roll must fit in a distinct category
  • The goal is to find the maximum score for a play (the optimal placement of rolls in categories); score(play) returns the score for a play

Brute-forcing to find the maximum play score requires 13! (= 6,227,020,800) score() calls.

I choose simulated annealing to find something close to the highest score, faster. Though not deterministic, it's good enough. I have a list of 13 rolls of 5 die, like:

((1,2,3,4,5) #1
 (1,2,6,3,4),#2
    ...
 (1,4,3,2,2) #13
)

And a play (1,5,6,7,2,3,4,8,9,10,13,12,11) passed into score() returns a score for that play's permutation.

How do I choose a good "neighboring state"? For random-restart, I can simply choose a random permutation of nos. 1-13, put them in a vector, and score them. In the traveling salesman problem, here's an example of a good neighboring state:

"The neighbours of some particular permutation are the permutations that are produced for example by interchanging a pair of adjacent cities."

I have a bad feeling about simply swapping two random vector positions, like so:

(1,5,6,7, 2 , 3,4,8,9,10, 13, 12,11) # switch 2 and 13
(1,5,6,7, 13, 3,4,8,9,10, 2 , 12,11) # now score this one

But I have no evidence and don't know how to select a good neighboring state. Anyone have any ideas on how to pick good neighboring states?

animuson
  • 53,861
  • 28
  • 137
  • 147
atp
  • 30,132
  • 47
  • 125
  • 187

2 Answers2

1

The pair-swap strategy does not sound bad to me. It certainly visits -in theory- all permutations. The main point, I think, is to see if the "neighbors" are really "similar" in your case, i.e. if two placements that differ only in a pair swapping are rather similar in score. I cannot decide this, because the rules of your "game" are not clear to me.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • You've clarified much, in spite of not knowing the rules. If the key point is to find two placements that are rather similar in score, I can solve it. Thanks! – atp Jan 11 '11 at 02:18
1

The trick is to have multiple types of moves. So offer SA both small, unifying moves and big, diversifying moves. But have a higher chance of offering the first. The small moves are easy: change 1 or switch 2.

Take a look at my nurse rostering example in drools planner. Its open source in java.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120