Lecture 22

  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Lecture 22 as PDF for free.

More details

  • Words: 2,091
  • Pages: 10
Data Structures Notes for Lecture 22 Algorithms of Searching By Samaher Hussein Ali 2007-2008

Tabu Search Algorithm Tabu Search is a neighborhood search, which means the next possible state is found from the set of neighborhood states and then move to that state. Tabu search the set of all possible neighborhood states and takes the best one. It will take the best move in the neighborhood, even though it might be worse than the current move and doing so tabu search may move away from a good solution in search of others. The main principle behind tabu search is that it has some memory of the states that is has already investigated and it does not re-visit those states. Not re-visiting previously visited states helps in two ways. It avoids the search getting into a loop by continually searching the same area without actually making any progress. In turn, this helps the search explore regions that it might not otherwise explore. The moves that are not allowed to be re-visited are held in a data structure and these moves are called “tabu” . But still there is a special case, which is called “aspiration criterion”. When a tabu move will result in a solution better than any visited so far, its tabu classification may be overridden. A condition that allows such an override to occur is called an aspiration criterion. Tabu Search Algorithm: Initialize Tabu List (TL) = empty Generate a {current} solution S let S* = S be the best solution so far repeat repeat select the best point B in the neighborhood of S: N(S) if(B is not Tabu: B∉ TL) accept move: S=B update Tabu List: TL = TL ∪ B if(eval(B) > eval(S*)) S* = B 1

else if (eval(B) < eval(S*)) accept move: S = B update best: S* = B end until (acceptable move found) until (halting-criterion) Example:The follows example shows how tabu search can be used in solving n queens (here 7-queens) problem step by step. At the beginning a random solution is generated for 7-queens problem as shown in the below figure: Iteration 0: The below figure shows the current solution randomly generated at the iteration number 0. Current solution:

The below figure also shows the same current solution but in a different visual format. From the figure we can see that the current solution has 4 collusions (between Q1 and Q2, between Q4 and Q5, between Q6 and Q7 and between Q4 and Q7).

Number of collisions 4 The Tabu structure is initially empty as there have been no moves yet.

Tabu Structure The below figure shows a swap table with the top five moves out of 21 moves after evaluating the candidate swap moves for the iteration 0. The values in the swap table indicate that ,for example, considering the first row values (1, 7, -2) , if we swap queen 1 and queens 7 queens we may reduce 2

number of collisions by 2. So right now we have 4 collisions, if we swap 1 and 7 queen we will have 2 collisions. Similarly considering the values of fifth row of the swap table if we swap 1 and 5 queens we will reduce number of collisions by 1 as the value is –1 there.

Iteration 1: To locally minimize the total number of collisions, we swap the queens 1 and 7, which the top best value in the swap table of iteration 0. After swapping queen 1 and 7 the below figure shows the current solution. Current solution:

The below figure also shows the same current solution after swapping queen 1 and 7. We can see that currently we decreased the number of collisions by 2 and now we have total number of collisions 2.

Number of collisions 2 The below figure shows the tabu structure at the iteration 1. As we swapped the queen 1 and 7 so we can’t swap queen 1 and 7 again in three iterations. The tabu structure shows that swapping the positions of queens 1 and 7 is forbidden for 3 iterations.

Tabu Structure 3

The below figure shows the swap table with the top 5 moves after swapping queen 1 and 7 at the iteration 1.

Iteration 2: Now at the iteration 2, to locally minimize the total number of collisions , we swap the queens 2 and 4 which the top best value in the swap table of iteration 1. After swapping queens 2 and 4 the below figure shows the current solution. Current solution:

The below figure also shows the same current solution after swapping queen 2 and 4. We can see that currently we decreased the number of collisions by 1 and now we have total number of collisions 1.

Number of collisions 1 The below figure shows the tabu structure at the iteration 2. As we swapped the queen 2 and 4 so we can’t swap queen 2 and 4 again in next three iterations. The tabu structure shows that swapping the positions of queens 2 and 4 is forbidden for 3 iterations. Also as 1 iteration has passed so queens 1 and 7 still have to wait for more two iterations until they are allowed to swap again.

4

The below figure shows the swap table with the top 5 moves after swapping queens 2 and 4 at the iteration 2. We can also see that the second and the three row are marked with T which mean they are in tabu structure. As these two pairs are in the tabu structure so we can’t swap these queen pairs.

