cuiksort.c
Go to the documentation of this file.
1 #include "box_list.h"
2 #include "box.h"
3 #include "glr.h"
4 #include "llr.h"
5 #include "defines.h"
6 #include "error.h"
7 #include "filename.h"
8 
9 
10 #include <string.h>
11 #include <stdlib.h>
12 
46 /************************************************************************************/
48 /* Topologies used when sorting boxes */
49 
50 #define RN_TOPOLOGY 0 // Defines Rn topology to be used in graph construction
51 #define TORUS_TOPOLOGY 1 // Defines Torus topology to be used in graph construction
52 
53 /* Ways to traverse a graph*/
54 #define TRAVERSE_DEPTH_FIRST 0 // Traverse the graph in depth-first order
55 #define TRAVERSE_CYCLES 1 // Traverse only the cycles of the graph
56 #define TRAVERSE_WITHOUT_ORDER 2 // Traverse the graph with no specific order
57 
58 /* Tolerance in the box intersection when defining a graph */
59 #define INTERSECT_TOL 1e-3 // Threshold to decide whether two boxes intersect
60 
61 boolean NormalIntervalsIntersect(Tinterval *i1, Tinterval *i2);
62 boolean AngleIntervalsIntersect(Tinterval *i1, Tinterval *i2);
63 boolean BoxesAreNeighboring(Tbox* box1, Tbox* box2, int topology);
64 boolean BoxesIntersect(Tbox* box1, Tbox* box2, int topology);
65 void ConnectFirstBoxInGraphOfBoxes(graph G,int topology);
66 graph GraphOfBoxes(Tlist* boxlist, int topology);
67 status TraverseDepthFirstComponent(graph_vertex root_v, graph_vertex curr_v, Tlist* boxlist);
68 llist TraverseDepthFirstGraphOfBoxes(graph G);
69 llist TraverseCyclesGraphOfBoxes(graph G, int nskip);
70 llist TraverseAllNodesWithoutOrder(graph G);
71 llist TraverseGraphOfBoxes(graph G, int traversal_type);
72 void PrintWalk(FILE* f, llist walk, int stepsize);
73 
74 //*******************************************************************************
75 
76 //******************************************************************************
77 // NormalIntervalsIntersect
78 //
79 // Tells whether two "normal" intervals intersect. The intervals must have their
80 // lower limit below their upper limit.
81 //******************************************************************************
82 boolean NormalIntervalsIntersect(Tinterval *i1, Tinterval *i2)
83 {
84  return(Intersect(i1,i2));
85 }
86 
87 //******************************************************************************
88 // AngleIntervalsIntersect
89 //
90 // Tells whether two angle intervals intersect. The intervals must be in the
91 // range [0,2pi]. Intervals with lower limit > upper limit are allowed, provided
92 // the limits are within the [0,2pi] range.
93 //******************************************************************************
94 boolean AngleIntervalsIntersect(Tinterval *i1, Tinterval *i2)
95 {
96  double i1l, i1u, i2l, i2u;
97  Tinterval a, b, c, d;
98 
99  // Interval limits
100  i1l = i1->lower_limit; i1u = i1->upper_limit;
101  i2l = i2->lower_limit; i2u = i2->upper_limit;
102 
103  // If intervals are "normal" (with lower < upper)...
104  if(i1l <= i1u && i2l <= i2u)
105  {
106  // ... check first whether they are connected through 0 or 2pi
107  if((i1l == 0 && i2u == 2*M_PI) || (i2l == 0 && i1u == 2*M_PI))
108  return(TRUE);
109  // else check intersection in the normal way
110  else
111  return(Intersect(i1,i2));
112  }
113 
114  // If i1 has lower > upper ...
115  if(i1l > i1u)
116  {
117  // ... split i1 into two intervals a and b, and call me again
118  NewInterval(i1l,2*M_PI,&a);
119  NewInterval(0,i1u,&b);
120  return(AngleIntervalsIntersect(&a,i2) || AngleIntervalsIntersect(&b,i2));
121  }
122 
123  // If i2 has lower > upper ...
124  if(i2l > i2u)
125  {
126  // ... split i2 into two intervals c and d, and call me again
127  NewInterval(i2l,2*M_PI,&c);
128  NewInterval(0,i2u,&d);
129  return(AngleIntervalsIntersect(i1,&c) || AngleIntervalsIntersect(i1,&d));
130  }
131 
132  return(FALSE);
133 }
134 
135 //******************************************************************************
136 // ConnectFirstBoxInGraphOfBoxes - Connects the first box of a box graph to any
137 // neighboring boxes.
138 //******************************************************************************
139 
140 boolean BoxesAreNeighboring(Tbox* box1, Tbox* box2, int topology)
141 {
142  return(BoxesIntersect(box1,box2,topology));
143 }
144 
145 //******************************************************************************
146 // BoxesIntersect - Returns TRUE if the given boxes intersect
147 // Two boxes intersect iff no pair of corresponding intervals are disjoint
148 //******************************************************************************
149 boolean BoxesIntersect(Tbox* box1, Tbox* box2, int topology)
150 {
151  Tinterval* intv1;
152  Tinterval* intv2;
153  unsigned int i, dim;
154  boolean boxes_intersect;
155  double i1l, i1u, i2l, i2u;
156 
157  // Get boxes dimension
158  dim = GetBoxNIntervals(box1);
159 
160  // Iterate over all intervals of the boxes
161  for(i=0;i<dim;i++)
162  {
163  // Get corresponding intervals
164  intv1 = GetBoxInterval(i,box1);
165  intv2 = GetBoxInterval(i,box2);
166 
167  // Backup interval limits
168  i1l = intv1->lower_limit; i1u = intv1->upper_limit;
169  i2l = intv2->lower_limit; i2u = intv2->upper_limit;
170 
171  // Enlarge intervals a bit
172  intv1->lower_limit = intv1->lower_limit - INTERSECT_TOL;
173  intv1->upper_limit = intv1->upper_limit + INTERSECT_TOL;
174  intv2->lower_limit = intv2->lower_limit - INTERSECT_TOL;
175  intv2->upper_limit = intv2->upper_limit + INTERSECT_TOL;
176 
177  // Test intersection
178  switch(topology)
179  {
180  case RN_TOPOLOGY:
181  boxes_intersect = NormalIntervalsIntersect(intv1,intv2);
182  break;
183  case TORUS_TOPOLOGY:
184  boxes_intersect = AngleIntervalsIntersect(intv1,intv2);
185  break;
186  }
187 
188  // Restore original intervals
189  intv1->lower_limit = i1l; intv1->upper_limit = i1u;
190  intv2->lower_limit = i2l; intv2->upper_limit = i2u;
191 
192  // If the intervals are disjoint, the boxes do not intersect
193  if(!boxes_intersect)
194  return(FALSE);
195  }
196 
197  // If all intervals intersect, the boxes intersect
198  return(TRUE);
199 }
200 
201 //******************************************************************************
202 // ConnectFirstBoxInGraphOfBoxes - Connects the first box of a box graph to any
203 // neighboring boxes.
204 //******************************************************************************
205 void ConnectFirstBoxInGraphOfBoxes(graph G,int topology)
206 {
207  llist curr_v;
208  llist first_v;
209  Tbox* first_box;
210  Tbox* curr_box;
211  static int edge_count=1;
212 
213  // Pointer to first vertex and its box
214  first_v = G;
215  if(first_v==NULL)
216  Error("Error: empty graph in ConnectFirstBox");
217 
218  first_box = (Tbox*)SPECIFIC_VERTEX_DATA(first_v);
219 
220  // Iterate from the second to the last vertices (boxes)
221  for(curr_v=NEXT(first_v); curr_v!=NULL; curr_v=NEXT(curr_v))
222  {
223  curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_v);
224  if(BoxesAreNeighboring(first_box,curr_box,topology))
225  {
226  add_edge_with_pointers(first_v,curr_v,NULL);
227  printf("Edge added number %d\n", edge_count);
228  edge_count++;
229  }
230  }
231 }
232 
233 graph GraphOfBoxes(Tlist* boxlist, int topology)
234 {
235  graph G;
236  Tbox* curr_box;
237  Titerator iter;
238  int boxnumber;
239 
240  // Initialize graph of boxes
241  if(init_graph(&G)==ERROR)
242  Error("Error:: init_graph() failed in GraphOfBoxes()");
243 
244  // Iterate over the list of boxes
245  InitIterator(&iter,boxlist);
246  First(&iter);
247  boxnumber=1;
248  while(!EndOfList(&iter))
249  {
250  // Get a box from the list
251  curr_box=(Tbox*)GetCurrent(&iter);
252  printf("Adding box %d to the graph\n", boxnumber);
253 
254  // Add it as the first box of the graph
255  if(insert_vertex(&G,boxnumber,(void*)curr_box)==ERROR)
256  Error("Error in Graph of Boxes: couldn't insert vertex");
257 
258  // Connect the box to its neighbouring boxes
259  ConnectFirstBoxInGraphOfBoxes(G,topology);
260 
261  // Advance cursors and box number
262  Advance(&iter);
263  boxnumber++;
264  }
265 
266  return(G);
267 }
268 
269 
270 //*******************************************************************************
271 // TraverseDepthFirstComponent
272 // Preconditions: at the top-level call all vertices must be marked as non-visited.
273 //*******************************************************************************
274 
275 status TraverseDepthFirstComponent(graph_vertex root_v,
276  graph_vertex curr_v,
277  Tlist* boxlist)
278 {
279  llist curr_e; // Current edge: an edge emanating from current vertex
280  llist adj_v; // The vertex adjacent to current vertex
281  Tbox* curr_box; // The box stored in current vertex
282 /* static int count = 0; */
283 
284  // protection against the case of NULL pointers
285  if(root_v==NULL || curr_v==NULL)
286  return ERROR;
287 
288 /* // Print the degree */
289 /* if(degree(curr_v)>2) */
290 /* { */
291 /* printf("%d:: degree = %d\n", count, degree(curr_v)); */
292 /* curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_v); */
293 /* PrintBox(stdout,curr_box); */
294 /* } */
295 /* count++; */
296 
297  // mark the current vertex as visited
298  VISITED(curr_v)=TRUE;
299 
300  // store the box in it
301  curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_v);
302  AddLastElement((void*)curr_box,boxlist);
303 
304  // for all neighboring vertices of curr_v ...
305  for(curr_e=EMANATING(curr_v); curr_e!=NULL; curr_e=NEXT(curr_e))
306  {
307  // get pointer to the current adjacent vertex
308  adj_v = VERTEX_POINTER(curr_e);
309 
310  // if adjacent vertex is not yet visited ...
311  if(!VISITED(adj_v))
312  {
313  // visit the vertex and its descendants ...
314  if(TraverseDepthFirstComponent(root_v,adj_v,boxlist)==ERROR)
315  return ERROR;
316  // store the box again upon backtracking
317  // AddLastElement((void*)curr_box,boxlist);
318  }
319  }
320 
321  return OK;
322 }
323 
324 //*******************************************************************************
325 // TraverseAllNodesWithoutOrder
326 //*******************************************************************************
327 
328 llist TraverseAllNodesWithoutOrder(graph G)
329 {
330  llist walk_list; // A list of connected box components
331  graph_vertex curr_v; // Current vertex while searching for connected components
332  Tlist* box_list; // A list of boxes for a walk
333  Tbox* curr_box; // The box stored in current vertex
334 
335  // pertinent protection
336  if(G==NULL)
337  Error("Error in TraverseDepthFirstGraphOfBoxes: empty graph");
338 
339  // Initialize list of walks to be returned
340  if(init_list(&walk_list)==ERROR)
341  Error("Error in TraverseDepthFirstGraphOfBoxes: unable to initialize list");
342 
343  // Traverse the graph
344  NEW(box_list,1,Tlist);
345  InitListOfBoxes(box_list);
346 
347  for(curr_v=G; curr_v!=NULL; curr_v=NEXT(curr_v))
348  {
349  curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_v);
350  AddLastElement((void*)curr_box,box_list);
351  }
352 
353  // Insert list of boxes into walk_list
354  insert(&walk_list,(generic_ptr)box_list);
355 
356  // Return list of walks
357  return(walk_list);
358 }
359 
360 
361 //*******************************************************************************
362 // TraverseDepthFirstGraphOfBoxes
363 //
364 // Traverses all connected components of a graph G, in depth first order. Returns
365 // a list of walks, where wach walk is a depth-first traversal of a connected
366 // component. Each node of this returned list actually points to a list of boxes,
367 // the boxes corresponding to the mentioned walk.
368 //*******************************************************************************
369 
370 llist TraverseDepthFirstGraphOfBoxes(graph G)
371 {
372  llist walk_list; // A list of connected box components
373  graph_vertex curr_v; // Current vertex while searching for connected components
374  Tlist* box_list; // A list of boxes for a walk
375 
376  // pertinent protection
377  if(G==NULL)
378  Error("Error in TraverseDepthFirstGraphOfBoxes: empty graph");
379 
380  // Initialize list of walks to be returned
381  if(init_list(&walk_list)==ERROR)
382  Error("Error in TraverseDepthFirstGraphOfBoxes: unable to initialize list");
383 
384  // Traverse the graph
385  mark_all_unvisited(G);
386  for(curr_v=G; curr_v!=NULL; curr_v=NEXT(curr_v)) {
387  if(!VISITED(curr_v)) {
388  // Traverse the connected component of current vertex, ntimes times
389  NEW(box_list,1,Tlist);
390  InitListOfBoxes(box_list);
391  TraverseDepthFirstComponent(curr_v, curr_v, box_list);
392  insert(&walk_list,(generic_ptr)box_list);
393  }
394  }
395 
396  // Return list of walks
397  return(walk_list);
398 }
399 
400 
401 //*******************************************************************************
402 // TraverseCyclesGraphOfBoxes
403 //
404 // Traverses the cycles of a graph G. Returns a list of cycles. Each node in this
405 // list points to a cycle of boxes.
406 //*******************************************************************************
407 
408 llist TraverseCyclesGraphOfBoxes(graph G, int nskip)
409 {
410  llist components; // List of components of G
411  llist root; // Pointer to a vertex of current component
412  llist cycles; // List of cycles of a component
413  llist walk_list; // List of walks to be returned
414  Tlist* box_list; // The list of boxes of a walk
415  Tbox* curr_box; // The box stored in current vertex
416  llist node_comp; // A node of the lit "components"
417  llist node_cyc; // A node of the list "cycles"
418  llist node_vert; // A node of the list CYC_VERTICES(cycles)
419  int i;
420 
421  // Initialize list of walks to be returned
422  if(init_list(&walk_list)==ERROR)
423  Error("Error in TraverseCyclesGraphOfBoxes: unable to initialize list");
424 
425  // Generate list of connected components
426  init_list(&components);
427  if(connected_components(G,&components)==ERROR)
428  Error("Error in TraverseCyclesGraphOfBoxes: connected_components failed");
429 
430  printf("Generating list of walks. One walk for each cycle of the graph...\n");
431  printf("\tNumber of connected components is %d\n", length(components));
432 
433  // Get the cycles of each connected component
434  for(node_comp=components; node_comp!=NULL; node_comp=NEXT(node_comp))
435  {
436  // Get pointer to current component
437  root = (llist)(DATA(node_comp));
438  printf("\tNew component:\n");
439 
440  // Obtain the cycles of this component
441  init_list(&cycles);
442  if(detect_fundamental_cycles(root, &cycles, NULL)==ERROR)
443  Error("Error in TraverseCyclesGraphOfBoxes: failed to detect fundamental cycles");
444  printf("\t\tNumber of cycles of this component is %d\n", length(cycles));
445 
446  // Generate a walk for each cycle, and add it to the list of walks
447  for(node_cyc = cycles; node_cyc!=NULL; node_cyc=NEXT(node_cyc))
448  {
449  // Generate the list of boxes of this cycle (of type Tlist)
450  NEW(box_list,1,Tlist);
451  InitListOfBoxes(box_list);
452  for(node_vert=CYC_VERTICES(node_cyc); node_vert!=NULL; node_vert=NEXT(node_vert))
453  {
454  // We convert the *list* of vertices to a *Tlist* of boxes
455  // curr_vertex = (graph_vertex)DATA(node_vert);
456  // curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_vertex);
457  curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(node_vert);
458  AddLastElement((void*)curr_box,box_list);
459 
460  // Skip nskip boxes (usefull when clustering exists, e.g. cycloheptane)
461  i=0;
462  while(NEXT(node_vert)!=NULL && i<nskip)
463  {
464  node_vert=NEXT(node_vert);
465  i++;
466  }
467  }
468 
469  // Add the list of boxes as a node of the list of walks (of type list)
470  append(&walk_list,(generic_ptr)box_list);
471  }
472 
473  // Destroy temporary list of cycles
474  destroy_list(&cycles,NULL);
475  }
476 
477  // Destroy dynamic memory
478  destroy_list(&components,NULL);
479 
480  return(walk_list);
481 }
482 
483 //*******************************************************************************
484 // TraverseGraphOfBoxes
485 //
486 // Traverses a graph of boxes. Returns a list of walks. Each
487 // walk is a list of boxes corresponding either to a cycle (when
488 // traversal_type==TRAVERSE_CYCLES) or to a connected component traversed
489 // in a depth-first order (when traversal_type==TRAVERSE_DEPTH_FIRST)
490 //*******************************************************************************
491 
492 llist TraverseGraphOfBoxes(graph G, int traversal_type)
493 {
494  llist walk_list=NULL;
495 
496  // Different traversals are possible
497  switch(traversal_type)
498  {
499  case TRAVERSE_CYCLES:
500  // Returns a list of cycle traversals
501  walk_list = TraverseCyclesGraphOfBoxes(G,0);
502  break;
503  case TRAVERSE_DEPTH_FIRST:
504  // Returns a list of connected component traversals
505  walk_list = TraverseDepthFirstGraphOfBoxes(G);
506  break;
507  case TRAVERSE_WITHOUT_ORDER:
508  // Returns a list of all boxes in the graph, with no specific order
509  walk_list = TraverseAllNodesWithoutOrder(G);
510  break;
511  default:
512  // Detect invalid traversal type
513  Error("Error in TraverseGraphOfBoxes: invalid traversal type");
514  break;
515  }
516 
517  return(walk_list);
518 }
519 
520 //*******************************************************************************
521 // PrintWalk
522 // Prints the boxes of a walk to a file "f".
523 //*******************************************************************************
524 void PrintWalk(FILE* f, llist walk, int stepsize)
525 {
526  Tbox* curr_box;
527  Titerator iter;
528  Tlist* walk_box_list;
529  unsigned int i;
530 
531  // Get the list of boxes of the walk
532  walk_box_list = (Tlist*)DATA(walk);
533 
534  // Iterate over all boxes and print them
535  InitIterator(&iter,walk_box_list);
536  First(&iter);
537  while(!EndOfList(&iter))
538  {
539  // Get current box
540  curr_box = (Tbox *)GetCurrent(&iter);
541 
542  // Print the box
543  PrintBox(f,curr_box);
544 
545  // Forward stepsize elements
546  for(i=0;i<(unsigned int)stepsize;i++)
547  Advance(&iter);
548  }
549 }
578 int main(int argc, char **arg)
579 {
580  if (argc<2)
581  {
582  fprintf(stdout,"Use:\n");
583  fprintf(stdout," cuiksort <basename> <topology> <travmode> <stepsize> \n");
584  fprintf(stdout,"Where:\n");
585  fprintf(stdout," basename: The basename of the *.sol input file\n");
586  fprintf(stdout," topology: May be 'r' (for Rn topology) or 't' (for torus topology)\n");
587  fprintf(stdout," travmode: May be 'd' (depth 1st) or 'c' (for cycles) or 'u' (for unordered)\n");
588  fprintf(stdout," stepsize: Stepsize used when printing the boxes of a walk to a file\n");
589  fprintf(stdout,"Examples:\n");
590  fprintf(stdout," sortboxes ./examples/cyclohexane r d 1\n");
591  fprintf(stdout," sortboxes ./examples/cycloheptane r d 1\n");
592  fprintf(stdout," sortboxes ./examples/cycloctane r d 1\n");
593  }
594  else
595  {
596  char suffix[50];
597  Tlist sol_box_list; // List of solution boxes
598  graph G; // Graph of boxes, made out of sol_box_list
599  llist walk_list; // List of walks, altogether integrating a traversal of G
600  llist curr_walk; // Current walk in the previous list
601  Tlist* walk_box_list; // List of boxes of a walk
602  int traversal_type=0;
603  int walk_number;
604  int topology;
605  FILE *fd;
606  int nisol;
607  graph_vertex curr_v;
608  Tbox* curr_box;
609  int stepsize;
610  Tfilename fsols,fout;
611 
612 
613  if (argc<3)
614  topology = RN_TOPOLOGY; //default topology
615  else
616  {
617  // Get topology
618  switch(arg[2][0])
619  {
620  case 'r':
621  topology = RN_TOPOLOGY;
622  printf("Using Rn topology\n");
623  break;
624  case 't':
625  topology = TORUS_TOPOLOGY;
626  printf("Using torus topology\n");
627  break;
628  }
629  }
630 
631  if (argc<4)
632  traversal_type = TRAVERSE_DEPTH_FIRST; // default traverse mode
633  else
634  {
635  // Get traversal type
636  switch(arg[3][0])
637  {
638  case 'd':
639  traversal_type = TRAVERSE_DEPTH_FIRST;
640  printf("Walks in depth-first mode\n");
641  break;
642  case 'c':
643  traversal_type = TRAVERSE_CYCLES;
644  printf("Walks in cycles mode\n");
645  break;
646  case 'u':
647  traversal_type = TRAVERSE_WITHOUT_ORDER;
648  printf("Walks in unordered mode\n");
649  break;
650  default:
651  Error("Unknown traversal mode\n");
652  break;
653  }
654  }
655 
656  if (argc<5)
657  stepsize=1;
658  else
659  {
660  // Get stepsize
661  stepsize = (unsigned int)(atoi(arg[4]));
662  }
663 
664  // Read the list of solution boxes (TRUE avoids reading duplicated variables)
665  CreateFileName(NULL,arg[1],NULL,SOL_EXT,&fsols);
666  ReadListOfBoxes(GetFileFullName(&fsols),&sol_box_list);
667  if(ListSize(&sol_box_list)==0)
668  Error("Couldn't open solutions file\n");
669 
670  // Generate graph of boxes
671  G = GraphOfBoxes(&sol_box_list,topology);
672 
673  // Traverse the graph, generating a list of walks
674  walk_list = TraverseGraphOfBoxes(G,traversal_type);
675 
676  // Generate one *.sol file for each walk, excluding one-box walks
677  walk_number=1;
678  for(curr_walk=walk_list; curr_walk!=NULL; curr_walk=NEXT(curr_walk))
679  {
680  // Get list of boxes in current walk
681  walk_box_list = (Tlist*)DATA(curr_walk);
682 
683  if(ListSize(walk_box_list) > 1)
684  {
685  // Open output file
686  sprintf(suffix,"_%d",walk_number);
687  CreateFileName(NULL,arg[1],suffix,SOL_EXT,&fout);
688  printf("Generating %s ...",GetFileFullName(&fout));
689  fd = fopen(GetFileFullName(&fout),"w");
690  if(fd==NULL)
691  Error("Couldn't open output file\n");
692 
693  // Print the walk
694  PrintWalk(fd,curr_walk,stepsize);
695  fclose(fd);
696  printf("done.\n");
697  DeleteFileName(&fout);
698 
699  walk_number++;
700  }
701  }
702 
703  // Generate an extra *.sol with all isolated boxes
704  nisol = 0;
705  CreateFileName(NULL,arg[1],"_isol",SOL_EXT,&fout);
706  fd = fopen(GetFileFullName(&fout),"w");
707  if(fd==NULL)
708  Error("Couldn't open file\n");
709  printf("Generating %s ...",GetFileFullName(&fout));
710  for(curr_v=G; curr_v!=NULL; curr_v = NEXT(curr_v))
711  {
712  if(degree(curr_v)==0)
713  {
714  curr_box = (Tbox*)SPECIFIC_VERTEX_DATA(curr_v);
715  PrintBox(fd,curr_box);
716  nisol ++;
717  }
718  }
719  fclose(fd);
720  printf("done.\n");
721  printf("%d isolated boxes.\n",nisol);
722 
723  DeleteFileName(&fout);
724  DeleteFileName(&fsols);
725  }
726 
727  return(EXIT_SUCCESS);
728 }
729 
void First(Titerator *i)
Moves an iterator to the first position of its associated list.
Definition: list.c:356
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
boolean Intersect(Tinterval *i1, Tinterval *i2)
Checks is a two intervals intersect.
Definition: interval.c:272
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:248
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
boolean ReadListOfBoxes(char *filename, Tlist *l)
Reads a list of boxes from a file.
Definition: box_list.c:286
Collection of methods to work on Tlist of boxes.
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:992
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
void AddLastElement(void *Info, Tlist *list)
Adds an element at the tail of the list.
Definition: list.c:206
boolean EndOfList(Titerator *i)
Checks if an iterator is pointing at the end of the list.
Definition: list.c:445
Definition of the Tbox type and the associated functions.
Definitions of constants and macros used in several parts of the cuik library.
A generic list.
Definition: list.h:46
void InitIterator(Titerator *i, Tlist *list)
Constructor.
Definition: list.c:284
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define M_PI
Pi.
Definition: defines.h:83
#define SOL_EXT
File extension for solution files.
Definition: filename.h:137
A box.
Definition: box.h:83
int main(int argc, char **arg)
Main body of the cuiksort application.
Definition: cuiksort.c:578
void InitListOfBoxes(Tlist *l)
Constructor.
Definition: box_list.c:24
void * GetCurrent(Titerator *i)
Gets the element pointed by the iterator.
Definition: list.c:299
double upper_limit
Definition: interval.h:36
double lower_limit
Definition: interval.h:35
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
List iterator.
Definition: list.h:61
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1118
unsigned int ListSize(Tlist *list)
Gets the number of elements in the list.
Definition: list.c:180
Defines a interval.
Definition: interval.h:33
boolean Advance(Titerator *i)
Moves an iterator to the next position of its associated list.
Definition: list.c:373