QHV
Compute 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 "Quick
8  * HyperVolume, Luís M. S. Russo, Alexandre P. Francisco IEEE Trans.
9  * Evolutionary Computation 18(4): 481-502(2014)".
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 
27 
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 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 /*** public functions declarations ************************/
65 
66 /*** file scope functions *********************************/
67 
68 /* ------------------------------------------------------ */
69 
70 /*** public functions *************************************/
71 
72 void IECinit(void)
73 {
74  int i;
75  int j;
76 
78  i = 0;
79  while(i < N)
80  {
81  C[i][0] = 1;
82  C[i][i] = 1;
83  j = 1;
84  while(j < i)
85  {
86  C[i][j] = C[i-1][j-1] + C[i-1][j];
87  j++;
88  }
89  i++;
90  }
91 
93  i = 0;
94  while(i < N)
95  {
96  j = 1;
97  while(j <= i)
98  {
99  C[i][j] += C[i][j-1];
100  j++;
101  }
102  i++;
103  }
104 }
105 
106 double InExClusion(point* zero, point* one, int n, int* idx, point* PS)
107 {
108  assert(n <= N);
109 
110  double res;
111  int i;
112  int j;
113  int twoton;
114  int ones;
115  int counts[N+2];
117  res = 0;
118 
120  i = 0;
121  j = 1;
122  while(i < n)
123  {
124  intercept(&(PTS[i+1]), one, &(PS[idx[i]]));
125  i++;
126  res += HV(zero, &(PTS[i]));
127  C2P[j] = i;
128  j <<= 1;
129  }
130 
131  twoton = 1 << n;
132  memcpy(&counts[1], &C[n][0], (n+1)*sizeof(int));
133  i = 1;
134  ones = 1;
135  while(i < twoton)
136  {
137  if(ones > 1)
138  {
139  C2P[i] = counts[ones];
140  counts[ones]++;
141  intercept(&(PTS[C2P[i]]), &(PTS[C2P[Rbit(i)]]), &(PTS[C2P[Rpop(i)]]));
142  if(ones & 1)
143  res += HV(zero, &(PTS[C2P[i]]));
144  else
145  res -= HV(zero, &(PTS[C2P[i]]));
146  }
147  i++;
148  ones++;
149  ones-=fastLog2(Rbit(i));
150  }
151 
152  return res;
153 }
This returns iterators for diferent type. WARNING, these objects are singleton, so new overwrites exi...
Simple point interface. Contains simple point manipulation functions.
double InExClusion(point *zero, point *one, int n, int *idx, point *PS)
Definition: inexclusion.c:106
#define Rpop(N)
Definition: subsets.h:88
void IECinit(void)
Definition: inexclusion.c:72
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