KMR
flexdice.h
1 /* flexdice.h (2014-02-04) -*-Coding: us-ascii;-*- */
2 /* Copyright (C) 1901-2014 Tomotake Nakamura */
3 
4 /* FlexDice. See "flexdice.c". */
5 
6 #include <stdbool.h>
7 
8 /* Data types: DATA=DATA_Z for integer, DATA=DATA_R for real. */
9 
10 #define DATA_Z 1
11 #define DATA_R 2
12 #define DATA DATA_R
13 
14 #if (DATA == DATA_Z)
15 #define DATATYPE int
16 #elif (DATA == DATA_R)
17 #define DATATYPE double
18 #else
19 #define DATATYPE error
20 #endif
21 
22 /* Cell state. Undetermined-cells, sparse-cells, middle-cells,
23  dense-cells. */
24 
25 enum CELLDENSITY {MADA = 0, SPARSE, MIDDLE, DENSE, DEBRIS};
26 
27 extern struct FLEXDICE fxd;
28 
29 /* Parameters to FlexDice. DIM: The number of attributes (dimension).
30  DMIN: The lower bound of the number of objects in a dense cell.
31  DFAC: The factor for the lower bound of the number of child cells
32  in a dense cell. NLAYERS: The limit of the number of layers
33  (bottom cells can have levels of this value minus one).
34  PLOT_CUT_OFF: Print threshold; only clusters holding objects more
35  than this value is printed. */
36 
37 struct INPARA {
38  int dim;
39  int dmin;
40  double dfac;
41  int nlayers;
42  int hashsize;
43  char *infile;
44  char *outdir;
45  int plot_cut_off;
46  int plot_noise;
47 };
48 
49 struct OBJECT {
50  struct OBJECT *next;
51  int id;
52  DATATYPE *value;
53 };
54 
55 /* Object Holder. */
56 
57 struct OBJECTQ {
58  struct OBJECT *head;
59  struct OBJECT *tail;
60  long count;
61 };
62 
63 /* List of cells (for hashtables). It links CELLs by the D_NEXT
64  field. */
65 
66 struct CELLS {
67  struct CELL *head;
68  long count;
69 };
70 
71 /* Cell of objects. C_NEXT links cells in CHILDREN (thus at the same
72  level), Q_NEXT for QUEUE, D_NEXT for dense cells, noise cells, and
73  hash-bin, X_NEXT for cells in clusters. PATH is a relative path
74  from its parent. CLUSTER is one it belongs to (in phase2).
75  TOTAL_OBJECT_COUNT is the number of objects in this and below. It
76  equals to the sum of the COUNTS of the all children for a cell with
77  children. */
78 
79 struct CELL {
80  struct CELL *c_next;
81  struct CELL *q_next;
82  struct CELL *d_next;
83  struct CELL *x_next;
84  int level;
85  enum CELLDENSITY density;
86  int child_count;
87  long total_object_count;
88  struct CELL *parent;
89  unsigned int *path;
90  struct CLUSTER *cluster;
91  struct CELL *children;
92  struct CELLS *hashed_children;
93  struct CELL **adjacents;
94  DATATYPE *min;
95  DATATYPE *max;
96  DATATYPE *cen;
97  struct OBJECTQ objects;
98 };
99 
100 /* FIFO queue of cells. */
101 
102 struct CELLQ {
103  struct CELL *head;
104  struct CELL *tail;
105  long count;
106 };
107 
108 /* Clusters of cells. ACTIVE indicates it is not merged to another
109  cluster (and are representatives at the end). V_NEXT links all
110  clusters created. N_NEXT links neighboring clusters as a cyclic
111  list. Cells in CELLS are linked by X_NEXT. */
112 
113 struct CLUSTER {
114  struct CLUSTER *v_next;
115  struct CLUSTER *n_next;
116  struct CELL *cells;
117  int id;
118  bool active;
119  long object_count;
120 };
121 
122 /* Information of each middle layer. It records the number of middle
123  cells, the total number of the child cells of them, and the number
124  of objects in middle cells. */
125 
126 struct LAYER {
127  long cell_count;
128  long child_cell_count;
129  long object_count;
130 };
131 
132 /* State of FlexDice. CODE_SIZE=((DIM-1)/INT_BITS+1). DEPTH_LIMITS:
133  The limit of depth for each attribute. NOISE_CELLS: List of noise
134  (sparse) cells, linked thru D_NEXT. LAYERS: Info at each layer. */
135 
136 struct FLEXDICE {
137  struct INPARA *para;
138  int DIM;
139  int DIM_UPDN;
140  int CODE_SIZE;
141 
142  int *depth_limits;
143 
144  long n_objects;
145  long n_clusters;
146  long n_cells;
147  long n_middle_cells;
148  long n_dense_cells;
149  long n_noise_cells;
150  long n_debris_cells;
151  long n_noise_objects;
152 
153  struct CLUSTER *clusters;
154  long cluster_count;
155 
156  struct CELL *noise_cells;
157  struct CELL *dense_cells;
158  struct LAYER *layers;
159 
160  struct CELLQ queue;
161 
162  struct CELL *top;
163  double t[3];
164 };
165 
166 extern void init_flexdice(int argc, char **argv, struct INPARA *);
167 extern void fin_flexdice(void);
168 extern struct CELL *create_cell(struct CELL *parent, unsigned int *path);
169 extern void read_input(struct CELL *top, struct INPARA *para);
170 extern void set_input(struct CELL *top, struct INPARA *para,
171  int *data, long count);
172 extern int flexdice(struct CELL *top, struct INPARA *para);
173 extern void print_parameters(struct INPARA *para);
174 extern void print_input(struct CELL *top);
175 extern void output_clusters(void);
Definition: flexdice.h:66
Definition: flexdice.h:79