ソースを参照

Codigo fuente sonar3d

コミット
c06dc5a37b
共有7 個のファイルを変更した1029 個の追加0 個の削除を含む
  1. 368
    0
      Costas.py
  2. 2
    0
      Makefile
  3. 395
    0
      Sonar.py
  4. 8
    0
      issonar.py
  5. 97
    0
      sonar3d.cpp
  6. 48
    0
      sonar3d.py
  7. 111
    0
      sonar3dnxn.cpp

+ 368
- 0
Costas.py ファイルの表示

@@ -0,0 +1,368 @@
1
+
2
+class Costas:
3
+
4
+	def __init__(self):
5
+		pass
6
+
7
+
8
+	def BuildWelch(self, p, root):
9
+		costas = [0] * (p-1)
10
+		for i in range(p-1):
11
+			costas[i] = pow(root, i+1) % p 
12
+		return costas
13
+
14
+	def isCostas(self, array):
15
+		a_size = len(array)
16
+		for c in range(1, a_size):
17
+			hash = [0] * (2 * a_size)
18
+			for i in range(a_size - c):
19
+				dif = array[i+c] - array[i]
20
+				#print dif,
21
+				if hash[dif] == 1:
22
+					return 0
23
+				else:
24
+					hash[dif] = 1
25
+			#print
26
+		return 1
27
+
28
+        def CostasExtendedCrossCorrelation(self, costa1, costa2, n):
29
+                cross = 0
30
+                for h in range(n):
31
+                	hash = [0] * (n - 1)
32
+                        for i in range(n):
33
+                        	if costa1[(i+h) % n] == "*" or costa2[i] == "*":
34
+                                	 continue
35
+                             	dif =  (costa1[(i + h) % n] - costa2[i]) % (n- 1)
36
+                             	hash[dif]+=1
37
+                               	if cross < hash[dif]:
38
+                                	cross = hash[dif]
39
+                return cross
40
+
41
+
42
+	def isExtendedCostas(self, costas, n):
43
+		for h in range(n):
44
+			if h == 0:
45
+				continue
46
+			hash = [0] * (n-1)
47
+			for i in range(n):
48
+				if costas[(i + h) % n] == "*" or costas[i] == "*":
49
+					continue
50
+				dif = (costas[(i+h) % n] - costas[i]) % (n-1)
51
+				if hash[dif] == 1:
52
+					return 0
53
+				else:
54
+					hash[dif] = 1
55
+		return 1
56
+
57
+        def CostasColumnSymetries(self, a, p):
58
+                costaList = []
59
+                for i in range(2, p):
60
+                        costas = [0] * p
61
+                        for x in range(p):
62
+                       		costas[(x*i) % p] = a[x]
63
+                        costaList.append(costas)
64
+                return costaList
65
+
66
+
67
+
68
+        def is3DCostas(self, costas, n):                
69
+		for h1 in range(n):
70
+                        for h2 in range(n):
71
+                                if h1 == 0 and h2 == 0:
72
+                                        continue
73
+                                hash = [0] * ((n*n) - 1)
74
+                                for i in range(n):
75
+                                        for j in range(n):                                       
76
+                                                #if i == 0 and j == 0:
77
+                                                #        continue
78
+                                                #if (i+h1) % n == 0 and (j+h2) % n == 0:
79
+						# Fix for * anyware on the grid.
80
+						if costas[(i+h1) % n][(j+h2) % n] == "*" or costas[i][j] == "*":
81
+                                                        continue
82
+
83
+                                                dif =  (costas[((i + h1) % n)][((j+h2) % n)]
84
+ - costas[i][j]) % (pow(n,2) - 1)
85
+                                                #print dif,
86
+                                                if hash[dif] == 1:
87
+                                                        return 0
88
+                                                else:
89
+                                                        hash[dif] =1
90
+                                #print
91
+                return 1
92
+
93
+	def Costas3DCrossCorrelation(self, costa1, costa2, n):
94
+		cross = 0
95
+		for h1 in range(n):
96
+                        for h2 in range(n):
97
+                                #if h1 == 0 and h2 == 0:
98
+                                #        continue
99
+                                hash = [0] * ((n*n) - 1)
100
+                                for i in range(n):
101
+                                        for j in range(n):                                       
102
+                                                #if i == 0 and j == 0:
103
+                                                #        continue
104
+                                                #if (i+h1) % n == 0 and (j+h2) % n == 0:
105
+                                        	# Fix for * anyware on the grid.
106
+                                                if costa1[(i+h1) % n][(j+h2) % n] == "*" or costa2[i][j] == "*": 
107
+						       continue
108
+
109
+                                                dif =  (costa1[((i + h1) % n)][((j+h2) % n)]
110
+ - costa2[i][j]) % (pow(n,2) - 1)
111
+                                                #print dif,
112
+                                                hash[dif]+=1
113
+						if cross < hash[dif]:
114
+							cross = hash[dif]
115
+                                #print
116
+				#print hash
117
+                return cross
118
+
119
+		
120
+
121
+	def is3DCostas1D(self, costas, n):
122
+	        for h1 in range(n):
123
+       	        	for h2 in range(n):
124
+       	                	if h1 == 0 and h2 == 0:
125
+                                	continue
126
+                        	hash = [0] * ((n*n) - 1)
127
+                        	for i in range(n):
128
+                                	for j in range(n):                                        
129
+						if i == 0 and j == 0:
130
+                                                	continue
131
+                                        	if (i+h1) % n == 0 and (j+h2) % n == 0:
132
+                                                	continue
133
+
134
+                                        	dif =  (costas[ n *((i + h1) % n) + ((j+h2) % n)] - costas[n*i+j]) % (pow(n,2) - 1)
135
+						#print dif,
136
+                                        	if hash[dif] == 1:
137
+                                                	return 0
138
+                                        	else:
139
+                                                	hash[dif] =1
140
+				#print	
141
+        	return 1
142
+		
143
+	def Costas3DRowSymetries(self, a, p):
144
+		# Given a Welch 3dCostas return all its column symetries 
145
+		costaList = []
146
+		for i in range(2,p):
147
+        		costas2d = []
148
+                        for j in range(p):
149
+                                costas2d.append([0] * p)
150
+                        for x in range(p):
151
+                                for y in range(p):
152
+                                        if x == 0 and y == 0:
153
+                                                costas2d[x][y] = "*"
154
+                                        else:
155
+                                                costas2d[(x*i) % p][y] = a[x][y]
156
+
157
+        		costaList.append(costas2d)
158
+		return costaList
159
+	
160
+	def Costas3DRowShiftPermutation(self, a, p):
161
+		# Given a Welch 3dCostas return all its row power permutations
162
+                costaList = []
163
+                for i in range(1,p):
164
+                        costas2d = []
165
+                        costas2d.append(a[0][:])
166
+                        for j in range(1, p):
167
+                                costas2d.append(a[j][-(((i*j)%p)) :] + a[j][:-((i*j)%p)])
168
+                        costaList.append(costas2d)
169
+                return costaList
170
+
171
+	
172
+	def Costas3DColumnSymetries(self, a, p):
173
+		costaList = []
174
+		for i in range(2, p):
175
+			costas2d = []
176
+			for j in range(p):
177
+				costas2d.append([0] * p)
178
+			for y in range(p):
179
+				for x in range(p):
180
+					if x == 0 and y == 0:
181
+						costas2d[x][y] = "*"
182
+					else:
183
+						costas2d[x][(y*i) % p] = a[x][y]
184
+			costaList.append(costas2d)
185
+		return costaList	
186
+
187
+        def Costas3DColumnShiftPermutation(self, a, p):
188
+                costaList = []
189
+                for i in range(1, p):
190
+                        costas2d = []
191
+                        for j in range(p):
192
+                                costas2d.append([0] * p)
193
+                        for y in range(p):
194
+                                for x in range(p):
195
+                                        if x == 0 and y == 0:
196
+                                                costas2d[x][y] = "*"
197
+                                        else:
198
+                                                costas2d[(x+(y*i)) % p][y] = a[x][y]
199
+                        costaList.append(costas2d)
200
+                return costaList
201
+	
202
+	def CostasAdditionSymetries(self, a, p):
203
+		#Given a Welch 3dCostas return all its Addition symetries excluding a
204
+		costaList = []
205
+		for i in range(1, p):
206
+			costas2d = []
207
+			for j in range(p):
208
+				costas2d.append([0] * p)
209
+			for x in range(p):
210
+				for y in range(p):
211
+					if x == 0 and y == 0:
212
+						costas2d[x][y] = "*"
213
+					else:
214
+						costas2d[x][y] = (a[x][y] + i) % (pow(p,2)-1)
215
+			costaList.append(costas2d)
216
+
217
+		return costaList
218
+			
219
+	def CostasMultiplicationSymetries(self, a, p1, primes):
220
+		costaList = []
221
+		for p in primes:
222
+			costas2d = []
223
+                        for j in range(p1):
224
+                                costas2d.append([0] * p1)
225
+
226
+			for x in range(p1):
227
+				for y in range(p1):
228
+					if x == 0 and y == 0:
229
+						costas2d[0][0] = "*"
230
+					else:
231
+						costas2d[x][y] = (a[x][y] * p) % (pow(p1,2)-1)	
232
+			costaList.append(costas2d)
233
+		return costaList
234
+
235
+	def Costas3D90DegreeSymetry(self, a, p):
236
+		# Given a Welch 3DCostas return its 90Degree Symetry
237
+		costas = [] * p
238
+		for i in range(p):
239
+			costas.append([0] * p)
240
+		for i in range(p):
241
+			for j in range(p):
242
+				costas[i][j] = a[j][i]
243
+				
244
+		return costas
245
+
246
+	def Costas3DDihedralSymetry(self, a, p):
247
+		costas = [] * p
248
+                for i in range(p):
249
+                        costas.append([0] * p)
250
+		for i in range(p):
251
+			costas[i] = a[i][:]
252
+			costas[i].reverse()
253
+		return costas
254
+	
255
+	def Costas2Legendre(self, a, p):
256
+		for i in range(p):
257
+			for j in range(p):
258
+				if a[i][j] == "*":
259
+					continue
260
+				if(a[i][j] % 2 == 0):
261
+					a[i][j]=1
262
+				else:
263
+					a[i][j]=-1
264
+		
265
+	def GetLegendre(self, a, p):
266
+                # Given a Welch 3DCostas return its Legendre
267
+                costas = [] * p
268
+                for i in range(p):
269
+                        costas.append([0] * p)
270
+
271
+                for i in range(p):
272
+                        for j in range(p):
273
+                                if a[i][j] == "*":
274
+					costas[i][j] = "*"
275
+                                        continue
276
+
277
+                                if(a[i][j] % 2 == 0):
278
+                                        costas[i][j]=1
279
+                                else:
280
+                                        costas[i][j]=-1
281
+		return costas
282
+	
283
+	def IsCalabro(self, a, p):
284
+		# Check if Legendre array is Calabro
285
+		similar = (p-1)/2
286
+		counter = [0] * p	
287
+		for i in range(1, p-1):
288
+			for j in range(i+1, p):
289
+				if a[i] == a[j]:
290
+					if counter[i] == 0:
291
+						counter[i]+=2
292
+					else:
293
+						counter[i]+=1
294
+					if counter[j] == 0:
295
+						counter[j]+=2
296
+					else:
297
+						counter[j]+=1
298
+		if similar in counter:
299
+			return 1, counter
300
+		else:
301
+			return 0, counter
302
+
303
+	def LegendreCorrelation(self, legendre, p):
304
+		cor = 0
305
+		cor_pos = 0
306
+		cor_neg = 0
307
+		for h1 in range(p):
308
+			for h2 in range(p):
309
+				if h1 == 0 and h2 == 0:
310
+					continue
311
+				tmp_cor = 0
312
+				for i in range(p):
313
+					for j in range(p):
314
+						tmp_cor += legendre[(i + h1) % p][(j + h2) % p] * legendre[i][j]
315
+				
316
+				if tmp_cor < 0:
317
+					if tmp_cor < cor_neg:
318
+						cor_neg = tmp_cor					
319
+				else:
320
+					if tmp_cor > cor_pos:
321
+						cor_pos = tmp_cor
322
+				if abs(tmp_cor) > cor:
323
+					cor = abs(tmp_cor) 	
324
+		return cor, cor_neg, cor_pos
325
+				
326
+        def LegendreCrossCorrelation(self, legendre1, legendre2, p):
327
+                cor = 0
328
+                cor_pos = 0
329
+                cor_neg = 0
330
+                for h1 in range(p):
331
+                        for h2 in range(p):
332
+                                #if h1 == 0 and h2 == 0:
333
+                                #        continue
334
+                                tmp_cor = 0
335
+                                for i in range(p):
336
+                                        for j in range(p):
337
+                                                if legendre1[(i + h1) % p][(j + h2) % p] == "*" or legendre2[i][j] == "*":
338
+                                                        continue
339
+                                                tmp_cor += legendre1[(i + h1) % p][(j + h2) % p] * legendre2[i][j]
340
+
341
+                                if tmp_cor < 0:
342
+                                        if tmp_cor < cor_neg:
343
+                                                cor_neg = tmp_cor
344
+                                else:
345
+                                        if tmp_cor > cor_pos:
346
+                                                cor_pos = tmp_cor
347
+                                if abs(tmp_cor) > cor:
348
+                                        cor = abs(tmp_cor)
349
+                return cor, cor_neg, cor_pos
350
+
351
+
352
+	def LegendreCrossCorrelationCoincidences(self, legendre1, legendre2, p):
353
+                cor = 0
354
+                for h1 in range(p):
355
+                        for h2 in range(p):
356
+                                #if h1 == 0 and h2 == 0:
357
+                                #        continue
358
+                                tmp_cor = 0
359
+                                for i in range(p):
360
+                                        for j in range(p):
361
+                                                if legendre1[(i + h1) % p][(j + h2) % p] == legendre2[i][j]:
362
+							tmp_cor+=1 
363
+                                if tmp_cor > cor:
364
+                                        cor = tmp_cor
365
+                return cor
366
+		
367
+#c = Costas()
368
+#print c.isCostas([4,3,2,1])	

