home *** CD-ROM | disk | FTP | other *** search
/ vis-ftp.cs.umass.edu / vis-ftp.cs.umass.edu.tar / vis-ftp.cs.umass.edu / pub / Software / ASCENDER / ascendMar8.tar / UMass / BuildingFinder / Staging / sortNodes.c < prev    next >
C/C++ Source or Header  |  1994-01-24  |  1KB  |  69 lines

  1. #include "../polygons.h"
  2.  
  3.  
  4. MGvertexList *sort_top_K_nodes(MGvertex *meta_graph, int k)
  5. {
  6.    int size, i;
  7.    MGvertexList *list;
  8.    MGvertex *node;
  9.    MGedgeList *eptr;
  10.    double max = 999999.99;
  11.    double newmax;
  12.  
  13.    fprintf(stderr,"Sorting top %d nodes\n",k);
  14.  
  15.    list = (MGvertexList *) malloc(sizeof(MGvertexList));
  16.    list->eList = (MGedgeList *) malloc(sizeof(MGedgeList));
  17.  
  18.    node = get_max_MG(meta_graph,max, &newmax);
  19.    list->eList->vertex = node;
  20.    list->eList->next = NULL;
  21.    fprintf(stderr,"MAX: %f\n",max);
  22.    max = newmax;
  23.  
  24.    eptr = list->eList;
  25.    for (i=1 ; i < k; i++) {
  26.        fprintf(stderr,"%d\n",i);
  27.        fprintf(stderr,"MAX: %f\n",max);
  28.        node = get_max_MG(meta_graph,max, &newmax);
  29.     fprintf(stderr,"bak: %f\n",newmax);
  30.     if (node != NULL) {
  31.         eptr->next = (MGedgeList *) malloc(sizeof(MGedgeList));
  32.         eptr->next->vertex = node;
  33.         eptr = eptr->next; 
  34.         eptr->next = NULL;
  35.         max = newmax;
  36.     } else 
  37.         break;
  38.         
  39.    }
  40.    fprintf(stderr,"Done.\n");
  41.    return(list);
  42. }
  43.  
  44. MGvertex *get_max_MG(MGvertex *graph, double max, double *new)
  45. {
  46.  
  47.    MGvertex *ptr, *temp;
  48.    double current=-9999.99;
  49.  
  50.    temp = NULL;
  51.    ptr = graph;
  52.    while (ptr != NULL) {
  53.     if ((ptr->confidence > current)  && (ptr->confidence < max)) {
  54.         current = ptr->confidence;
  55.         temp = ptr;
  56.     }
  57.     ptr = ptr->next;
  58.   }
  59.  
  60.   if (temp != NULL) {
  61.       *new = temp->confidence;
  62.       return(temp);
  63.   } else {
  64.     *new = 0.0;
  65.     return(NULL);
  66.   }
  67. }
  68.         
  69.