1 /*
2 # This file is part of the Astrometry.net suite.
3 # Licensed under a 3-clause BSD style license - see LICENSE
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <assert.h>
9
10 #include "solver.h"
11 #include "index.h"
12 #include "pquad.h"
13 #include "permutedsort.h"
14 #include "quad-utils.h"
15 #include "log.h"
16
compare_n(const void * v1,const void * v2,int N)17 static int compare_n(const void* v1, const void* v2, int N) {
18 const int* u1 = v1;
19 const int* u2 = v2;
20 int i;
21 for (i=0; i<N; i++) {
22 if (u1[i] < u2[i]) return -1;
23 if (u1[i] > u2[i]) return 1;
24 }
25 return 0;
26 }
27
compare_tri(const void * v1,const void * v2)28 static int compare_tri(const void* v1, const void* v2) {
29 return compare_n(v1, v2, 3);
30 }
compare_quad(const void * v1,const void * v2)31 static int compare_quad(const void* v1, const void* v2) {
32 return compare_n(v1, v2, 4);
33 }
compare_quint(const void * v1,const void * v2)34 static int compare_quint(const void* v1, const void* v2) {
35 return compare_n(v1, v2, 5);
36 }
37
38
39 bl* quadlist;
40 int ninv;
41
test_try_permutations(int * stars,double * code,int dimquad,solver_t * s)42 void test_try_permutations(int* stars, double* code, int dimquad, solver_t* s) {
43 int i;
44 fflush(NULL);
45 /*
46 printf("test_try_permutations: [");
47 for (i=0; i<dimquad; i++) {
48 printf("%s%i", (i?" ":""), stars[i]);
49 }
50 printf("]\n");
51 */
52 printf("{");
53 for (i=0; i<dimquad; i++) {
54 printf("%s%i", (i?",":""), stars[i]);
55 }
56 printf("}, ");
57 fflush(NULL);
58 bl_append(quadlist, stars);
59
60 if (quad_obeys_invariants(NULL, code, dimquad, 0))
61 ninv++;
62 }
63
field1()64 static starxy_t* field1() {
65 starxy_t* starxy;
66 double field[14];
67 int i=0, N;
68 // star0 A: (0,0)
69 field[i++] = 0.0;
70 field[i++] = 0.0;
71 // star1 B: (2,2)
72 field[i++] = 2.0;
73 field[i++] = 2.0;
74 // star2
75 field[i++] = -1.0;
76 field[i++] = 3.0;
77 // star3
78 field[i++] = 0.5;
79 field[i++] = 1.5;
80 // star4
81 field[i++] = 1.0;
82 field[i++] = 1.0;
83 // star5
84 field[i++] = 1.5;
85 field[i++] = 0.5;
86 // star6
87 field[i++] = 3.0;
88 field[i++] = -1.0;
89
90 N = i/2;
91 starxy = starxy_new(N, FALSE, FALSE);
92 for (i=0; i<N; i++) {
93 starxy_setx(starxy, i, field[i*2+0]);
94 starxy_sety(starxy, i, field[i*2+1]);
95 }
96 return starxy;
97 }
98
testit(int * wanted,int Nwanted,int dimquads,int (* compar)(const void *,const void *),anbool cxdx)99 void testit(int* wanted, int Nwanted, int dimquads, int (*compar)(const void *, const void *),
100 anbool cxdx) {
101 int i;
102 solver_t* solver;
103 index_t index;
104 starxy_t* starxy;
105
106 starxy = field1();
107 quadlist = bl_new(16, dimquads*sizeof(int));
108 ninv = 0;
109 solver = solver_new();
110 memset(&index, 0, sizeof(index_t));
111 index.index_scale_lower = 1;
112 index.index_scale_upper = 10;
113 index.dimquads = dimquads;
114
115 index.cx_less_than_dx = index.meanx_less_than_half = cxdx;
116
117 solver->funits_lower = 0.1;
118 solver->funits_upper = 10;
119
120 solver_add_index(solver, &index);
121 solver_set_field(solver, starxy);
122 solver_preprocess_field(solver);
123
124 printf("Found:\n");
125 solver_run(solver);
126 printf("\n");
127 fflush(NULL);
128
129 solver_free_field(solver);
130 solver_free(solver);
131
132 //
133 bl_sort(quadlist, compar);
134
135 qsort(wanted, Nwanted, dimquads*sizeof(int), compar);
136 printf("\n\n");
137 printf("Wanted:\n");
138 for (i=0; i<Nwanted; i++) {
139 int j;
140 printf("{");
141 for (j=0; j<dimquads; j++)
142 printf("%s%i", (j?",":""), wanted[i*dimquads+j]);
143 printf("}, ");
144 }
145 printf("\n");
146 printf("N found: %i; N wanted: %i\n", bl_size(quadlist), Nwanted);
147 printf("N obeying invariants: %i\n", ninv);
148 assert(bl_size(quadlist) == Nwanted);
149 for (i=0; i<bl_size(quadlist); i++) {
150 //int* i1 = bl_access(quadlist, i);
151 //int* i2 = wanted[i];
152 //printf("[%i, %i, %i] vs [%i, %i, %i]\n", i1[0],i1[1],i1[2], i2[0],i2[1],i2[2]);
153 assert(compar(bl_access(quadlist, i), wanted+i*dimquads) == 0);
154 }
155 bl_free(quadlist);
156 }
157
158
159
160 char* OPTIONS = "v";
161
main(int argc,char ** args)162 int main(int argc, char** args) {
163 int argchar;
164 int* flatwanted;
165 int Nwanted;
166 int itemsize;
167 int i;
168
169 while ((argchar = getopt(argc, args, OPTIONS)) != -1)
170 switch (argchar) {
171 case 'v':
172 log_init(LOG_ALL+1);
173 break;
174 }
175
176 // NOTE, contain duplicates because of parity (we're trying both)
177 int wanted3[][3] = {
178 {0,1,3}, {1,0,3}, {0,1,3}, {1,0,3}, {0,2,3}, {2,0,3}, {0,2,3}, {2,0,3}, {1,2,3}, {2,1,3}, {1,2,3}, {2,1,3}, {2,4,3}, {4,2,3}, {2,4,3}, {4,2,3}, {0,1,4}, {1,0,4}, {0,1,4}, {1,0,4}, {0,2,4}, {2,0,4}, {0,2,4}, {2,0,4}, {0,3,4}, {3,0,4}, {0,3,4}, {3,0,4}, {1,2,4}, {2,1,4}, {1,2,4}, {2,1,4}, {1,3,4}, {3,1,4}, {1,3,4}, {3,1,4}, {0,5,4}, {5,0,4}, {0,5,4}, {5,0,4}, {1,5,4}, {5,1,4}, {1,5,4}, {5,1,4}, {2,5,0}, {5,2,0}, {2,5,0}, {5,2,0}, {2,5,1}, {5,2,1}, {2,5,1}, {5,2,1}, {2,5,3}, {5,2,3}, {2,5,3}, {5,2,3}, {2,5,4}, {5,2,4}, {2,5,4}, {5,2,4}, {3,5,4}, {5,3,4}, {3,5,4}, {5,3,4}, {0,1,5}, {1,0,5}, {0,1,5}, {1,0,5}, {0,6,4}, {6,0,4}, {0,6,4}, {6,0,4}, {0,6,5}, {6,0,5}, {0,6,5}, {6,0,5}, {1,6,4}, {6,1,4}, {1,6,4}, {6,1,4}, {1,6,5}, {6,1,5}, {1,6,5}, {6,1,5}, {2,6,0}, {6,2,0}, {2,6,0}, {6,2,0}, {2,6,1}, {6,2,1}, {2,6,1}, {6,2,1}, {2,6,3}, {6,2,3}, {2,6,3}, {6,2,3}, {2,6,4}, {6,2,4}, {2,6,4}, {6,2,4}, {2,6,5}, {6,2,5}, {2,6,5}, {6,2,5}, {3,6,0}, {6,3,0}, {3,6,0}, {6,3,0}, {3,6,1}, {6,3,1}, {3,6,1}, {6,3,1}, {3,6,4}, {6,3,4}, {3,6,4}, {6,3,4}, {3,6,5}, {6,3,5}, {3,6,5}, {6,3,5}, {4,6,5}, {6,4,5}, {4,6,5}, {6,4,5},
179 };
180 int wanted4[][4] = {
181 {0, 1, 4, 3}, {0, 1, 3, 4}, {1, 0, 4, 3}, {1, 0, 3, 4}, {0, 1, 4, 3}, {0, 1, 3, 4}, {1, 0, 4, 3}, {1, 0, 3, 4}, {0, 2, 4, 3}, {0, 2, 3, 4}, {2, 0, 4, 3}, {2, 0, 3, 4}, {0, 2, 4, 3}, {0, 2, 3, 4}, {2, 0, 4, 3}, {2, 0, 3, 4}, {1, 2, 4, 3}, {1, 2, 3, 4}, {2, 1, 4, 3}, {2, 1, 3, 4}, {1, 2, 4, 3}, {1, 2, 3, 4}, {2, 1, 4, 3}, {2, 1, 3, 4}, {2, 5, 0, 1}, {2, 5, 1, 0}, {5, 2, 0, 1}, {5, 2, 1, 0}, {2, 5, 0, 1}, {2, 5, 1, 0}, {5, 2, 0, 1}, {5, 2, 1, 0}, {2, 5, 0, 3}, {2, 5, 3, 0}, {5, 2, 0, 3}, {5, 2, 3, 0}, {2, 5, 0, 3}, {2, 5, 3, 0}, {5, 2, 0, 3}, {5, 2, 3, 0}, {2, 5, 0, 4}, {2, 5, 4, 0}, {5, 2, 0, 4}, {5, 2, 4, 0}, {2, 5, 0, 4}, {2, 5, 4, 0}, {5, 2, 0, 4}, {5, 2, 4, 0}, {2, 5, 1, 3}, {2, 5, 3, 1}, {5, 2, 1, 3}, {5, 2, 3, 1}, {2, 5, 1, 3},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0}, {6,3,0,1,5}, {6,3,0,5,1}, {6,3,1,0,5}, {6,3,1,5,0}, {6,3,5,0,1}, {6,3,5,1,0}, {3,6,0,4,5}, {3,6,0,5,4}, {3,6,4,0,5}, {3,6,4,5,0}, {3,6,5,0,4}, {3,6,5,4,0}, {6,3,0,4,5}, {6,3,0,5,4}, {6,3,4,0,5}, {6,3,4,5,0}, {6,3,5,0,4}, {6,3,5,4,0}, {3,6,0,4,5}, {3,6,0,5,4}, {3,6,4,0,5}, {3,6,4,5,0}, {3,6,5,0,4}, {3,6,5,4,0}, {6,3,0,4,5}, {6,3,0,5,4}, {6,3,4,0,5}, {6,3,4,5,0}, {6,3,5,0,4}, {6,3,5,4,0}, {3,6,1,4,5}, {3,6,1,5,4}, {3,6,4,1,5}, {3,6,4,5,1}, {3,6,5,1,4}, {3,6,5,4,1}, {6,3,1,4,5}, {6,3,1,5,4}, {6,3,4,1,5}, {6,3,4,5,1}, {6,3,5,1,4}, {6,3,5,4,1}, {3,6,1,4,5}, {3,6,1,5,4}, {3,6,4,1,5}, {3,6,4,5,1}, {3,6,5,1,4}, {3,6,5,4,1}, {6,3,1,4,5}, {6,3,1,5,4}, {6,3,4,1,5}, {6,3,4,5,1}, {6,3,5,1,4}, {6,3,5,4,1}
185 };
186
187 itemsize = 4*sizeof(int);
188 Nwanted = sizeof(wanted4) / itemsize;
189 flatwanted = calloc(Nwanted, itemsize);
190 for (i=0; i<Nwanted; i++) {
191 memcpy(flatwanted+i*4, wanted4[i], itemsize);
192 //qsort(flatwanted+i*4, 2, sizeof(int), compare_ints_asc);
193 //qsort(sorted+2, dimquad-2, sizeof(int), compare_ints_asc);
194 }
195 testit(flatwanted, Nwanted, 4, compare_quad, FALSE);
196 free(flatwanted);
197
198 itemsize = 5*sizeof(int);
199 Nwanted = sizeof(wanted5) / itemsize;
200 flatwanted = calloc(Nwanted, itemsize);
201 for (i=0; i<Nwanted; i++)
202 memcpy(flatwanted+i*5, wanted5[i], itemsize);
203 testit(flatwanted, Nwanted, 5, compare_quint, FALSE);
204 free(flatwanted);
205
206 itemsize = 3*sizeof(int);
207 Nwanted = sizeof(wanted3) / itemsize;
208 flatwanted = calloc(Nwanted, itemsize);
209 for (i=0; i<Nwanted; i++)
210 memcpy(flatwanted+i*3, wanted3[i], itemsize);
211 testit(flatwanted, Nwanted, 3, compare_tri, FALSE);
212 free(flatwanted);
213
214 int wanted3b[][3] = {
215 {0,1,3}, {1,0,3}, {2,0,3}, {0,2,3}, {1,2,3}, {2,1,3}, {4,2,3}, {4,2,3}, {0,1,4}, {1,0,4}, {0,1,4}, {1,0,4}, {2,0,4}, {0,2,4}, {3,0,4}, {0,3,4}, {1,2,4}, {2,1,4}, {1,3,4}, {3,1,4}, {0,5,4}, {5,0,4}, {5,1,4}, {1,5,4}, {5,2,0}, {2,5,0}, {2,5,1}, {5,2,1}, {5,2,3}, {5,2,3}, {5,2,4}, {5,2,4}, {3,5,4}, {5,3,4}, {3,5,4}, {5,3,4}, {1,0,5}, {0,1,5}, {0,6,4}, {6,0,4}, {0,6,5}, {6,0,5}, {6,1,4}, {1,6,4}, {6,1,5}, {1,6,5}, {6,2,0}, {2,6,0}, {2,6,1}, {6,2,1}, {2,6,3}, {2,6,3}, {2,6,4}, {6,2,4}, {2,6,4}, {6,2,4}, {6,2,5}, {6,2,5}, {6,3,0}, {3,6,0}, {3,6,1}, {6,3,1}, {3,6,4}, {3,6,4}, {3,6,5}, {3,6,5}, {4,6,5}, {4,6,5}
216 };
217 int wanted5b[][5] = {
218 {5,2,0,3,1}, {5,2,1,3,0}, {5,2,0,4,1}, {5,2,1,4,0}, {5,2,0,4,3}, {5,2,4,3,0}, {5,2,4,3,1}, {5,2,1,4,3}, {0,1,3,4,5}, {1,0,5,4,3}, {0,1,5,4,3}, {1,0,3,4,5}, {2,6,1,3,0}, {2,6,0,3,1}, {2,6,1,4,0}, {6,2,0,4,1}, {2,6,0,4,1}, {6,2,1,4,0}, {6,2,0,5,1}, {6,2,1,5,0}, {6,2,0,4,3}, {2,6,0,3,4}, {6,2,0,5,3}, {2,6,0,3,5}, {6,2,0,5,4}, {2,6,0,4,5}, {2,6,1,3,4}, {6,2,1,4,3}, {2,6,1,3,5}, {6,2,1,5,3}, {2,6,1,4,5}, {6,2,1,5,4}, {2,6,3,4,5}, {6,2,5,4,3}, {2,6,3,4,5}, {6,2,5,4,3}, {3,6,1,4,0}, {3,6,0,4,1}, {3,6,1,5,0}, {3,6,0,5,1}, {3,6,4,5,0}, {3,6,0,4,5}, {3,6,1,4,5}, {3,6,4,5,1},
219 };
220 int wanted4b[][4] = {
221 {0,1,3,4}, {1,0,3,4}, {2,0,3,4}, {0,2,4,3}, {1,2,4,3}, {2,1,3,4}, {5,2,0,1}, {5,2,1,0}, {5,2,0,3}, {2,5,0,3}, {5,2,3,0}, {5,2,0,4}, {5,2,4,0}, {2,5,1,3}, {5,2,3,1}, {5,2,1,3}, {5,2,4,1}, {5,2,1,4}, {5,2,4,3}, {5,2,4,3}, {0,1,3,5}, {1,0,5,3}, {0,1,5,3}, {1,0,3,5}, {1,0,5,4}, {0,1,5,4}, {0,6,4,5}, {6,0,5,4}, {6,1,5,4}, {1,6,4,5}, {2,6,1,0}, {6,2,0,1}, {2,6,0,1}, {6,2,1,0}, {6,2,0,3}, {2,6,0,3}, {6,2,0,4}, {2,6,0,4}, {6,2,0,5}, {2,6,0,5}, {2,6,1,3}, {6,2,1,3}, {2,6,1,4}, {6,2,1,4}, {2,6,1,5}, {6,2,1,5}, {2,6,3,4}, {2,6,3,4}, {2,6,3,5}, {6,2,5,3}, {2,6,3,5}, {6,2,5,3}, {6,2,5,4}, {6,2,5,4}, {3,6,1,0}, {3,6,0,1}, {3,6,4,0}, {3,6,0,4}, {3,6,5,0}, {6,3,0,5}, {3,6,0,5}, {3,6,1,4}, {3,6,4,1}, {3,6,1,5}, {3,6,5,1}, {6,3,1,5}, {3,6,4,5}, {3,6,4,5}
222 };
223
224 itemsize = 4*sizeof(int);
225 Nwanted = sizeof(wanted4b) / itemsize;
226 flatwanted = calloc(Nwanted, itemsize);
227 for (i=0; i<Nwanted; i++) {
228 memcpy(flatwanted+i*4, wanted4b[i], itemsize);
229 }
230 testit(flatwanted, Nwanted, 4, compare_quad, TRUE);
231 free(flatwanted);
232
233 itemsize = 3*sizeof(int);
234 Nwanted = sizeof(wanted3b) / itemsize;
235 flatwanted = calloc(Nwanted, itemsize);
236 for (i=0; i<Nwanted; i++) {
237 memcpy(flatwanted+i*3, wanted3b[i], itemsize);
238 }
239 testit(flatwanted, Nwanted, 3, compare_tri, TRUE);
240 free(flatwanted);
241
242 itemsize = 5*sizeof(int);
243 Nwanted = sizeof(wanted5b) / itemsize;
244 flatwanted = calloc(Nwanted, itemsize);
245 for (i=0; i<Nwanted; i++) {
246 memcpy(flatwanted+i*5, wanted5b[i], itemsize);
247 }
248 testit(flatwanted, Nwanted, 5, compare_quint, TRUE);
249 free(flatwanted);
250
251
252 return 0;
253 }
254
255