QHV
Compute HyperVolumes sequentially
 All Data Structures Files Functions Variables Macros
subsets.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 <stdlib.h>
29 #include <string.h>
30 #include <stdio.h>
31 #include "macros.h"
32 #include "subsets.h"
33 
34 /*** global variables *************************************/
35 struct setIterator git;
36 
37 /*** file scope macro definitions *************************/
38 
39 /*** file scope type declarations *************************/
40 
41 struct setIterator{
42  int i;
43  unsigned int S[32];
44 };
45 
46 /*** file scope variables *********************************/
47 
48 /*** file scope functions declarations ********************/
49 
50 /*** public functions declarations ************************/
51 
52 /*** file scope functions *********************************/
53 
54 /* ------------------------------------------------------ */
55 
56 /*** public functions *************************************/
57 
58 void newSets(unsigned int t)
59 {
60  int i;
61 
62  i = 0;
63  while(t > 0)
64  {
65  git.S[i] = Rbit(t);
66  i++;
67  t = Rpop(t);
68  }
69 
70  git.i = (1<<i) - 1;
71 }
72 
73 int hasNextSet(void)
74 {
75  return git.i > 0;
76 }
77 
78 unsigned int nextSet(void)
79 {
80  int i;
81  int res;
82 
83  res = 0;
84  i = git.i;
85  git.i--;
86 
87  while(i > 0)
88  {
89  res |= git.S[fastLog2(Rbit(i))];
90  i = Rpop(i);
91  }
92 
93  return res;
94 }
95 
105 /* int main(int argc, char** argv) */
106 /* { */
107 /* newSets(128+64+1); */
108 
109 /* while(hasNextSet()) */
110 /* { */
111 /* printf("%d\n", nextSet()); */
112 /* } */
113 
114 /* return 0; */
115 /* } */
void newSets(unsigned int t)
Definition: subsets.c:58
This returns iterators for diferent type. WARNING, these objects are singleton, so new overwrites exi...
#define Rpop(N)
Definition: subsets.h:88
unsigned int nextSet(void)
Definition: subsets.c:78
#define Rbit(N)
Definition: subsets.h:81
int hasNextSet(void)
Definition: subsets.c:73
#define fastLog2(L)
Definition: subsets.h:98
unsigned int S[32]
Definition: subsets.c:43