+ 2
- 0
Makefile ファイルの表示

@@ -0,0 +1,2 @@
1
+all:
2
+	g++ -o sonar3dnxn sonar3dnxn.cpp

+ 395
- 0
Sonar.py ファイルの表示

@@ -0,0 +1,395 @@
1
+
2
+class Sonar:
3
+
4
+	def __init__(self):
5
+		pass
6
+
7
+
8
+	def BuildWelch(self, p, root):
9
+		costas = [0] * (p-1)
10
+		for i in range(p-1):
11
+			costas[i] = pow(root, i+1) % p 
12
+		return costas
13
+
14
+	def isCostas(self, array):
15
+		a_size = len(array)
16
+		for c in range(1, a_size):
17
+			hash = [0] * (2 * a_size)
18
+			for i in range(a_size - c):
19
+				dif = array[i+c] - array[i]
20
+				#print dif,
21
+				if hash[dif] == 1:
22
+					return 0
23
+				else:
24
+					hash[dif] = 1
25
+			#print
26
+		return 1
27
+
28
+        def CostasExtendedCrossCorrelation(self, costa1, costa2, n):
29
+                cross = 0
30
+                for h in range(n):
31
+                	hash = [0] * (n - 1)
32
+                        for i in range(n):
33
+                        	if costa1[(i+h) % n] == "*" or costa2[i] == "*":
34
+                                	 continue
35
+                             	dif =  (costa1[(i + h) % n] - costa2[i]) % (n- 1)
36
+                             	hash[dif]+=1
37
+                               	if cross < hash[dif]:
38
+                                	cross = hash[dif]
39
+                return cross
40
+
41
+
42
+	def isExtendedCostas(self, costas, n):
43
+		for h in range(n):
44
+			if h == 0:
45
+				continue
46
+			hash = [0] * (n-1)
47
+			for i in range(n):
48
+				if costas[(i + h) % n] == "*" or costas[i] == "*":
49
+					continue
50
+				dif = (costas[(i+h) % n] - costas[i]) % (n-1)
51
+				if hash[dif] == 1:
52
+					return 0
53
+				else:
54
+					hash[dif] = 1
55
+		return 1
56
+
57
+        def CostasColumnSymetries(self, a, p):
58
+                costaList = []
59
+                for i in range(2, p):
60
+                        costas = [0] * p
61
+                        for x in range(p):
62
+                       		costas[(x*i) % p] = a[x]
63
+                        costaList.append(costas)
64
+                return costaList
65
+
66
+
67
+
68
+        def is3DCostas(self, costas, n):                
69
+		for h1 in range(n):
70
+                        for h2 in range(n):
71
+                                if h1 == 0 and h2 == 0:
72
+                                        continue
73
+                                hash = [0] * ((n*n) - 1)
74
+                                for i in range(n):
75
+                                        for j in range(n):                                       
76
+                                                #if i == 0 and j == 0:
77
+                                                #        continue
78
+                                                #if (i+h1) % n == 0 and (j+h2) % n == 0:
79
+						# Fix for * anyware on the grid.
80
+						if costas[(i+h1) % n][(j+h2) % n] == "*" or costas[i][j] == "*":
81
+                                                        continue
82
+
83
+                                                dif =  (costas[((i + h1) % n)][((j+h2) % n)]
84
+ - costas[i][j]) % (pow(n,2) - 1)
85
+                                                #print dif,
86
+                                                if hash[dif] == 1:
87
+                                                        return 0
88
+                                                else:
89
+                                                        hash[dif] =1
90
+                                #print
91
+                return 1
92
+
93
+	def Costas3DCrossCorrelation(self, costa1, costa2, n):
94
+		cross = 0
95
+		for h1 in range(n):
96
+                        for h2 in range(n):
97
+                                #if h1 == 0 and h2 == 0:
98
+                                #        continue
99
+                                hash = [0] * ((n*n) - 1)
100
+                                for i in range(n):
101
+                                        for j in range(n):                                       
102
+                                                #if i == 0 and j == 0:
103
+                                                #        continue
104
+                                                #if (i+h1) % n == 0 and (j+h2) % n == 0:
105
+                                        	# Fix for * anyware on the grid.
106
+                                                if costa1[(i+h1) % n][(j+h2) % n] == "*" or costa2[i][j] == "*": 
107
+						       continue
108
+
109
+                                                dif =  (costa1[((i + h1) % n)][((j+h2) % n)]
110
+ - costa2[i][j]) % (pow(n,2) - 1)
111
+                                                #print dif,
112
+                                                hash[dif]+=1
113
+						if cross < hash[dif]:
114
+							cross = hash[dif]
115
+                                #print
116
+				#print hash
117
+                return cross
118
+
119
+		
120
+
121
+	def is3DSonar1D(self, costas, p, n):
122
+	        for h1 in range(p):
123
+       	        	for h2 in range(p):
124
+       	                	if h1 == 0 and h2 == 0:
125
+                                	continue
126
+                        	hash = [0] * ((p*p))
127
+                        	for i in range(p):
128
+					if p*i > n-1:
129
+						break
130
+                                	for j in range(p):                                        
131
+						if i == 0 and j == 0:
132
+                                                	continue
133
+                                        	if (i+h1) % p == 0 and (j+h2) % p == 0:
134
+                                                	continue
135
+							
136
+						if p*i+j > n-1:
137
+							break
138
+
139
+						if  p *((i + h1) % p) + ((j+h2) % p) > n - 1:
140
+							continue
141
+
142
+                                        	dif =  (costas[ p *((i + h1) % p) + ((j+h2) % p)] - costas[p*i+j]) % (pow(p,2))
143
+                                        	if hash[dif] == 1:
144
+                                                	return 0
145
+                                        	else:
146
+                                                	hash[dif] =1
147
+				#print	
148
+        	return 1
149
+
150
+        def is3DSonar1DFull(self, costas, p):
151
+                for h1 in range(p):
152
+                        for h2 in range(p):
153
+                                if h1 == 0 and h2 == 0:
154
+                                        continue
155
+                                hash = [0] * (p*p)
156
+                                for i in range(p):
157
+                                        for j in range(p):
158
+                                                if i == 0 and j == 0:
159
+                                                        continue
160
+                                                if (i+h1) % p == 0 and (j+h2) % p == 0:
161
+                                                        continue
162
+                                                dif =  (costas[ p *((i + h1) % p) + ((j+h2) % p)] - costas[p*i+j]) % (pow(p,2))
163
+                                                #print dif,
164
+                                                if hash[dif] == 1:
165
+                                                        return 0
166
+                                                else:
167
+                                                        hash[dif] =1
168
+		return 1
169
+		
170
+	def Costas3DRowSymetries(self, a, p):
171
+		# Given a Welch 3dCostas return all its column symetries 
172
+		costaList = []
173
+		for i in range(2,p):
174
+        		costas2d = []
175
+                        for j in range(p):
176
+                                costas2d.append([0] * p)
177
+                        for x in range(p):
178
+                                for y in range(p):
179
+                                        if x == 0 and y == 0:
180
+                                                costas2d[x][y] = "*"
181
+                                        else:
182
+                                                costas2d[(x*i) % p][y] = a[x][y]
183
+
184
+        		costaList.append(costas2d)
185
+		return costaList
186
+	
187
+	def Costas3DRowShiftPermutation(self, a, p):
188
+		# Given a Welch 3dCostas return all its row power permutations
189
+                costaList = []
190
+                for i in range(1,p):
191
+                        costas2d = []
192
+                        costas2d.append(a[0][:])
193
+                        for j in range(1, p):
194
+                                costas2d.append(a[j][-(((i*j)%p)) :] + a[j][:-((i*j)%p)])
195
+                        costaList.append(costas2d)
196
+                return costaList
197
+
198
+	
199
+	def Costas3DColumnSymetries(self, a, p):
200
+		costaList = []
201
+		for i in range(2, p):
202
+			costas2d = []
203
+			for j in range(p):
204
+				costas2d.append([0] * p)
205
+			for y in range(p):
206
+				for x in range(p):
207
+					if x == 0 and y == 0:
208
+						costas2d[x][y] = "*"
209
+					else:
210
+						costas2d[x][(y*i) % p] = a[x][y]
211
+			costaList.append(costas2d)
212
+		return costaList	
213
+
214
+        def Costas3DColumnShiftPermutation(self, a, p):
215
+                costaList = []
216
+                for i in range(1, p):
217
+                        costas2d = []
218
+                        for j in range(p):
219
+                                costas2d.append([0] * p)
220
+                        for y in range(p):
221
+                                for x in range(p):
222
+                                        if x == 0 and y == 0:
223
+                                                costas2d[x][y] = "*"
224
+                                        else:
225
+                                                costas2d[(x+(y*i)) % p][y] = a[x][y]
226
+                        costaList.append(costas2d)
227
+                return costaList
228
+	
229
+	def CostasAdditionSymetries(self, a, p):
230
+		#Given a Welch 3dCostas return all its Addition symetries excluding a
231
+		costaList = []
232
+		for i in range(1, p):
233
+			costas2d = []
234
+			for j in range(p):
235
+				costas2d.append([0] * p)
236
+			for x in range(p):
237
+				for y in range(p):
238
+					if x == 0 and y == 0:
239
+						costas2d[x][y] = "*"
240
+					else:
241
+						costas2d[x][y] = (a[x][y] + i) % (pow(p,2)-1)
242
+			costaList.append(costas2d)
243
+
244
+		return costaList
245
+			
246
+	def CostasMultiplicationSymetries(self, a, p1, primes):
247
+		costaList = []
248
+		for p in primes:
249
+			costas2d = []
250
+                        for j in range(p1):
251
+                                costas2d.append([0] * p1)
252
+
253
+			for x in range(p1):
254
+				for y in range(p1):
255
+					if x == 0 and y == 0:
256
+						costas2d[0][0] = "*"
257
+					else:
258
+						costas2d[x][y] = (a[x][y] * p) % (pow(p1,2)-1)	
259
+			costaList.append(costas2d)
260
+		return costaList
261
+
262
+	def Costas3D90DegreeSymetry(self, a, p):
263
+		# Given a Welch 3DCostas return its 90Degree Symetry
264
+		costas = [] * p
265
+		for i in range(p):
266
+			costas.append([0] * p)
267
+		for i in range(p):
268
+			for j in range(p):
269
+				costas[i][j] = a[j][i]
270
+				
271
+		return costas
272
+
273
+	def Costas3DDihedralSymetry(self, a, p):
274
+		costas = [] * p
275
+                for i in range(p):
276
+                        costas.append([0] * p)
277
+		for i in range(p):
278
+			costas[i] = a[i][:]
279
+			costas[i].reverse()
280
+		return costas
281
+	
282
+	def Costas2Legendre(self, a, p):
283
+		for i in range(p):
284
+			for j in range(p):
285
+				if a[i][j] == "*":
286
+					continue
287
+				if(a[i][j] % 2 == 0):
288
+					a[i][j]=1
289
+				else:
290
+					a[i][j]=-1
291
+		
292
+	def GetLegendre(self, a, p):
293
+                # Given a Welch 3DCostas return its Legendre
294
+                costas = [] * p
295
+                for i in range(p):
296
+                        costas.append([0] * p)
297
+
298
+                for i in range(p):
299
+                        for j in range(p):
300
+                                if a[i][j] == "*":
301
+					costas[i][j] = "*"
302
+                                        continue
303
+
304
+                                if(a[i][j] % 2 == 0):
305
+                                        costas[i][j]=1
306
+                                else:
307
+                                        costas[i][j]=-1
308
+		return costas
309
+	
310
+	def IsCalabro(self, a, p):
311
+		# Check if Legendre array is Calabro
312
+		similar = (p-1)/2
313
+		counter = [0] * p	
314
+		for i in range(1, p-1):
315
+			for j in range(i+1, p):
316
+				if a[i] == a[j]:
317
+					if counter[i] == 0:
318
+						counter[i]+=2
319
+					else:
320
+						counter[i]+=1
321
+					if counter[j] == 0:
322
+						counter[j]+=2
323
+					else:
324
+						counter[j]+=1
325
+		if similar in counter:
326
+			return 1, counter
327
+		else:
328
+			return 0, counter
329
+
330
+	def LegendreCorrelation(self, legendre, p):
331
+		cor = 0
332
+		cor_pos = 0
333
+		cor_neg = 0
334
+		for h1 in range(p):
335
+			for h2 in range(p):
336
+				if h1 == 0 and h2 == 0:
337
+					continue
338
+				tmp_cor = 0
339
+				for i in range(p):
340
+					for j in range(p):
341
+						tmp_cor += legendre[(i + h1) % p][(j + h2) % p] * legendre[i][j]
342
+				
343
+				if tmp_cor < 0:
344
+					if tmp_cor < cor_neg:
345
+						cor_neg = tmp_cor					
346
+				else:
347
+					if tmp_cor > cor_pos:
348
+						cor_pos = tmp_cor
349
+				if abs(tmp_cor) > cor:
350
+					cor = abs(tmp_cor) 	
351
+		return cor, cor_neg, cor_pos
352
+				
353
+        def LegendreCrossCorrelation(self, legendre1, legendre2, p):
354
+                cor = 0
355
+                cor_pos = 0
356
+                cor_neg = 0
357
+                for h1 in range(p):
358
+                        for h2 in range(p):
359
+                                #if h1 == 0 and h2 == 0:
360
+                                #        continue
361
+                                tmp_cor = 0
362
+                                for i in range(p):
363
+                                        for j in range(p):
364
+                                                if legendre1[(i + h1) % p][(j + h2) % p] == "*" or legendre2[i][j] == "*":
365
+                                                        continue
366
+                                                tmp_cor += legendre1[(i + h1) % p][(j + h2) % p] * legendre2[i][j]
367
+
368
+                                if tmp_cor < 0:
369
+                                        if tmp_cor < cor_neg:
370
+                                                cor_neg = tmp_cor
371
+                                else:
372
+                                        if tmp_cor > cor_pos:
373
+                                                cor_pos = tmp_cor
374
+                                if abs(tmp_cor) > cor:
375
+                                        cor = abs(tmp_cor)
376
+                return cor, cor_neg, cor_pos
377
+
378
+
379
+	def LegendreCrossCorrelationCoincidences(self, legendre1, legendre2, p):
380
+                cor = 0
381
+                for h1 in range(p):
382
+                        for h2 in range(p):
383
+                                #if h1 == 0 and h2 == 0:
384
+                                #        continue
385
+                                tmp_cor = 0
386
+                                for i in range(p):
387
+                                        for j in range(p):
388
+                                                if legendre1[(i + h1) % p][(j + h2) % p] == legendre2[i][j]:
389
+							tmp_cor+=1 
390
+                                if tmp_cor > cor:
391
+                                        cor = tmp_cor
392
+                return cor
393
+		
394
+#c = Costas()
395
+#print c.isCostas([4,3,2,1])	

