Computer Science Department - University of Puerto Rico
Prepared by: José R. Ortiz-Ubarri
A Costas array is an permutation matrix (
) such that
vectors connecting two
of the matrix are all distinct as vectors. Equivalently a Costas sequence of length
is a permutation
with the distinct different property.
A Costas array 2 4 3 1 2 -1 -2 1 -3
|
Not a Costas array 2 1 4 3 -1 3 -1 2 2
|
2 -3 -1 -2 5 -4
-1 -4 -3 3 1
-2 -6 2 -1
-4 -1 -2
1 -5A Costas array can be conveniently represented as a 2D permutation matrix.
Example: 4 2 1 3 5 6By hand, JP Costas had his students do it for n=12 in the 80's
Instead of using an algorithm to generate all the n! permutations. We will use backtracking to eliminate branches of computations and speed things a little bit more.
The backtracking algorithm work as follows:
costas_list = []
while current >= start:
costas[current] += 1
while costas[current] in costas[:current] and costas[current] <= n:
costas[current]+=1
if costas[current] > n:
costas[current] = 0
current-=1
elif isCostas(costas[:current+1], n):
if current < n-1:
current+=1
else:
costas_list.append(costas[:])
def isCostas(array, n):
a_size = len(array)
for c in range(1, a_size):
hash = [0] * (2 * n)
for i in range(a_size - c):
dif = array[i+c] - array[i]
if hash[dif] == 1:
return 0
else:
hash[dif] = 1
return 1
We can start by computing the set of sub Costas of size less than N.
Divide set in equal parts among the processes and have them complete the search.
Have one process, the master, send one sub Costas to the other processes, the slaves. Once the slaves finish their computation, send back the results and wait for another sub Costas.
# The master computes the sub Costas and have the set in
# the List scostas_list
for i in range(1, num_procs):
sub_costas = scostas_list.pop(0)
comm.send(sub_costas, dest=i, tag=TAG_WORK)
while len(scostas_list) > 0:
sub_costas = scostas_list.pop(0)
costas_list += comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=stat)
comm.send(sub_costas, dest=stat.Get_source(), tag=TAG_WORK)
for i in range(1, num_procs):
costas_list += comm.recv(source=MPI.ANY_SOURCE, tag=MPI.ANY_TAG, status=stat)
comm.send(sub_costas, dest=stat.Get_source(), tag=TAG_END)
The Slave:
sub_costas = comm.recv(source=0, tag=MPI.ANY_TAG, status=stat)
while stat.Get_tag() == TAG_WORK:
costas_list = findCostas(sub_costas, n, sub_n, sub_n)
comm.send(costas_list, dest=0)
sub_costas = comm.recv(source=0, tag=MPI.ANY_TAG, status=stat)
R. Arce, J. Ortiz, "Enumeration of Costas Arrays in FPGAs and GPUs". International Conference on ReConFigurable Computing and FPGAs, Cancun, Mexico, 2011.
K. Drakakis, F. Iorio, S. Rickard, and J. Walsh, “Results of the enumeration of Costas arrays of order 29,” Advances in Mathematics of Communications, vol. 5, no. 3, pp. 547–553, 2011.
MPI4py, http://mpi4py.scipy.org/
Python, www.python.org