Research Article
A Fast Fully Parallel Ant Colony Optimization Algorithm Based on CUDA for Solving TSP
Algorithm 1
Kernel function <<<BN, 128>>>.
| Begin: | | idx ← blockDim.x × blockIdx.x + threadIdx.x | | idy ← blockDim.y × blockIdx.y + threadIdx.y | | thread_id ← (gridDim.x blockDim.x) × idy + idx | | Ini_City ← random (int) [1-N] | | for i:1 to N | | for j:1 to i | | //update visited cities | | end for | | for j:1 to N | | flag ← 0 | | for k:0 to N-i//Find out unvisited cities | | if visited [k] = = k | | flag ← 1 | | end if | | end for | | if flag = = 0 | | unvisited [unvisited_index++] = j | | end if | | end for | | __syncthreads(); | | for i:1 to unvisited_index | | //Calculating probability of selecting unvisited cities and cumulative probability | | End for | | //Roulette | | End for | | L ← 0 | | deta_tao [N][N] ← 0 | | R[N] ← 0 | | for i:1 to N | | R [i-1] ← visited city [i-1] | | end for//Record the nodes on the shortest path | | //calculating length of the shortest path | | L ← distance [[R [N-1]-1] [R [0] -1]] | | for i:1 to N-1 | | L ← L + distance [ R[i]-1]] [R[i + 1]-1] | | end for | | __syncthreads(); | | //Pheromone update using compensation mechanism | | End. |
|