Iteration 3: Now at the iteration 3, we swap the queens 1 and 3 which the top best value in the swap table of iteration 2. After swapping queens 1 and 3 the below figure shows the current solution. Current solution:

The below figure also shows the same current solution after swapping queen 1 and 3. We can see that currently we didn’t decrease or increase the number of collisions, as value in the swap table for swapping queen 1 and 3 is zero. So number of collisions is still 1.

Number of collisions 1 The below figure shows the tabu structure at the iteration 3. As we swapped the queen 1 and 3 so we can’t swap queen 1 and 3 again in three iterations. The tabu structure shows that swapping the positions of queens 2 and 4 is forbidden for 2 iterations. Also as 2 iteration has passed so queens 1 and 7 still have to wait for more one iterations until they are allowed to swap again.

Tabu search 5

The below figure shows the swap table with the top 5 moves after swapping queens 1 and 3 at the iteration 3. We can also see that the first and the second row are marked with T. As these two pairs are in the tabu structure so we can’t swap these queen pairs.

Iteration 4: Now at the iteration 4 , we swap the queens 5 and 7 which the top best value in the swap table of iteration 3 as the top two values are in tabu structure. After swapping queens 5 and 7 the below figure shows the current solution. Current solution:

The below figure also shows the same current solution after swapping queen 5 and 7. We can see that currently we increased the number of collisions as value in the swap table for swapping queen 5 and 7 is 1. So number of collisions is 2.

Number of collisions 2 The below figure shows the tabu structure at the iteration 4. As we swapped the queen 5 and 7 so we can’t swap queen 5 and 7 again in three iterations. The tabu structure shows that swapping the positions of queens 2 and 4 is forbidden for 1 iteration and swapping the positions of queens 1 and 3 is forbidden for 2 iterations.

Tabu structure 6

The below figure shows the swap table with the top 5 moves after swapping queens 5 and 7 at the iteration 4. We can also see that the second and the fifth rows are marked with T . As these two pairs are in the tabu structure so we can’t swap these queen pairs.

Iteration 5: Now at the iteration 5 , we swap the queens 4 and 7 which the top best value in the swap table of iteration 4. After swapping queens 4 and 7 the below figure shows the current solution. Current solution:

The below figure also shows the same current solution after swapping queen 4 and 7. We can see that currently we reduced the number of collisions by 1. So number of collisions is 1.

Number of collisions 1 The below figure shows the tabu structure at the iteration 5. As we swapped the queen 4 and 7 so we can’t swap queen 4 and 7 again in three iterations. The tabu structure shows that swapping the positions of queens 1 and 3 is forbidden for 1 iteration and swapping the positions of queens 5 and 7 is forbidden for 2 iterations.

Tabu search The below figure shows the swap table with the top 5 moves after swapping queens 4 and 7 at the iteration 5. We can also see that the first and the third rows are marked with T as those two pair are in the tabu structure .But queen pair in the first row also satisfy the aspiration criterion. 7

Iteration 6: Now at the iteration 6, we swap the queens 1 and 3, which is the top best value in the swap table of iteration 5. We swap this pair although it is in tabu as it satisfies the aspiration criterion which means this move will provide solution which is better than any solutions we got so far. After swapping queens 1 and 3 the below figure shows the current solution which is the final solution as there are no collisions. Current solution:

The below figure also shows the same current solution after swapping queen 1 and 3. We can see that currently we reduced the number of collisions by 1. So number of collisions is 0, which is the final solution as no queens attack each other.

Number of collisions 0 So , thus using tabu search we can find solution for n-queens problem.

