Docsity

Search Algorithms: Techniques and Techniques for Solving Combinatorial Problems - Prof. Ji, Study notes of Computer Science

Partial preview of the text

Download Search Algorithms: Techniques and Techniques for Solving Combinatorial Problems - Prof. Ji and more Study notes Computer Science in PDF only on Docsity!

Search Algorithms

Jingke Li

Portland State University

Jingke Li (Portland State University) CS 415/515 Search Algorithms 1 / 19

Combinatorial Search

The process of finding a feasible solution or the optimal solution in a

defined problem space.

Example: The 8-puzzle problem โ€” Given a 8-tile grid, find a shortest

sequence of moves that transforms the initial configuration to the final

configuration.

State Space Tree

A search problem can often be represented by a tree:

  • Nodes correspond

to states, some

correspond to

feasible solutions

  • Edges of a node

correspond to

search options in

the corresponding

state

Parallel Search:

Finding parallelism in a state-space search problem is trivial โ€” at a given

node, all its child nodes can be explored in parallel.

Jingke Li (Portland State University) CS 415/515 Search Algorithms 3 / 19

Common Search Techniques

  • (^) Branch-and-Bound โ€” It starts with the root node in the state space

tree; while proceeding with the search, it tries to prune the tree to

reduce the search space.

  • Hill Climbing โ€” It starts with a random (potentially poor) solution,

and iteratively makes small improvements to the solution. It

terminates when no more improvement can be made.

  • Simulated Annealing โ€” It shares the idea of improving solution.

However, in each step, it replaces the current solution by a random

โ€œnearbyโ€ solution, chosen with a probability that depends on the

value of a โ€œglobal temperatureโ€. It allows for โ€œuphillโ€ moves that

saves itself from becoming stuck at a local minimum.

  • (^) Genetic Algorithms โ€” Emulate the natural evolution process. A GA

produces a new โ€œchildโ€ solution from a pair of โ€œparentโ€ solutions by

using two genetic operations, โ€œcrossoverโ€ (for local improvements)

and โ€œmutationโ€ (for random changesโ€).

The 8-Puzzle Problem (cont.)

Jingke Li (Portland State University) CS 415/515 Search Algorithms 7 / 19

Example: Traveling Salesman Problem

Given a weighted, undirected graph, find a tour containing every node in

the graph so that the total weight of the tour is minimized.

The problem is NP-hard.

Naive Exhaustive-Search:

Generate all possible solutions, and pick the shortest.

A B

C

D E

ABECDA โ€” 35

ABEDCA โ€” 38

ABCEDA โ€” 31

ACBEDA โ€” 34

Worst Case:

(n โˆ’ 1)! possible solutions.

Littleโ€™s Branch-and-Bound TSP Algorithm

  • Establish a lower bound on the weight of any tour over the whole

graph. A state space tree with a single root node is created, where

the root node is marked with the lower bound.

  • Pick an edge (i, j), break a TSP problem into two subproblems

representing tours that must include or exclude (i, j). Creating two

nodes corresponding to these two cases.

  • (^) Compare the two subproblems by computing the lower bounds on the

two tours; pick the lower one.

  • (^) Recursively apply the above two steps.

Jingke Li (Portland State University) CS 415/515 Search Algorithms 9 / 19

Computing a Lower Bound

Observation: An edge has to be traversed to visit a node.

Lower Bound 1: For each node, consider the edge with the lowest weight.

The sum of these weights is a lower bound on a tour.

A B

C

D E

This gives a lower bound of 21.

Representing the Set of Solutions

The adjacency matrix can be used to represent the set of solutions.

  • (^) When an edge is excluded from the solution, its entry is deleted.
  • When an edge is included in the solution, the row and column

corresponding to that edge are deleted, except for the edge entry.

A B C D E

A โˆž 9 6 7 โˆž

B 9 โˆž 3 โˆž 10

C 6 3 โˆž 5 4

D 7 โˆž 5 โˆž 8

E โˆž 10 4 8 โˆž

Including edge (B,C): A B C D E A โˆž 9 โˆž 7 โˆž B โˆž โˆž 3 โˆž โˆž C 6 โˆž โˆž 5 4 D 7 โˆž โˆž โˆž 8 E โˆž 10 โˆž 8 โˆž

Excluding edge (B,C): A B C D E A โˆž 9 6 7 โˆž B 9 โˆž โˆž โˆž 10 C 6 3 โˆž 5 4 D 7 โˆž 5 โˆž 8 E โˆž 10 4 8 โˆž

Jingke Li (Portland State University) CS 415/515 Search Algorithms 13 / 19

Computing Subproblem Lower Bound

  • (^) Including edge (B,C) โ€” Lower bound is 31.

A B C D E row A โˆž 9 โˆž 7 โˆž 7 B โˆž โˆž 3 โˆž โˆž 3 C 6 โˆž โˆž 5 4 4 D 7 โˆž โˆž โˆž 8 7 E โˆž 10 โˆž 8 โˆž 8 29

A B C D E

A โˆž 2 โˆž 0 โˆž

B โˆž โˆž 0 โˆž โˆž

C 2 โˆž โˆž 1 0

D 0 โˆž โˆž โˆž 1

E โˆž 2 โˆž 0 โˆž

col 0 2 0 0 0 2

  • Excluding edge (B,C) โ€” Lower bound is 29.

A B C D E row A โˆž 9 6 7 โˆž 6 B 9 โˆž โˆž โˆž 10 9 C 6 3 โˆž 5 4 3 D 7 โˆž 5 โˆž 8 5 E โˆž 10 4 8 โˆž 4 27

A B C D E

A โˆž 3 0 1 โˆž

B 0 โˆž โˆž โˆž 1

C 3 0 โˆž 2 1

D 2 โˆž 0 โˆž 3

E โˆž 6 0 4 โˆž

col 0 0 0 1 1 2

State Space Tree For the TSP Algorithm

Traversal Strategy: Best first.

25

31

31

31

31

31

31 inf

inf

32

35

32

29

Incl (B,C) Excl (B,C)

Incl (E,C) Excl (E,C)

Incl (A,D) Excl (A,D)

Incl (C,B) Excl (C,B)

Incl (B,A) Excl (B,A)

Incl (D,E) Excl (D,E)

Jingke Li (Portland State University) CS 415/515 Search Algorithms 15 / 19

Parallel TSP Algorithm (Shared-Memory)

begin

reduce weight matrix, determining the rootโ€™s lower bound

initially only the root node is in the state space tree

while (true) do

select the unexamined node in the state space tree

with the smallest lower bound

if (the node represents a tour)

exit the loop

end if

select the k edges whose exclusion increases

the lower bound the most

forall (the 2^k cases representing all inclusion-exclusion

combinations of the selected edges)

create a child node with the correct constraints

find the lower bound for the child node

end forall

end while

end

Speedup Anomalies (cont.)