+ 8
- 0
issonar.py ファイルの表示

@@ -0,0 +1,8 @@
1
+from Sonar import *
2
+
3
+p = 3
4
+sonar = ["*", 1, 1, 1, 2, 5, 4, 8, 5]
5
+
6
+s = Sonar()
7
+if s.is3DSonar1DFull(sonar, p):
8
+	print "Sonar"

+ 97
- 0
sonar3d.cpp ファイルの表示

@@ -0,0 +1,97 @@
1
+#include <iostream>
2
+#include <stdlib.h>
3
+
4
+using namespace std ;
5
+
6
+void printArray(int *array, int size){
7
+	for(int i = 0; i < size; i++){
8
+		cout << array[i] << " " ;
9
+	}
10
+
11
+}
12
+
13
+bool is3DSonar1D(int *array, int *hash, int iter_id, int p, int n){
14
+	int *hash = NULL ;
15
+	int p2 = p*p ;
16
+	int dif ;
17
+	for (int h1 = 0; h1 < p; h1++){
18
+		for(int h2 = 0; h2 < p; h2++){
19
+			if(h1 == 0 && h2 == 0)
20
+				continue ;
21
+			//printArray(hash, p2) ;cout << endl ;
22
+			for(int i = 0; i < p; i++){
23
+				if(p*i > n-1) 
24
+					break ;
25
+				for(int j = 0; j < p; j++){
26
+					if(i == 0 && j == 0)
27
+						continue ;
28
+					if((i+h1) % p == 0 && (j+h2) % p == 0)
29
+						continue ;
30
+					if(p*i+j > n-1)
31
+						break;
32
+					if( p * ((i + h1) % p) + ((j+h2) % p) > n - 1)
33
+						continue ;
34
+					dif = (array[ p *((i + h1) % p) + ((j+h2) % p)] - array[p*i+j]);
35
+					//cout <<i<< j<< h1 << h2 << "dif" <<dif<<endl ;
36
+					if(dif < 0)
37
+						dif = p2 + dif;
38
+					else
39
+						dif = dif % p2;
40
+					if (hash[dif] ==1){
41
+					//	printArray(hash, p2) ;cout << endl ;
42
+						return false ;
43
+					}
44
+					else	
45
+						hash[dif]=1 ;
46
+				}
47
+			}
48
+		}
49
+	}
50
+	return true ;
51
+}
52
+
53
+int main(int argc, char **argv){
54
+
55
+	int start, end, p, n ;
56
+	p = 3 ;
57
+	int counter = 0 ;
58
+	bool sonar = false ;
59
+	start = 3;
60
+	end = 3;
61
+	n = p*p ;
62
+	int *array = new int[n];
63
+	int *hash = (int *) calloc(p2, sizeof(int)) ;
64
+
65
+	for(int i = 0; i < n; i++)
66
+		array[i] = -1 ;
67
+	
68
+	array[1] = 0;
69
+	array[2] = atoi(argv[1]) ;	
70
+	while(end >= start){
71
+		counter++ ;	
72
+		sonar = false ;
73
+		if(array[end] + 1 > n-1){
74
+			array[end] = -1;
75
+			end-- ;
76
+			continue ;
77
+		}
78
+		array[end]++;
79
+		if(counter % 2000 == 0){ 
80
+			cout << "Check Point: " ; printArray(array, end+1);  cout << endl;
81
+			counter = 0;
82
+		}
83
+		if (is3DSonar1D(array, p, end+1)){
84
+			//cout <<"Costas";printArray(array, end+1) ; cout <<endl ;
85
+			sonar = true ;
86
+			if(end+1 == n){
87
+				cout <<"Sonar:";printArray(array, end+1);cout << endl;
88
+			}
89
+		}	
90
+		if(sonar && end < (n-1)){
91
+			end++ ;
92
+		}
93
+
94
+	}
95
+
96
+return 0 ;
97
+}

