QHV
Compute HyperVolumes sequentially
 All Data Structures Files Functions Variables Macros
dominant.c
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 
28 #include <assert.h>
29 #include <stdio.h>
30 #include "dominant.h"
31 #include "point.h"
32 
33 /*** global variables *************************************/
34 #define NPs 1001
35 
37 static point PTS[NPs] __attribute__ ((aligned (CLS)));
38 
39 /*** file scope macro definitions *************************/
40 
41 /*** file scope type declarations *************************/
42 
43 /*** file scope variables *********************************/
44 
45 /*** file scope functions declarations ********************/
46 
47 /*** public functions declarations ************************/
48 
49 /*** file scope functions *********************************/
50 
51 static sureInline() void swap(int* a, int* b);
52 
53 /* static int isDominated(point* PS, int* idx, int n, int j, int exclude); */
54 
55 /* ------------------------------------------------------ */
56 
57 static sureInline() void swap(int* a, int* b)
58 {
59  int t;
60 
61  t = *a;
62  *a = *b;
63  *b = t;
64 }
65 
66 /*** public functions *************************************/
67 
68 int dominant(point* PS, int* idx, int n,
69  point *o,
70  point *p,
71  int hypoct,
72  int exclude)
73 {
74  int i;
75  int j;
76  int k;
77  int R;
78  static point newo;
79 
80  static int localidx[NPs];
82  /* printf("o: %.2f %.2f %.2f\n", o->x[0], o->x[1], o->x[2]); */
83  /* printf("p: %.2f %.2f %.2f\n", p->x[0], p->x[1], p->x[2]); */
84  /* printf("hypoct: %x\n", hypoct); */
85 
87  assert(n < NPs);
88 
89  /* if(n > 100) */
90  /* printf("Big dominat\n"); */
91 
93  projectOne(&newo, p, hypoct, o);
94  /* printf("newo: %.2f %.2f %.2f\n", newo.x[0], newo.x[1], newo.x[2]); */
95  i = 0;
96  while(i < n)
97  {
98  /* printf("Initial %d : %.2f %.2f %.2f \t", idx[i], PS[idx[i]].x[0], PS[idx[i]].x[1], PS[idx[i]].x[2]); */
99  intercept(&(PTS[i]), &newo, &(PS[idx[i]]));
100  /* printf("Projected %d : %.2f %.2f %.2f\n", idx[i], PTS[i].x[0], PTS[i].x[1], PTS[i].x[2]); */
101 
102  i++;
103  }
104 
106  k = n;
107  i = n;
108  while(i > 0)
109  {
110  i--;
111 
112  R = 0;
113  j = n;
114  while(!R && j > k)
115  {
116  j--;
117  R = (classify(&(PTS[localidx[j]]), &(PTS[i])) & ~exclude) == 0;
118  }
119 
120  if(R == 0)
121  {
122  k--;
123  localidx[k] = i;
124  }
125  }
126 
127  /* printf("Initial pass %d points \t", n-k); */
128  /* j = k; */
129  /* while(j < n) */
130  /* { */
131  /* printf("%.2f %.2f %.2f \t", PTS[localidx[j]].x[0], PTS[localidx[j]].x[1], PTS[localidx[j]].x[2]); */
132  /* j++; */
133  /* } */
134  /* printf("\n"); */
135 
137  while(k < n)
138  {
139  R = 0;
140  j = 0;
141  while(!R && j < i)
142  {
143  R = (classify(&(PTS[localidx[j]]), &(PTS[localidx[k]])) & ~exclude) == 0;
144  j++;
145  }
146 
147  if(R == 0)
148  {
149  localidx[i] = localidx[k];
150  i++;
151  }
152  k++;
153  }
154 
156  j = 0;
157  while(j < i)
158  {
159  swap(&idx[j], &idx[localidx[j]]);
160  j++;
161  }
162 
163  /* printf("Second pass %d points \t", i); */
164  /* j = 0; */
165  /* while(j < i) */
166  /* { */
167  /* printf("%.2f %.2f %.2f \t", PTS[localidx[j]].x[0], PTS[localidx[j]].x[1], PTS[localidx[j]].x[2]); */
168  /* j++; */
169  /* } */
170  /* printf("\n"); */
171 
172 
173  /* printf("First %d points \t", i); */
174  /* j = 0; */
175  /* while(j < n) */
176  /* { */
177  /* printf("point %d : %.2f %.2f %.2f \t", idx[j], PS[idx[j]].x[0], PS[idx[j]].x[1], PS[idx[j]].x[2]); */
178  /* j++; */
179  /* } */
180  /* printf("\n"); */
181 
182  return i;
183 }
Simple point interface. Contains simple point manipulation functions.
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