- PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Description:

Recall that an algorithm is a set of procedures or rules that, when followed, ... the Commander has asked the helm to chart the course that will use the lowest ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 16
Provided by: biolog5
Learn more at: http://www.math.ku.edu
Category:
Tags: helm

less

Transcript and Presenter's Notes

Title:


1
6.5 - 6.8 Algorithms, Algorithms, Algorithms
2
  • Recall that an algorithm is a set of procedures
    or rules that, when followed, lead to a
    solution to a particular problem.

3
Think back to the Homer example from
yesterday.The method we used there can be
written as a slightly more formal algorithm
  • The Brute-Force Algorithm
  • First, make a list of all the possible
    Hamiltonian circuits of the graph.
  • For each circuit, calculate its total weight by
    summing the weights of all the edges traveled.
  • Find the circuits with the least total weight.
    Any of these can be chosen as an optimal H.C.

4
THE METHOD USED IN OUR OTHER (EVEN GEEKIER)
EXAMPLE FROM YESTERDAY CAN ALSO BE MADE A BIT
MORE FORMAL. . .
  • THE NEAREST NEIGHBOR ALGORITHM
  • PICK ANY VERTEX AS A STARTING POINT.
  • FROM THE STARTING VERTEX GO TO ITS NEAREST
    NEIGHBOR--THE NEAREST VERTEX FOR WHICH THE
    CORRESPONDING EDGE HAS THE SMALLEST WEIGHT.
  • CONTINUE BUILDING THE CIRCUIT, ONE VERTEX AT A
    TIME, ALWAYS CHOOSING THE NEAREST NEIGHBOR FROM
    THE VERTICES THAT HAVE NOT BEEN TRAVELED YET.
  • FROM THE LAST VERTEX RETURN TO YOUR STARTING
    POINT.

5
So which of these methods is better? The
Brute-Force Method will always give the optimal
solution, but it is inefficient. The Nearest
Neighbor Algorithm on the other hand is efficient
but not always accurate. Given its efficiency,
one might ask if there is a way to improve on the
second algorithm.
6
  • The Repetitive Nearest-Neighbor Algorithm
  • Let X be any vertex. Apply the Nearest-Neighbor
    Algorithm using X as the starting point and
    calculate the total cost for the circuit.
  • Repeat the process for each of the other
    vertices of the graph.
  • Choose the best Hamiltonian circuit you find.
    If we have designated a starting vertex, then
    rewrite the circuit with that vertex as the
    reference point.

7
Example The Galactica needs to survey a set of
planets (A, B, C, D, E, F, G) in order to find
water for the Fleet. the Commander has asked the
helm to chart the course that will use the lowest
amount of tylium fuel.
LET US REVISIT THE SECOND EXAMPLE FROM YESTERDAY,
ARMED THIS TIME WITH THE REPETITIVE NEAREST
NEIGHBOR ALGORITHM. . .
8
THE FOLLOWING TABLE TELLS US HOW MANY TONS OF
TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO
ANOTHER
A B C D E F G
A 75 50 28 35 15 22
B 75 30 60 80 65 50
C 50 30 40 48 35 28
D 28 60 40 20 30 29
E 35 80 48 20 40 32
F 15 65 35 30 40 13
G 22 50 28 29 32 13
YESTERDAY WE FOUND THAT THE N.N. ALGORITHM
APPLIED TO A GAVE US THE FOLLOWING CIRCUIT AND
WEIGHT a,f,g,c,b,d,e,a15132830602035201
9
THE FOLLOWING TABLE TELLS US HOW MANY TONS OF
TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO
ANOTHER
A B C D E F G
A 75 50 28 35 15 22
B 75 30 60 80 65 50
C 50 30 40 48 35 28
D 28 60 40 20 30 29
E 35 80 48 20 40 32
F 15 65 35 30 40 13
G 22 50 28 29 32 13
NOW STARTING WITH B WE GET 302813152820802
14b,c,g,f,a,d,e,b
10
THE FOLLOWING TABLE TELLS US HOW MANY TONS OF
TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO
ANOTHER
A B C D E F G
A 75 50 28 35 15 22
B 75 30 60 80 65 50
C 50 30 40 48 35 28
D 28 60 40 20 30 29
E 35 80 48 20 40 32
F 15 65 35 30 40 13
G 22 50 28 29 32 13
NOW STARTING WITH C WE GET 281315282080302
14c,g,f,a,d,e,b,c
11
THE FOLLOWING TABLE TELLS US HOW MANY TONS OF
TYLIUM IT TAKES TO TRAVEL FROM ONE PLANET TO
ANOTHER
SIMILARLY FOR d, e, f AND g WE GET 2035151328
5060221d,e,a,f,g,c,b,d 2028151328308021
4e,d,a,f,g,c,b,e 15222920483065229f,a,g,d
,e,c,b,e 13152820483050204g,f,a,d,e,c,b
A B C D E F G
A 75 50 28 35 15 22
B 75 30 60 80 65 50
C 50 30 40 48 35 28
D 28 60 40 20 30 29
E 35 80 48 20 40 32
F 15 65 35 30 40 13
G 22 50 28 29 32 13
12
  • The Cheapest-Link Algorithm
  • Pick the edge with the smallest weight first.
    Mark the edge (or otherwise note that you have
    chosen it).
  • Pick the next cheapest edge. Mark or note it.
  • Continue picking the cheapest edge available
    and mark the edge as long as (a) it does not
    close a circuit and (b) it does not result in
    three edges coming out of a single verrtex.
  • When there are no more vertices left, close the
    circuit.

13
B
75
30
60
65
WE CAN USE THIS NEW ALGORITHM ON OUR SECOND
EXAMPLE
A
50
C
28
28
48
22
35
40
35
50
29
G
D
30
15
32
13
20
80
40
F
E
14
B
75
30
60
65
A
50
C
28
28
48
22
35
40
35
50
29
G
D
30
15
32
13
20
80
40
F
E
15
A Few Final notes
  • The Nearest-Neighbor, Repetitive N.N. and
    Cheapest-Link Algorithms are all approximate
    algorithms.
  • I.e. - The routes they make may not be the
    optimal solution, but they are usually better
    than a random approach.
  • The amount of time needed to arrive at these
    approximate routes is much shorter than using the
    Brute-Force method which is why they are used
    more often in real-life situations.
Write a Comment
User Comments (0)
About PowerShow.com