+ 48
- 0
sonar3d.py ファイルの表示

@@ -0,0 +1,48 @@
1
+import bisect
2
+from Sonar import *
3
+
4
+p = 3
5
+
6
+start = 2
7
+end = 2
8
+array = [-1] * (p*p) 
9
+array[1] = 0
10
+n = (p*p)
11
+
12
+c = Sonar()
13
+counter = 0
14
+
15
+while 1:
16
+        costas = 0
17
+
18
+        if end < start:
19
+                break
20
+        if array[end] + 1> n-1: #or len(next) == 0 or bisect.bisect(next, array[end]) >= len(next):
21
+                #bisect.insort(next, array[end])
22
+                array[end] = -1
23
+                end -=1
24
+                continue
25
+
26
+        #if not array[end] == 0:
27
+                #tmp = array[end]
28
+        #        array[end] += 1 #next[bisect.bisect_right(next, tmp)]
29
+                #next.remove(array[end])
30
+                #bisect.insort(next, tmp)
31
+        #else:
32
+
33
+        array[end] += 1
34
+	counter+= 1 
35
+	#print "Check Point:", array[:end+1]
36
+        if c.is3DSonar1D(array[:end+1], p, end+1):
37
+        	costas = 1
38
+		if end+1 == n: 
39
+        		print array[:end+1]
40
+
41
+
42
+        if costas and end < (n-1):
43
+                end += 1
44
+        elif costas and end == (n-1):
45
+                pass
46
+        else:
47
+                pass
48
+

