Sei sulla pagina 1di 8

CLARANS

data
10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
1.Input parameters numlocal and maxneighbor.
Initialize i to 1, and mincost to a large number.

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

10

k=3
numlocal = 10
maxneighbor = 5
i=1
mincost = 9999

Data
10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
2.Set current to an arbitrary node in Gn,k.
3.Set j to 1.

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

cost
3.1623
4
0
2.2361
3
2.2361
2.2361
6.0828
3.1623
0
1.4142
1.4142
3.6056
0
2.2361

K#
3
2
2
3
2
3
3
2
3
1
3
3
3
3
1

10

Step 2. current = Gn,k. = {(4,1), (6,9), (7,3)}


cost(current) = 34.7856
Step 3. j = 1

note: S1 and S2 are neighbors if and only if |S1 S2| = k-1

Data
10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
4.Consider a random neighbor S of current, and
based on Equation (5) calculate the cost differential
of the two nodes.
5.If S has a lower cost, set current to S, and go to
Step (3).
6. Otherwise, increment j by 1. If j <= maxneighbor,
go to Step (4).

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

cost
4.4721
4
0
2.2361
3
2.2361
2.2361
6.0828
2.8284
0
0
2
4.2426
1.4142
2.2361

K#
3
2
2
3
2
3
3
2
3
1
3
3
2
3
1

10

Step 4. random S = {(4,1), (6,9), (6,2)}


cost(S) = 36.98
Step 5. -Step 6. j = j + 1 , j = 2
j <= maxneighbor goto step (4)

Data

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
4.Consider a random neighbor S of current, and
based on Equation (5) calculate the cost differential
of the two nodes.
5.If S has a lower cost, set current to S, and go to
Step (3).
6. Otherwise, increment j by 1. If j <= maxneighbor,
go to Step (4).

10

10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

cost

K#

2.8284
4
0
3.1623
3
1
3.1623
6.0828
2
0
2
0
4.1231
1.4142
2.2361

3
2
2
1
2
3
1
2
3
1
3
3
3
3
1

Step 4. random S = {(4,1), (6,9), (8,2)}


cost(S) = 35.009
Step 5. -Step 6. j = j + 1 , j = 3
j <= maxneighbor goto step (4)

Data

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
4.Consider a random neighbor S of current, and
based on Equation (5) calculate the cost differential
of the two nodes.
5.If S has a lower cost, set current to S, and go to
Step (3).
6. Otherwise, increment j by 1. If j <= maxneighbor,
go to Step (4).

10

10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

cost

K#

3.1623
0
4
2.2361
6.3246
2.2361
2.2361
2.2361
3.1623
0
1.4142
1.4142
3.6056
0
2.2361

3
2
2
3
3
3
3
2
3
1
3
3
3
3
1

Step 4. random S = {(4,1), (2,9), (7,3)}


cost(S) = 34.263
Step 5. cost(S)<cost(current)
current = {(4,1), (2,9), (7,3)}
goto step (3)

Data

8
7
6
5
4
3
2
1
0

Algorithm CLARANS
3.Set j to 1.
4.Consider a random neighbor S of current, and
based on Equation (5) calculate the cost differential
of the two nodes.
5.If S has a lower cost, set current to S, and go to
Step (3).
6. Otherwise, increment j by 1. If j <= maxneighbor,
go to Step (4).

10

10
2
6
5
9
8
5
0
8
4
6
8
9
7
2

4
9
9
4
9
1
4
8
0
1
2
2
6
3
2

cost

K#

2.2361
0
4
3.1623
3
4
3.1623
2.2361
4.1231
0
2.2361
4.1231
0
3.6056
2.2361

3
2
2
1
3
1
1
2
1
1
1
1
3
1
1

current = {(4,1), (2,9), (7,3)}


cost(current) = 34.263
Step 3. j = 1
Step 4. random S = {(4,1), (2,9), (9,6)}
cost(S) = 38.121
Step 5. -Step 6. j = j + 1 , j = 2
j <= maxneighbor goto step (4)

current = {(4,1), (2,9), (7,3)}


cost(current) = 34.263
j=1
random S = {(4,1), (2,9), (9,6)} cost(S) = 38.121
j=2
random S = {(4,1), (2,9), (10,4)} cost(S) = 38.087
j=3
random S = {(4,1), (5,4), (7,3)} cost(S) = 40.888
j=4
random S = {(4,1), (9,9), (7,3)} cost(S) = 39.16
j=5
random S = {(2,2), (2,9), (7,3)} cost(S) = 37.422
j=6
j > maxneighbor goto step 7
Step 7. cost(current) < mincost
mincost = cost(current) = 34.263
bestnode = current = {(4,1), (2,9), (7,3)}
Step 8. i = i + 1 , i = 2
i < numlocal goto step (2)

random
set ?
current
?

Algorithm CLARANS
7. Otherwise, when j > maxneighbor, compare the
cost of current with mincost. If the former is less
than mincost, set mincost to the cost of current,
and set bestnode to current.
8. Increment i by 1. If i > numlocal, output
bestnode and halt. Otherwise, go to Step (2).
8

Potrebbero piacerti anche