parQHV
Compute 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 double InExClusion(point* zero, point* one, int n, int* idx, point* PS,
105  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 }
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
double InExClusion(point *zero, point *one, int n, int *idx, point *PS, struct iex *ax)
Definition: inexclusion.c:104
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