Four Queens with Hill Climbing

Optimization Techniques
Techniques for finding a solution
to an optimization problem
Optimization Problems
• Four Queens / Eight Queens
• Travelling Salesman
• Vertex Coloration (2 colors or minimum coloration)
• Eight Puzzle
• Blocks World with initial and goal configuration
• Path in a grid graph
• Classification of input string to closest library string
General Problem Format
• State Space consists of different problem states
• Value of each state
• Initial State
• Transitions between states
• Goal States
• Heuristic bound to distance
• from a state to a goal state
Optimization Techniques
Optimization Techniques
Technique : Hill Climbing or Greedy
Variables : current state, neighbor
• current state  initial state (or randomly generated state)
• while current state <> goal and not through
• base value = value of current state
• best neighbor value = base value
• best neighbor = current state
• for each neighbor of current state
• if value of neighbor > best neighbor value then
• best neighbor value  value of neighbor
• best neighbor  neighbor
• end if
• end for
• through  (best neighbor = current state)
• if not through then current state  best neighbor
• end while
Four Queens with Hill Climbing
h(n) is value of node or state n. Each state has 12 neighbors. Select best.
2 Coloration with Hill Climbing
v=6
v=3
v=1
State Space : X i  Y jt
i = 0 .. X.length, j = 0 .. Yt.length
Goal = nearest goal
Informed search for shortest path in grid graph
• A grid graph is used for circuit layout and routing in urban street networks.
Vertices have degree zero, one, two, three or four. Edges are horizontal or
vertical and are give uniform length.
• Manhattan distance is the number of “blocks” north or south plus the
number of blocks east or west between two vertices.
• To find the shortest path from one vertex to another, Manhattan distance
can be used as a lower bound.
• Because the edges all have the same length, A* has a simple form :
• the open set is two stacks of vertices :
• the “zero” stack is a list of vertices for which the Manhattan
distance was 1 less than that of the vertex expanded as current
vertex
• the “one” stack is a list of vertices for which the Manhattan
distance was 1 greater than that of the vertex expanded as current
vertex
• search proceeds be retrieving a vertex from the “zero” stack unless
empty in which case the “one” stack become the zero stack else if both
are empty, there is no path from start to goal.
Path from 3,5 to 5,6 is found two steps with
neighbors on the “One” stack never expanded.
2 Coloration with Beam Search
v=3
v=3