Professional Documents
Culture Documents
TECHNIQUE- PART 2
(CONSTRUCTIVE HEURISTIC)
2
EXAMPLE: The traveling
salesman problem (TSP)
A salesman needs to visit n cities
(incl. his home city). He wishes to
determine a minimum length (time/cost)
tour that visits each city exactly once
(except that it begins and ends in his
home city).
Example - Traveling Salesman
Problem (TSP)
Traveler needs to visit n cities.
Want to know the shortest route that visits all the cities once.
2 1 4 2
2
5 3
3 5
4
How might we construct initial tour for TSP?
Nearest neighbour
Furthest Insetion
Random
The traveling salesman problem
Nearest neighbor (construction) heuristic
1. Begin with any city, say x.
2. Select among all currently unvisited
cities, the one which is closest to x.
Call this city y, and add the route (x,y)
to the tour.
3. If all cities are visited, STOP.
Otherwise let x = y be the most recently
added city and go to 2.
Illustration of the nearest neighbor
heuristic (start city: 1)
3
1 2
4 3
2 1 4 2
2
5 3
3 5
3
1 2
4 3
2 1 4 2
2
5 3
start
3 5
4
Total distance = 13
Best-First Search
Combines the advantages of Breadth-First and Depth-First searchs.
• DFS: follows a single path, don’t need to generate all competing paths.
• BFS: doesn’t get caught in loops or dead-end-paths.
Best First Search: explore the most promising path seen so far.
Similar to steepest-ascent, but don’t throw away states that are not
chosen. 10
A* Algorithm
The A* algorithm uses a modified evaluation function and a Best-First
search.
Under the right conditions A* provides the cheapest cost solution in the
optimal time!
This doesn’t make sense for DFS or BFS, but is useful for
Best-First Search.
12
Why we need modified evaluation
Consider a best-first search that generates
the same state many times.
13
A* Algorithm
Best First Search with the modified evaluation function.
14
A* Algorithm
15
Example - Maze
START GOAL
16
Example - Maze
START GOAL
17
A* Optimality and Completeness
18
ARAD
Example: A*
BUCHAREST
Romania with step costs in km
Open List:
Arad
A* search example
We’ve been
to Arad
before. Do
not list it
again on
the open
list.
SIBIU 140+80=220
• 80
The algorithm doesn’t end until we “expand” the goal node – it has to
be at the top of the open list.
Open List:
A* search example
Pitesti
Timisoara
Zerind
Bucharest
Craiova
Oradea
We just found a better value for Bucharest; so, it got moved higher in the list.
We ran into Rimricu Vicea again. Since it’s already been expanded once, we don’t
re-add it to the Open List.
A* search example
Open List:
Bucharest
Timisoara
Zerind
Craiova
Oradea
Chromatic number
Given is a list of
The goal is to find a If a student is
courses, and for each The resulting class
time slot for each registered for courses
course the list of can be coloured with
course (using as few p and q, add an edge
students who want to k number of colour.
slots as possible). between p and q.
register for it.
An application of graph colouring: EXAMPLE 1
The committees must all meet during the first week of classes, but there are only
three time slots available.
Using a graph coloring algorithm, find a schedule that will allow all faculty
members to attend the meetings of all committees on which they serve.
3 time slots An application of graph colouring: EXAMPLE 1
Undergraduate education (UE): Sineman, Limitson, Axiomus, Functionini
Graduate Education (GE): Graphian, Vectorades, Functionini, Infinitescu
Colloquium (C): Lemmeau, Randomov, Proofizaki
Library (L): Van Sum, Sineman, Lemmeau
Staffing (S): Graphian, Randomov, Vectorades, Limitson
Promotion (P): Vectorades, Van Sum, Parabolton
GE
SLOT1 SLOT2 SLOT3
S
• UE • GE •S
UE •P •L
•C
P
C L
Assignment 1: An application of graph colouring
(EXAMPLE 1)
Twelve faculty members in a mathematics department serve on the following
committees:
Undergraduate education: Sineman, Limitson, Axiomus, Functionini
Graduate Education: Graphian, Vectorades, Functionini, Infinitescu
Colloquium: Lemmeau, Randomov, Proofizaki
Library: Van Sum, Sineman, Lemmeau
Staffing: Graphian, Randomov, Vectorades, Limitson
Promotion: Vectorades, Van Sum, Parabolton
The committees must all meet during the first week of classes, but there are
only three time slots available. Using a graph coloring algorithm, find a
schedule that will allow all faculty members to attend the meetings of all
committees on which they serve.
Write a pseudocode for the graph colouring algorithm.
Assignment 2: Graph colouring for exam
timetabling
Suppose that in a particular quarter there are students taking each of the following
combinations of courses:
S1: Math, English, Biology, Chemistry
S2: Math, English, Computer Science, Geography
S3: Biology, Psychology, Geography, Spanish
S4: Biology, Computer Science, History, French
S5: English, Psychology, Computer Science, History
S6: Psychology, Chemistry, Computer Science, French
S7: Psychology, Geography, History, Spanish
Q1: What is the minimum number of examination periods required
for the exams of the ten courses specified so that students
taking any of the given combinations of courses have no
conflicts?
Q2: Find a schedule that uses this minimum number of periods.
http://www.ftsm.ukm.my/cait/DMOLab.html
https://www.facebook.com/dmoukm/
41