Thursday, March 1, 2018

Random Restart Hill Climbing For N Queen

Hill climbing is an optimization technique which is a local search algorithm. It is an algorithm that starts with a random solution to a problem. By changing a single element of the solution it attempts to find a better solution. Hill climbing is sometimes called greedy local search because it grabs a good neighbor state without thinking ahead about where to go next.
To find a global maxima random restart hill climbing is used. Random restart hill climbing is a series of hill climbing searches. From randomly generated initial state until a goal is found.

board setup: n queens, one queen per column
successors : The successors of a state are all possible states generated by moving a single queen to another square in the same column. Meaning, there are n queens on the board and each queen can move to n-1 defined positions. So, each state has n*(n-1) successors.
heuristic cost function h : h is the number of pairs of queens that are attacking each other
Basic hill climbing creates a random state of the board. Then it finds the highest value successor of the current state(for n queen the lowest valued successor), which is called the neighbor. If the heuristic cost value of the neighbor is less than the heuristic cost value of the current state, then the neighbor becomes the current state. If not then the current solution is the minima of the current hill.
What random restart does is, it runs the hill climbing until the global minima is found. In each hill climbing, it creates a new initial state of the board then runs the hill climbing algorithm to find the minima of the hill. It stops when the global minima is reached.
h(board)
1  returns the number of attacking pair on board

highest_valued_successor_of_current(current)
1  best_h  
2  best_successor  NULL
3  while(new successor can be created)
4      successor  new_successor(current)
5      if h(successor) < best_h 
6           best_h  h(successor)
7           best_successor  successor
8  return successor


hill_climbing()
1  current  A random state of the board
2  while(1)
3      neighbor  highest_valued_successor_of_current(current)
4      if h(neighbor) >= h(current) 
5           return current
6      neighbor  current

random_restart_hill_climbing()
1  final_h  
2  best_board  NULL
3  while(final_h != 0)
4       result  hill_climbing()
5       now_h  h(result)
6       if final_h > now_h
7            final_h  now_h
8            best_board  result
9  return best_board

No comments:

Post a Comment

Football Player Transfer Prediction

Football Player Transfer Prediction Using Different Classifiers Project Report :  Football Player Transfer Prediction Report ...