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