exQHV
Compute Exclusive HyperVolumes sequentially
 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 "quickhvolume.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 point PTS[1<<N] __attribute__ ((aligned (CLS)));
59 static int C2P[1<<N] __attribute__ ((aligned (CLS)));
60 static int C[N][N+1] __attribute__ ((aligned (CLS)));
62 /*** file scope functions declarations ********************/
63 
64 static double InExClusion(point* zero, point* one, int n, int* idx, point* P);
65 
66 /*** public functions declarations ************************/
67 
68 /*** file scope functions *********************************/
69 
70 /* ------------------------------------------------------ */
71 
72 /*** public functions *************************************/
73 
74 void IECinit(void)
75 {
76  int i;
77  int j;
78 
80  i = 0;
81  while(i < N)
82  {
83  C[i][0] = 1;
84  C[i][i] = 1;
85  j = 1;
86  while(j < i)
87  {
88  C[i][j] = C[i-1][j-1] + C[i-1][j];
89  j++;
90  }
91  i++;
92  }
93 
95  i = 0;
96  while(i < N)
97  {
98  j = 1;
99  while(j <= i)
100  {
101  C[i][j] += C[i][j-1];
102  j++;
103  }
104  i++;
105  }
106 }
107 
108 static double InExClusion(point* zero, point* one, int n, int* idx, point* PS)
109 {
110  assert(n <= N);
111 
112  double res;
113  int i;
114  int j;
115  int twoton;
116  int ones;
117  int counts[N+2];
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) */
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); */
165 
166 /* j = 0; */
167 /* while(j < n) */
168 /* { */
169 /* swap(idx, 0, j); */
170 /* exHV[idx[0]] += T - InExClusion(zero, one, n-1, &(idx[1]), PS); */
171 /* j++; */
172 /* } */
173 
174 /* return T; */
175 /* } */
176 
177 double exInExClusion(point* zero, point* one, int n, int* idx, point* PS, double* exHV)
178 {
179  assert(n <= N);
180 
181  int i;
182  int j;
183  int twoton;
184  int ones;
185  double T;
186  double H;
188  T = InExClusion(zero, one, n, idx, PS);
189 
190  twoton = 1 << n;
191  i = 1;
192  ones = 1;
193  while(i < twoton)
194  {
195  j = i;
196  H = HV(zero, &(PTS[C2P[i]]));
197  if(0 == (ones & 1))
198  H = -H;
199 
200  while(0 != j)
201  {
202  exHV[idx[fastLog2(Rbit(j))]] += H;
203  j = Rpop(j);
204  }
205  i++;
206  ones++;
207  ones-=fastLog2(Rbit(i));
208  }
209 
210  return T;
211 }
212 
213 
int i
Definition: dominant.c:43
double exInExClusion(point *zero, point *one, int n, int *idx, point *PS, double *exHV)
Definition: inexclusion.c:177
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:74
struct point __attribute__((aligned(16))) point
All points must be aligned for SSE2.
Inclusion Exclusion Algorithm better than HSO for high d and small n.
Point is an array of coordinates, in a struct for simple and fast copy.
Definition: point.h:58
#define Rbit(N)
Definition: subsets.h:81