+ 111
- 0
sonar3dnxn.cpp ファイルの表示

@@ -0,0 +1,111 @@
1
+#include <iostream>
2
+#include <stdlib.h>
3
+
4
+using namespace std ;
5
+
6
+void printArray(int *array, int size){
7
+	for(int i = 0; i < size; i++){
8
+		cout << array[i] << " " ;
9
+	}
10
+
11
+}
12
+
13
+void ZeroArray(int *array, int size){
14
+	for (int i = 0; i < size ; i++)
15
+		array[i] = 0 ;
16
+}
17
+
18
+bool is3DSonar1D(int *array, int *hash, int n1, int n2, int n){
19
+	int p2 = n1*n2 ;
20
+	int dif ;
21
+	int iter = 0;
22
+	ZeroArray(hash, p2) ;
23
+	for (int h1 = 0; h1 < n1; h1++){
24
+		for(int h2 = 0; h2 < n2; h2++){
25
+			if(h1 == 0 && h2 == 0)
26
+				continue ;
27
+			iter++ ;
28
+			//ZeroArray(hash,p2) ;
29
+		 	//cout <<"after 0 " ;printArray(hash, p2) ; cout <<endl;
30
+			for(int i = 0; i < n1; i++){
31
+				if(n2*i > n-1) 
32
+					break ;
33
+				for(int j = 0; j < n2; j++){
34
+					if(i == 0 && j == 0)
35
+						continue ;
36
+					if((i+h1) % n1 == 0 && (j+h2) % n2 == 0)
37
+						continue ;
38
+					if(n2*i+j > n-1)
39
+						break;
40
+					if( n2 * ((i + h1) % n1) + ((j+h2) % n2) > n - 1)
41
+						continue ;
42
+					dif = (array[ n2 *((i + h1) % n1) + ((j+h2) % n2)] - array[n2*i+j]);
43
+					//cout << h1 << " " << h2 << " n " << n <<endl ;
44
+					//cout <<i+h1<< j+h2 << i << j << array[ n2 *((i + h1) % n1) + ((j+h2) % n2)] << array[n2*i+j] << "dif" <<dif<<endl ;
45
+					//cout <<"Pos " << n2 *((i + h1) % n1) + ((j+h2) % n2) << n2*i+j << endl ;
46
+					if(dif < 0)
47
+						dif = p2 + dif;
48
+					else
49
+						dif = dif % p2;
50
+					if (hash[dif] == iter){
51
+						//cout << "Eq " <<hash[dif] << iter <<endl ;
52
+						//printArray(hash, p2) ;cout << endl ;
53
+						return false ;
54
+					}
55
+					else{	
56
+					//	cout << "FALSE" <<endl ;
57
+						hash[dif]=iter ;
58
+					}
59
+				}
60
+			}
61
+		}
62
+	}
63
+	return true ;
64
+}
65
+
66
+int main(int argc, char **argv){
67
+
68
+	int start, end, n1, n2, n ;
69
+	int counter = 0 ;
70
+	bool sonar = false ;
71
+	start = 3;
72
+	end = 3;
73
+	n1 = atoi(argv[1]) ;
74
+	n2 = atoi(argv[2]) ;
75
+	n = n1*n2 ;
76
+	int *array = new int[n];
77
+	int *hash = (int *) calloc(n, sizeof(int)) ;
78
+
79
+	for(int i = 0; i < n; i++)
80
+		array[i] = -1 ;
81
+	
82
+	array[1] = 0;
83
+	array[2] = atoi(argv[3]) ;	
84
+	while(end >= start){
85
+		counter++ ;	
86
+		sonar = false ;
87
+		if(array[end] + 1 > n-1){
88
+			array[end] = -1;
89
+			end-- ;
90
+			continue ;
91
+		}
92
+		array[end]++;
93
+		if(counter % 10000 == 0){ 
94
+			cout << "Check Point: " ; printArray(array, end+1);  cout << endl;
95
+			counter = 0;
96
+		}
97
+		if (is3DSonar1D(array, hash, n1, n2, end+1)){
98
+			//cout <<"Costas";printArray(array, end+1) ; cout <<endl ;
99
+			sonar = true ;
100
+			if(end+1 == n){
101
+				cout <<"Sonar:";printArray(array, end+1);cout << endl;
102
+			}
103
+		}	
104
+		if(sonar && end < (n-1)){
105
+			end++ ;
106
+		}
107
+
108
+	}
109
+
110
+return 0 ;
111
+}