ΠΛΗ31 ΜΑΘΗΜΑ 1.3 (ΕΚΤΥΠΩΣΗ)

download ΠΛΗ31 ΜΑΘΗΜΑ 1.3 (ΕΚΤΥΠΩΣΗ)

of 19

  • date post

    22-Jan-2018
  • Category

    Education

  • view

    4.008
  • download

    0

Embed Size (px)

Transcript of ΠΛΗ31 ΜΑΘΗΜΑ 1.3 (ΕΚΤΥΠΩΣΗ)

  1. 1. 31 1: 1.3: ! !"#$% & ' !#$% ( )#$% & * + ,-. / 0 +1 & 2 0 3 4+ ( 2 5 + 6 2+ 7 2 + + 8 9 2 + + 81 ( * + :")#$% & + 3 ; * + >?@ / 0 +1 & 2 0 3 4+ ( 2 5 + 6 2+ 7 2 + + 8 9 2 + + 81 ( * + :" / 0 +1 & 2 0 3 4+ ( 2 5 + 6 2+ 7 2 + + 8 9 2 + + 81 A . ! " # $! %& ' '(! '(! UCS '(! A* " # ) ! " # ) * ( ( * %' " # + (-) ). , & " 1. $! %& ( : " *- !' # & - % & " *- !' ! . " ! % - !- " & * -/ "! " & * -/ ( ! '(! ' '(! % ' ( * -& " ' % !0 ! & / '(! ( * ' % !0 ! & / . 123 $ 2 123 3 $ ) ,
  2. 2. ). , & " 1. $! %& # ( ! -/ & " ( : #! 3 4 4 A B C - " S ' " G. ! # . . " -/ 3 4 5 2 5 4 3 S D E F G $! S A DB D A E 3 4 5 54 425 54 4 2 E F C G D E B F C G B C E F G B F A C G 4 2 5 5 4 4 44 4 43 3 3 3 : S,A,B,E,F,G : S,A,D,E,F,G : S,D,A,B,E,F,G : S,D,E,F,G # *4 # # *4 # # *4 # # *4 # # *4 # # *4 # ). , & " 1. $! %& * # 1. ( ! h*(v) - ! ! * # ( ! v ! % - !- , ! h*(v) " ! %! " ( ! h*(v) ! % v -/ & ! ( % / / ) %*' ! v ! % - !- . ! % - !- , ! h*(v) " ! ' ! # * . 5 : + ' : h*( )=0 + " v # # ( " ' : h*(v)=+6 ! # . *- & " ! % ( ! ! ! % !- . &! S A DB D A E 3 4 5 54 425 54 4 2 12 9 14 16 7 9 13 ! - / . " h* ( ! % E F C G D E B F C G B C E F G B F A C G 4 2 5 5 4 4 44 4 43 3 3 3 : S,A,B,E,F,G : S,A,D,E,F,G : S,D,A,B,E,F,G : S,D,E,F,G 0 3+ + 7 0+ + 3 7 0 3 + 7 12 + + + 0 3
  3. 3. ). , & " 1. $! %& * # 1. ( ! h*(v) ( & " ( ! , ! 4 ! % % . *- ! ! . ( * '(! * - & 4 : '! ' # ' ' (" %*' ' . ). , & " 1. $! %& * # 2. h(v) 4 # ( & " ( ! . + # ( "- * 4* " ' " "# . (! " h(v) ! % v -/ h(v) ! % , / ! -! " v ( # ( ! % - !- . (" & / ! 4 / ! !%' . " h(v) ! % v -/ & " " ! *- ! % ! * ! % - !- . '*( # # ( ! ! ! % , # ' # : h(v)7h*(v) ( ! % v -/ . ). , & " 1. $! %& * # 2. h(v) * * " ! *- ! % ! ! % !- . ! s *- # % " %*' ! , # ! ! # ' # '(! " . # # # "( # / / & . v t h(v) / h(v)7h*(v) ). , & " 1. $! %& * # 2. h(v): %' 1 / %' * - , " & ! ( . ! )*' # ! " ! " ( # * %*' ! , ! ( # . ! " +
  4. 4. ). , & " 1. $! %& * # 2. h(v): %' % " & %' ' % " & " ! Manhattan ! % ! ! % - !- .& : ! B " manhattan ((x1,y1),(x2,y2)) = |x1-x2|+|y1-y2| B " $! % ! Manhattan ' (" ' & - !# , # * ( ! ! . " 8 " ) C " " 8 ) C " $! % !- " (& (3,3) ). , & " 1. $! %& * # 3. ! # # g(v) H ' (" ! # *- ' / ( . *- ! % v. 1 " ! '(! * UCS ( ' ( ! "! H $! # # g(v) ! % v -/ " & % / & / ! " *- ! % v. 1 " ! '(! * UCS ( ' ( ! ! ! % - ". v t s h(v) / h(v)7h*(v) g(v) ! *-& ' / *- v #! S A DB D A E 3 4 5 54 425 54 4 2 12 9 14 16 7 9 13 ! - / . " h* ( ! % ' - / . " h ( ! % 12/0 11/3 7/4 7/7 7/8 4/9 5/6 .* - / . " g ( ! % E F C G D E B F C G B C E F G B F A C G 4 2 5 5 4 4 44 4 43 3 3 3 : S,A,B,E,F,G : S,A,D,E,F,G : S,D,A,B,E,F,G : S,D,E,F,G 0 3+ + 7 0+ + 3 7 0 3 + 7 12 + + + 0 3 + /11 4/12 + /14 + /15 2/16 5/10 2/14 4/13 + /17 6/18 + /11 + /15 + /15 0/17 3/22 0/19 0/25 0/13 3/10 + /19 ). , & " 3. '(! 1. ' '(! '(! ' % !0 % & / !- % * ! - ' . 1 '(! ' " ' '(! " % '*( 4 " $! ' '(! " % '*( 4 " ! % *- ! ! ! , # ' # *. " * ! # ( ( ( %*' ' .
  5. 5. ). , & " 3. '(! 1. ' '(! (1. # ('/ ) %! GREEDY(S,T) =[(S,f(S))] =[] : 1. v f(v) f(u) u 2. v 3. ! ! " ! v. " v3. ! ! " ! v. " v # " . 4. v $ " # % # & # ' $ ! " u v: 4.1 (# % f(u) 4.2 ( u % & , & ) ) % (u,f(u)) ' ( u % % % ) ! ! ' % f(u) # % ) ( >=# ) & u # ! " ! v & (u,# ) # # ! % ) ' ! (u, ' ) %. 0 # " & f(x) h(x) ). , & " 2. '(! 1. ' '(! (1. # ('/ ) : &! ! "#$ - : ) . " #* # f(x)=h(x). ' :' : % . &' % ( " ( # " !( " ) ( . * & # f(v)=h(v). #" ' . #* # : # 8 - #* # ! . - !. - #* # ! " , ! ' % . 8 - #* # ( ' , # ( . 8 - . & ! : ! % - !- 12 '! S ). , & " 2. '(! 1. ' '(! (2. # ( *' ) ( % ) #* + * +# + 0 {(S,12)} {} (! A D 12S (1) 11 7 ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)}
  6. 6. ! A E A D 12S (1) 11 7 (2) 4 5 ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} ! A E A D 12S (1) 11 7 (2) 4 5 (3) B 4 ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} 3 {(B,4),(E,5)} {(S,12),(D,7),(A,4)} ! A E A D 12S (1) 11 7 (2) 4 5 (3) (4) C E B 4 + 6 (4) ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} 3 {(B,4),(E,5)} {(S,12),(D,7),(A,4)} 4 {(C,+6),(E,5)} {(S,12),(D,7),(A,4),(B,4)} "! A E A D 12S (1) 11 7 (2) 4 5 (3) (4) (5) B F C E B 4 + 6 (4) + 3 ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} 3 {(B,4),(E,5)} {(S,12),(D,7),(A,4)} 4 {(C,+6),(E,5)} {(S,12),(D,7),(A,4),(B,4)} 5 {(C,+6),(F,3)} {(S,12),(D,7),(A,4),(B,4), (E,5)}
  7. 7. #! A E A D 12S (1) 11 7 (2) 4 5 (3) (4) (5) (6) G0 0 B F C E B 4 + 6 (4) + 3 (6) ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} 3 {(B,4),(E,5)} {(S,12),(D,7),(A,4)} 4 {(C,+6),(E,5)} {(S,12),(D,7),(A,4),(B,4)} 5 {(C,+6),(F,3)} {(S,12),(D,7),(A,4),(B,4), (E,5)} 6 {(C,+6),(G,0)} {(S,12),(D,7),(A,4),(B,4), (E,5),(F,3)} $! A E A D 12S (1) 11 7 (2) 4 5 (3) (4) (5) (6) ( % ) #* + * +# + 0 {(S,12)} {} 1 {( ,11),(D,7)} {(S,12)} 2 {( ,4),(E,5)} {(S,12),(D,7)} G B F C E B 4 + 6 (4) + 3 (6) 0 (7) 3 {(B,4),(E,5)} {(S,12),(D,7),(A,4)} 4 {(C,+6),(E,5)} {(S,12),(D,7),(A,4),(B,4)} 5 {(C,+6),(F,3)} {(S,12),(D,7),(A,4),(B,4), (E,5)} 6 {(C,+6),(G,0)} {(S,12),(D,7),(A,4),(B,4), (E,5),(F,3)} 7 {(C,+6)} {(S,12),(D,7),(A,4),(B,4), (E,5),(F,3),(G,0)} : S-D-E-F-G $! : 13 " 0 : S-D-A-E-B-F-G ) : 7 ). , & " 2. '(! 1. 9 ' '(! (3. ) " " 1: , : 4 % : ; ( # ! ! % " / - " ' 4 ( . ( '. % ) *- ( ' " & , ( " ! % '*( " ! ! . %! ! . " " 2: * % % - % %'" " # : ! % - !- . " ! % !- (! *- ! % " " 3: # & ' .%/ ' 0 " & # : '*( ! ! % " 0 '! " # " "# " # , ! '*( ! % " . 4 ( . ' ( ). , & " 2. '(! 1. 9 ' '(! (4.1 ) - ' '( " " !' : " , (( .! ! - . (+ # - . % " %*' ' &! - . % " %*' ' 1" )#* 2 * : (bd) 13"#* 2 * : (bd)
  8. 8. ). , & " 2. '(! 2. '(! UCS 2 '(! ' " UCS (Uniform Cost Search) " % '*( 4 " ! % *- ! ! # # , # ' # " " . UCS % " %*' ' ( " '! UCS % " %*' ' ( " # # - !' ! . " 4 ! (' ( " ! & '(! Dijkstra) ). , & " 2. '(! 2. '(! UCS (1. # ('/ ) (! UCS(S,T) =[(S,f(S))] =[] : 1. v f(v) f(u) u 2. v 3. ! ! " ! v. " v3. ! ! " ! v. " v # " . 4. v $ " # % # & # ' $ ! " u v: 4.1 (# % f(u) 4.2 ( u % & , & ) ) % (u,f(u)) ' ( u % % % ) ! ! ' % f(u) # % ) ( >=# ) & u # ! " ! v & (u,# ) # # ! % ) ' ! (u, ' ) %. 0 # " & f(x) g(x) ). , & " 2. '(! 2. '(! UCS (1. # ('/ ) : ! ! "#$ UCS - : ) . " #* # f(x)=g(x). ' :' : % . &' % ( " ( # " !( " ) ( . * & # f(v)=g(v). #" ' . #* # : # 8 - #* # ! . - !. - #* # ! " , ! ' % . 8 - #* # ( ' , # ( . 8 - . & ! : ! % - !- S 0 ! ). , & " 2. '(! 2. '(! UCS (2. # ( *' ) ( % ) #* + * +# + 0 {(S,0)} {}
  9. 9. ! A D 3 4 S 0 (1) 3 4 ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} "! DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} #! A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} $! 5 4 A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 (4) B F11 10 ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} 4 {(B,7),(F,10)} {(S,0),(A,3),(D,4),(E,4)}
  10. 10. %! 54 5 4 A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 (4) (5) EC B F11 10 11 12 ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} 4 {(B,7),(F,10)} {(S,0),(A,3),(D,4),(E,4)} 5 {(F,10),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7)} &! 54 5 4 A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 (4) (5) (6) G 3 EC B F1111 12 10 13 (6) ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} 4 {(B,7),(F,10)} {(S,0),(A,3),(D,4),(E,4)} 5 {(F,10),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7)} 6 {(G,13),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7), (F,10)} F '! 54 5 4 A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 (4) (5) (6) (7) G 3 EC B F1111 12 10 13 (6) ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} 4 {(B,7),(F,10)} {(S,0),(A,3),(D,4),(E,4)} 5 {(F,10),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7)} 6 {(G,13),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7),(F,10)} 7 {(G,13)} {(S,0),(A,3),(D,4),(E,4),(B,7),(F,10),(C,11)} "(! 54 5 4 A E 5 2 DB 54 A D 3 4 S 0 (1) 3 4 (2) 7 8 (3) 9 6 (4) (5) (6) (7) G 3 EC B F1111 12 10 13 (6) (8) ( % ) #* + * +# + 0 {(S,0)} {} 1 {(A,3),(D,4)} {(S,0)} 2 {(D,4),(B,7)} {(S,0),(A,3)} 3 {(B,7),(E,6)} {(S,0),(A,3),(D,4)} 4 {(B,7),(F,10)} {(S,0),(A,3),(D,4),(E,4)} 5 {(F,10),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7)} 6 {(G,13),(C,11)} {(S,0),(A,3),(D,4),(E,4),(B,7),(F,10)} 7 {(G,13)} {(S,0),(A,3),(D,4),(E,4),(B,7),(F,10),(C,11)} 8 {} {(S,0),(A,3),(D,4),(E,4),(B,7),(F,10),(C,11),(G,13)} : S-D-E-F-G $! : 13 " 0 : S-A-D-E-B-F-C-G ) : 8
  11. 11. ). , & " 2. '(! 2. '(! UCS (3. ) " " 1: , : 4 % : ; ( # ! ! % " / - " ' 4 ( . ( '. % ) *- ( ' " & , ( " ! % '*( " ! ! . "! ! . " " 2: * % % - % %'" " # ! % - !- . " ! % !- (! *- ! % " " 3: # & ' .%/ ' 0 " & # : '*( ! ! % " 0 '! " # " "# " # , ! '*( ! % " . 4 ( . ' ( ). , & " 2. '(! 2. '(! UCS (4.1 ) - ' '( " " !' : " , (( .! ! - . (+ # . (( %*' ' "! . (( %*' ' 1" )#* 2 * : (bd) 13"#* 2 * : (bd) ). , & " 2. '(! 3. '(! A* 3 '(! ' " A*, " % '*( 4 " ! % *- ! & / h ! g, # ' # " ' . O A* % " %*' ' , .! "! O A* % " %*' ' , .! - " " # . ). , & " 2. '(! 3. '(! * (1. # ('/ ) ""! *(S,T) =[(S,f(S))] =[] : 1. v f(v) f(u) u 2. v 3. ! ! " ! v. " v3. ! ! " ! v. " v # " . 4. v $ " # % # & # ' $ ! " u v: 4.1 (# % f(u) 4.2 ( u % & , & ) ) % (u,f(u)) ' ( u %