parExQHV
Compute Exclusive HyperVolumes using threads
 All Data Structures Files Functions Variables Macros
inexclusion.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) Year(s), 2013, Luis M. S. Russo and Alexandre
4  * P. Francisco / KDBIO / INESC-ID, <qhv@kdbio.inesc-id.pt>
5  *
6  * Any published media that is related with to use of the distributed
7  * software, or derived software, must contain a reference to "Extending
8  * quick hypervolume. Luís M. S. Russo, Alexandre P. Francisco:
9  * J. Heuristics 22(3): 245-271 (2016)".
10  *
11  * Permission to use, copy, modify, and/or distribute this software for
12  * any purpose with or without fee is hereby granted, provided that the
13  * above copyright notice and this permission notice appear in all
14  * copies.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
17  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
19  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
20  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
21  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23  * PERFORMANCE OF THIS SOFTWARE.
24  *
25  */
26 
39 #include <stdio.h>
40 #include <assert.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <strings.h>
44 #include "point.h"
45 #include "constants.h"
46 #include "macros.h"
47 #include "subsets.h"
48 #include "inexclusion.h"
49 
50 /*** global variables *************************************/
51 
52 /*** file scope macro definitions *************************/
53 
54 /*** file scope type declarations *************************/
55 
56 /*** file scope variables *********************************/
57 
58 static int C[N][N+1] __attribute__ ((aligned (CLS)));
60 /*** file scope functions declarations ********************/
61 
62 /*** public functions declarations ************************/
63 
64 /*** file scope functions *********************************/
65 
66 /* ------------------------------------------------------ */
67 
68 /*** public functions *************************************/
69 
70 void IECinit(void)
71 {
72  int i;
73  int j;
74 
76  i = 0;
77  while(i < N)
78  {
79  C[i][0] = 1;
80  C[i][i] = 1;
81  j = 1;
82  while(j < i)
83  {
84  C[i][j] = C[i-1][j-1] + C[i-1][j];
85  j++;
86  }
87  i++;
88  }
89 
91  i = 0;
92  while(i < N)
93  {
94  j = 1;
95  while(j <= i)
96  {
97  C[i][j] += C[i][j-1];
98  j++;
99  }
100  i++;
101  }
102 }
103 
104 
105 static double InExClusion(point* zero, point* one, int n, int* idx, point* PS, struct iex* ax)
106 {
107  assert(n <= N);
108 
109  double res;
110  int i;
111  int j;
112  int twoton;
113  int ones;
114  int counts[N+2];
116  point* PTS = (ax->PTS);
117  int* C2P = (ax->C2P);
118 
119  res = 0;
120 
122  i = 0;
123  j = 1;
124  while(i < n)
125  {
126  intercept(&(PTS[i+1]), one, &(PS[idx[i]]));
127  i++;
128  res += HV(zero, &(PTS[i]));
129  C2P[j] = i;
130  j <<= 1;
131  }
132 
133  twoton = 1 << n;
134  memcpy(&counts[1], &C[n][0], (n+1)*sizeof(int));
135  i = 1;
136  ones = 1;
137  while(i < twoton)
138  {
139  if(ones > 1)
140  {
141  C2P[i] = counts[ones];
142  counts[ones]++;
143  intercept(&(PTS[C2P[i]]), &(PTS[C2P[Rbit(i)]]), &(PTS[C2P[Rpop(i)]]));
144  if(ones & 1)
145  res += HV(zero, &(PTS[C2P[i]]));
146  else
147  res -= HV(zero, &(PTS[C2P[i]]));
148  }
149  i++;
150  ones++;
151  ones-=fastLog2(Rbit(i));
152  }
153 
154  return res;
155 }
156 
157 /* double exInExClusion(point* zero, point* one, int n, int* idx, point* PS, double* exHV, struct iex* ax) */
158 /* { */
159 /* assert(n <= N); */
160 
161 /* int j; /\**< Index value *\/ */
162 /* double T; /\**< Total volume *\/ */
163 
164 /* T = InExClusion(zero, one, n, idx, PS, ax); */
165 
166 /* j = 0; */
167 /* while(j < n) */
168 /* { */
169 /* swap(idx, 0, j); */
170 /* exHV[j] += T - InExClusion(zero, one, n-1, &(idx[1]), PS, ax); */
171 /* j++; */
172 /* } */
173 
174 /* /// This is now important, the values must match the idx's */
175 /* j = 0; */
176 /* while(j+1 < n) */
177 /* { */
178 /* swap(idx, j, j+1); */
179 /* j++; */
180 /* } */
181 
182 /* return T; */
183 /* } */
184 
185 double exInExClusion(point* zero, point* one, int n, int* idx, point* PS, double* exHV, struct iex* ax)
186 {
187  assert(n <= N);
188 
189  int i;
190  int j;
191  int twoton;
192  int ones;
193  double T;
194  double H;
196  T = InExClusion(zero, one, n, idx, PS, ax);
197 
198  twoton = 1 << n;
199  i = 1;
200  ones = 1;
201  while(i < twoton)
202  {
203  j = i;
204  H = HV(zero, &(ax->PTS[ax->C2P[i]]));
205  if(0 == (ones & 1))
206  H = -H;
207 
208  while(0 != j)
209  {
210  exHV[fastLog2(Rbit(j))] += H;
211  j = Rpop(j);
212  }
213  i++;
214  ones++;
215  ones-=fastLog2(Rbit(i));
216  }
217 
218  return T;
219 }
220 
221 
222 /* { */
223 /* assert(n <= N); */
224 
225 /* double res; */
226 /* int i; */
227 /* int j; */
228 /* int twoton; */
229 /* int ones; /\**< Number of bits set to 1 in i *\/ */
230 /* int counts[N+2]; /\**< A counters array *\/ */
231 
232 /* point* PTS = (ax->PTS); */
233 /* int* C2P = (ax->C2P); */
234 /* double t; */
235 
236 /* res = 0; */
237 
238 /* /// Local stash of points */
239 /* i = 0; */
240 /* j = 1; */
241 /* while(i < n) */
242 /* { */
243 /* intercept(&(PTS[i+1]), one, &(PS[idx[i]])); */
244 /* i++; */
245 /* t = HV(zero, &(PTS[i])); */
246 
247 /* exHV[i-1] = t; */
248 /* res += t; */
249 /* C2P[j] = i; */
250 /* j <<= 1; */
251 /* } */
252 
253 /* twoton = 1 << n; /\**< Upper limit *\/ */
254 /* memcpy(&counts[1], &C[n][0], (n+1)*sizeof(int)); /\**< Reinit counters *\/ */
255 /* i = 1; */
256 /* ones = 1; */
257 /* while(i < twoton) /\**< Running through all combinations *\/ */
258 /* { */
259 /* if(ones > 1) */
260 /* { /\**< These are already included *\/ */
261 /* C2P[i] = counts[ones]; */
262 /* counts[ones]++; */
263 /* intercept(&(PTS[C2P[i]]), &(PTS[C2P[Rbit(i)]]), &(PTS[C2P[Rpop(i)]])); */
264 
265 /* t = HV(zero, &(PTS[C2P[i]])); */
266 /* if(!(ones & 1)) /\**< Inclusion *\/ */
267 /* t = -t; */
268 
269 /* res += t; */
270 /* associate(i, idx, t, exHV); */
271 /* } */
272 /* i++; */
273 /* ones++; */
274 /* ones-=fastLog2(Rbit(i)); */
275 /* } */
276 
277 /* return res; */
278 /* } */
This returns iterators for diferent type. WARNING, these objects are singleton, so new overwrites exi...
Simple point interface. Contains simple point manipulation functions.
#define Rpop(N)
Definition: subsets.h:88
void IECinit(void)
Definition: inexclusion.c:70
Inclusion Exclusion Algorithm better than HSO for high d and small n.
struct point __attribute__((aligned(16))) point
All points must be aligned for SSE2.
Point is an array of coordinates, in a struct for simple and fast copy.
Definition: pointStruct.h:47
#define Rbit(N)
Definition: subsets.h:81
#define fastLog2(L)
Definition: subsets.h:98
double exInExClusion(point *zero, point *one, int n, int *idx, point *PS, double *exHV, struct iex *ax)
Definition: inexclusion.c:185