Block Search Algorithm ‫ﺧﻮارزﻣﻴﺔ اﻟﺒﺤﺚ اﻟﻜﺘﻠﻲ‬ -:‫ﻓﻜﺮﺗﻬﺎ‬ ‫( وﺗﻜ ﻮن ﻋﻨﺎﺻ ﺮ ه ﺬﻩ اﻟﻜﺘ ﻞ ﻣﺮﺗﺒ ﺔ ﻋﻠ ﻰ اﺳ ﺎس ان آ ﻞ ﻋﻨ ﺼﺮ ﻣ ﻦ اﻟﻌﻨﺎﺻ ﺮ اﻟﻤﻜﻮﻧ ﺔ ﻟﻠﻜﺘﻠ ﺔ‬blocks) ‫ﺗﻘﺴﻴﻢ ﻗﺎﺋﻤﺔ اﻟﺒﻴﺎﻧﺎت اﻟﻰ آﺘ ﻞ‬ ‫اﻻوﻟﻰ ﻳﻜﻮن اﺻﻐﺮ ﻣﻦ ﺟﻤﻴﻊ اﻟﻌﻨﺎﺻﺮ اﻟﻤﻜﻮﻧﺔ ﻟﻠﻜﺘﻠﺔ اﻟﺜﺎﻧﻴﺔ وآﻞ ﻋﻨﺼﺮ ﻓﻲ اﻟﻜﺘﻠﺔ اﻟﺜﺎﻧﻴﺔ ﻳﻜ ﻮن اﺻ ﻐﺮ ﻣ ﻦ ﺟﻤﻴ ﻊ اﻟﻌﻨﺎﺻ ﺮ اﻟﻤﻜﻮﻧ ﺔ‬ .‫ﻟﻠﻜﺘﻠﺔ اﻟﺜﺎﻟﺜﺔ وهﻜﺬا وﻋﻠﻴﻪ ﻳﺠﺐ ﺗﺤﺪﻳﺪ اآﺒﺮ واﺻﻐﺮ ﻋﻨﺼﺮ ﻟﻜﻞ آﺘﻠﺔ‬ 8

‫ان اﻟﺒﺤﺚ ﺑﻬﺬﻩ اﻟﻄﺮﻳﻘﺔ ﻳﻌﻨﻲ ﻣﻘﺎرﻧﺔ اﻟﻌﻨﺼﺮ اﻟﻤﻄﻠﻮب ﻣﻊ اآﺒﺮ او اﺻﻐﺮ ﻋﻨﺼﺮ ﻟﻜﻞ آﺘﻠﺔ ﻣ ﻦ اﻟﻜﺘ ﻞ اﻟﻤﻜﻮﻧ ﺔ ﻟﻠﻘﺎﺋﻤ ﺔ اﻟﻤﻌﻄ ﺎة اﻟ ﻰ ان ﻳ ﺘﻢ‬ ‫ﺗﺤﺪﻳﺪ اﻟﻜﺘﻠﺔ اﻟﺘﻲ ﻣﻦ اﻟﻤﻤﻜﻦ ان ﻳﻜﻮن اﻟﻌﻨ ﺼﺮ اﻟﻤﻄﻠ ﻮب ﻓﻴﻬ ﺎ وﻳ ﺘﻢ اﻟﺒﺤ ﺚ ﻋ ﻦ ﺗﻠ ﻚ اﻟﻜﺘﻠ ﺔ ﺑﺎﺳ ﺘﺨﺪام ﻃﺮﻳﻘ ﺔ اﻟﺒﺤ ﺚ اﻟﺜﻨ ﺎﺋﻲ وﻟﻠﺒﺤ ﺚ ﻋ ﻦ‬ ‫اﻟﻌﻨﺼﺮ ﺿﻤﻦ اﻟﻜﺘﻠﺔ ﻧﺴﺘﺨﺪم ﻃﺮﻳﻘﺔ اﻟﺒﺤﺚ اﻟﺘﺴﻠﺴﻠﻲ‪.‬‬ ‫ﻣﺜﺎل ‪ -:‬اﺑﺤﺚ ﻋﻦ اﻟﻌﺪد ‪ 18‬ﻓﻲ اﻟﻘﺎﺋﻤﺔ اﻟﺘﺎﻟﻴﺔ ﺑﺎﺳﺘﺨﺪام اﻟﺒﺤﺚ اﻟﻜﺘﻠﻲ‬ ‫‪15‬‬

‫‪20‬‬

‫‪16‬‬

‫‪18‬‬

‫‪17‬‬

‫‪13‬‬

‫‪14‬‬

‫‪9‬‬

‫‪10‬‬

‫‪11‬‬

‫‪4‬‬

‫‪6 5‬‬

‫‪8‬‬

‫اﻟﺤﻞ‪ -:‬ﻧﻘﺴﻢ اﻟﻘﺎﺋﻤﺔ اﻟﻰ آﺘﻞ‬ ‫اﻟﻜﺘﻠﺔ اﻻوﻟﻰ‬

‫اﻟﻜﺘﻠﺔ اﻟﺜﺎﻧﻴﺔ‬

‫اﻟﻜﺘﻠﺔ اﻟﺜﺎﻟﺜﺔ‬

‫‪2‬‬

‫‪11‬‬

‫‪17‬‬

‫‪8‬‬

‫‪9‬‬

‫‪18‬‬

‫‪6‬‬

‫‪10‬‬

‫‪16‬‬

‫‪5‬‬

‫‪13‬‬

‫‪20‬‬

‫‪4‬‬

‫‪14‬‬

‫‪15‬‬ ‫اذن ﻧﻬﻤﻞ اﻟﻜﺘﻠﺔ اﻻوﻟﻰ ‪8<18 -------------‬‬ ‫اذن ﻧﻬﻤﻞ اﻟﻜﺘﻠﺔ اﻟﺜﺎﻧﻴﺔ ‪14<18 -------------‬‬ ‫اذن ﻧﺒﺤﺚ ﻋﻦ اﻟﻌﻨﺼﺮ ﻓﻲ اﻟﻜﺘﻠﺔ اﻟﺜﺎﻟﺜﺔ ‪20>18 -------------‬‬

‫ان اﻓﻀﻞ ﻃﺮﻳﻘﺔ ﻟﺘﻘﺴﻴﻢ اﻟﻘﺎﺋﻤﺔ اﻟﻰ آﺘﻞ هﻮ ان ﻳﻜﻮن ﻋﺪد ﻋﻨﺎﺻﺮ آﻞ آﺘﻠﺔ ﻳﺴﺎوي‪-:‬‬

‫‪Lblock = Lb + Lw = n‬‬ ‫ﺣﻴﺚ‪-:‬‬ ‫‪ n‬ﻳﻤﺜﻞ ﻋﺪد اﻟﻌﻨﺎﺻﺮ‬ ‫‪ Lblock‬ﻣﻌﺪل ﻃﻮل اﻟﺒﺤﺚ اﻟﻜﺘﻠﻲ‬ ‫‪ Lb‬ﻣﻌﺪل ﻃﻮل اﻟﺒﺤﺚ ﻋﻦ اﻟﻜﺘﻠﺔ اﻟﺘﻲ ﻳﻮﺟﺪ ﻓﻴﻬﺎ اﻟﻌﻨﺼﺮ‬ ‫‪ Lw‬ﻣﻌﺪل ﻃﻮل اﻟﺒﺤﺚ ﻋﻦ اﻟﻌﻨﺼﺮ ﺿﻤﻦ اﻟﻜﺘﻠﺔ‬ ‫ﻣﺜﺎل ‪ -:‬اذا آﺎن ﻟﺪﻳﻚ ﻗﺎﺋﻤﺔ ﻋﺪد ﻋﻨﺎﺻﺮهﺎ ﻋﺸﺮة اﻻف ﻋﻨﺼﺮ ﺟﺪ ﻣﻌﺪل ﻃﻮل اﻟﺒﺤﺚ ﻟﻜﻞ ﻣﻤﺎ ﻳﺎﺗﻲ‪-:‬‬ ‫* ﻋﻨﺪﻣﺎ ﻧﺴﺘﺨﺪم ﻃﺮﻳﻘﺔ اﻟﺒﺤﺚ اﻟﻜﺘﻠﻲ‬ ‫* ﻋﻨﺪﻣﺎ ﻧﺴﺘﺨﺪم ﻃﺮﻳﻘﺔ اﻟﺒﺤﺚ اﻟﺘﺴﻠﺴﻠﻲ‬ ‫* ﻋﻨﺪﻣﺎ ﻧﺴﺘﺨﺪم ﻃﺮﻳﻘﺔ اﻟﺒﺤﺚ اﻟﺜﻨﺎﺋﻲ‬

‫‪9‬‬

‫‪2‬‬

Lblock= n Lsequ=

= 10000 = 100

n + 1 10000 + 1 = = 5000 2 2

Lbinary=ln(n+1)-1 = ln(10000+1)-1

Lbinary +1=ln(10001)

2 (Lbinary +1) = 10001 2 (Lbinary +1) = 214 Lbinary+1=14 Lbinary=13 ‫ﻣﻦ هﺬا ﻧﺴﺘﻨﺘﺞ اﻧﻨﺎ ﺑﻮاﺳﻄﺔ اﻟﺒﺤﺚ اﻟﺜﻨﺎﺋﻲ ﺣﺼﻠﻨﺎ ﻋﻠﻰ اﻗﻞ ﻣﻌﺪل ﻃﻮل ﺑﺤﺚ‬

10

Related Documents

Lecture 22
May 2020 5
Lecture 22
May 2020 2
Lecture 22
December 2019 10
Lecture 22
May 2020 3
Lecture 22
April 2020 3
Lecture 22
November 2019 17