Main Page | Alphabetical List | Class List | File List | Class Members | File Members

bary_functions.c File Reference

#include "bary.h"
#include <stdlib.h>

Include dependency graph for bary_functions.c:

Include dependency graph

Go to the source code of this file.

Defines

#define STATIC

Functions

STATIC int compare_bary (const GNODE *a, const GNODE *b)
STATIC void resort_up_down_layer (int level)
STATIC void resort_down_up_layer (int level)
void apply_horder (int i)
STATIC void mark_all_nodes (GNODE node, int i)
STATIC void phase1_down (void)
STATIC void phase1_up (void)
STATIC int cycle_sort_array (int siz)
STATIC void tree_horizontal_order (void)
STATIC void unmerge_connected_parts (void)
void copy_layers (DEPTH *l1, DEPTH *l2)
STATIC void save_level (int i)
STATIC void restore_level (int i)
STATIC void init_barycentering (void)
void barycentering (void)

Variables

int mark_all_nodes_merger
STATIC int have_alternative
STATIC int phase1_allowed


Define Documentation

#define STATIC
 

Definition at line 3 of file bary_functions.c.

Referenced by array_to_level(), calc_all_layers_crossings(), checkcrossing(), compare_pos(), cycle_sort_array(), finish_lower(), finish_upper(), graph_crossings(), gs_ide1518(), init_barycentering(), layer_crossing(), level_to_array(), mark_all_nodes(), phase1_down(), phase1_up(), phase2_down(), phase2_up(), resort_down_layer(), resort_down_up_layer(), resort_up_down_layer(), resort_up_layer(), restore_level(), save_level(), tree_horizontal_order(), and unmerge_connected_parts().


Function Documentation

void apply_horder int  i  ) 
 

Definition at line 49 of file bary_functions.c.

References compare_bary(), GNLIST, GNODE, sort_array, and tmp_layer.

Referenced by phase2_down(), phase2_up(), resort_down_layer(), and resort_up_layer().

00050 { 
00051     GNLIST hn; 
00052     int j;
00053     hn = ((tmp_layer[i]).succlist); 
00054     j = 0; 
00055 
00056     while (hn)     { 
00057         if (((((hn)->node))->nhorder) >= 0) 
00058         { 
00059             sort_array[j++] = ((hn)->node); 
00060             ((((hn)->node))->bary) = ((((hn)->node))->nhorder); 
00061         } 
00062         hn = ((hn)->next); 
00063     } 
00064     if (j) qsort (sort_array, j, sizeof (GNODE), (int (*)(const void *, const void *)) compare_bary); 
00065     hn = ((tmp_layer[i]).succlist); 
00066     j = 0; 
00067 
00068     while (hn) { 
00069         if (((((hn)->node))->nhorder) >= 0) 
00070             ((hn)->node) = sort_array[j++]; 
00071         hn = ((hn)->next); 
00072     }
00073 }

void barycentering void   ) 
 

Definition at line 383 of file bary_functions.c.

Referenced by main().

00384 {
00385     int alt; 
00386     int cross; 
00387     int changed; 
00388     int tmp_startlevel, alt_startlevel; 
00389     tmp_startlevel = alt_startlevel = 0; 
00390     changed = 1; 
00391     while (phase1_allowed && changed) 
00392     { 
00393         nr_bary_iterations++; 
00394         if (nr_bary_iterations >= max_baryiterations) 
00395         { 
00396             gs_wait_message ('t'); 
00397             break; 
00398         } 
00399         if (G_timelimit > 0) if (test_timelimit (60))  
00400         { 
00401             gs_wait_message ('t'); 
00402             break; 
00403         } 
00404         changed = 0; 
00405         phase1_down (); 
00406         cross = graph_crossings (); 
00407         alt = 0; 
00408         if ((cross < nr_crossings) || (nr_bary_iterations < min_baryiterations))  
00409         { 
00410             changed = 1; 
00411             copy_layers (layer, tmp_layer); 
00412             nr_crossings = cross; 
00413             alt_startlevel = tmp_startlevel;        
00414         } 
00415         else if (have_alternative)  
00416         { 
00417             copy_layers (tmp_layer, layer); 
00418             phase1_down (); 
00419             cross = graph_crossings (); 
00420             if (cross < nr_crossings)  
00421             { 
00422                 changed = 1; 
00423                 copy_layers (layer, tmp_layer); 
00424                 nr_crossings = cross; 
00425                 alt_startlevel = tmp_startlevel; 
00426             } 
00427             else if (cross > nr_crossings)  
00428             { 
00429                 copy_layers (tmp_layer, layer); 
00430                 tmp_startlevel = alt_startlevel; 
00431             } 
00432             else 
00433                 alt = 1; 
00434         } else if (cross == nr_crossings) 
00435             alt = 1; 
00436         else  
00437         {          
00438             copy_layers (tmp_layer, layer); 
00439             tmp_startlevel = alt_startlevel; 
00440         } 
00441         have_alternative = alt; 
00442         phase1_up (); 
00443         cross = graph_crossings (); 
00444         alt = 0; 
00445         if ((cross < nr_crossings) || (nr_bary_iterations < min_baryiterations))  
00446         {          
00447             changed = 1;     
00448             copy_layers (layer, tmp_layer); 
00449             nr_crossings = cross; 
00450             alt_startlevel = tmp_startlevel; 
00451         } 
00452         else if (have_alternative)  
00453         { 
00454             copy_layers (tmp_layer, layer); 
00455             phase1_up (); 
00456             cross = graph_crossings (); 
00457             if (cross < nr_crossings)  
00458             { 
00459                 changed = 1;                
00460                 copy_layers (layer, tmp_layer); 
00461                 nr_crossings = cross; 
00462                 alt_startlevel = tmp_startlevel; 
00463             } 
00464             else if (cross > nr_crossings)  
00465             { 
00466                 copy_layers (tmp_layer, layer); 
00467                 tmp_startlevel = alt_startlevel;                
00468             } 
00469             else 
00470                 alt = 1; 
00471         } else if (cross == nr_crossings) 
00472             alt = 1; 
00473         else  
00474         {           
00475             copy_layers (tmp_layer, layer); 
00476             tmp_startlevel = alt_startlevel; 
00477         } 
00478         have_alternative = alt; 
00479 
00480         if (nr_crossings == 0) 
00481             return; 
00482  
00483     } 
00484     if (nr_crossings == 0) 
00485         return; 
00486  
00487     if (skip_baryphase2) 
00488         return; 
00489  
00490     phase1_allowed = 0; 
00491     tmp_startlevel = alt_startlevel = 0; 
00492     changed = 1; 
00493     while (changed)  
00494     { 
00495         nr_bary_iterations++; 
00496         if (nr_bary_iterations >= max_baryiterations)  
00497         { 
00498             gs_wait_message ('t'); 
00499             break; 
00500         } 
00501         if (G_timelimit > 0) if (test_timelimit (60))  
00502         { 
00503             gs_wait_message ('t'); 
00504             break; 
00505         } 
00506         changed = 0; 
00507         phase2_startlevel = tmp_startlevel; 
00508         phase2_down (); 
00509         tmp_startlevel = phase2_startlevel; 
00510         
00511         if (tmp_startlevel > maxdepth) tmp_startlevel = 0; 
00512         cross = graph_crossings (); 
00513         alt = 0; 
00514         
00515         if (cross < nr_crossings)  
00516         { 
00517             changed = 1; 
00518             copy_layers (layer, tmp_layer); 
00519             nr_crossings = cross; 
00520             alt_startlevel = tmp_startlevel; 
00521         } 
00522         else if (have_alternative)  
00523         { 
00524             copy_layers (tmp_layer, layer); 
00525             phase2_startlevel = tmp_startlevel = alt_startlevel; 
00526             phase2_down (); 
00527             tmp_startlevel = phase2_startlevel; 
00528             if (tmp_startlevel > maxdepth) tmp_startlevel = 0; 
00529             cross = graph_crossings (); 
00530             if (cross < nr_crossings)  
00531             { 
00532                 changed = 1; 
00533                 copy_layers (layer, tmp_layer); 
00534                 nr_crossings = cross; 
00535                 alt_startlevel = tmp_startlevel; 
00536             } 
00537             else if (cross > nr_crossings)  
00538             { 
00539                 copy_layers (tmp_layer, layer); 
00540                 tmp_startlevel = alt_startlevel; 
00541             } 
00542             else alt = 1; 
00543         } else if (cross == nr_crossings) alt = 1; 
00544         else  
00545         {          
00546             copy_layers (tmp_layer, layer);         
00547             tmp_startlevel = alt_startlevel; 
00548         } 
00549         have_alternative = alt; 
00550         
00551         if (nr_crossings == 0) 
00552             return;     
00553     } 
00554 
00555     tmp_startlevel = alt_startlevel = maxdepth + 1; 
00556     changed = 1; 
00557     while (changed)  
00558     { 
00559         nr_bary_iterations++; 
00560         if (nr_bary_iterations >= max_baryiterations)  
00561         { 
00562             gs_wait_message ('t'); 
00563             break; 
00564         } if (G_timelimit > 0) if (test_timelimit (60))  
00565         { 
00566             gs_wait_message ('t'); 
00567             break; 
00568         } changed = 0; 
00569         phase2_startlevel = tmp_startlevel; 
00570         phase2_up (); 
00571         tmp_startlevel = phase2_startlevel; 
00572         if (tmp_startlevel < 0) tmp_startlevel = maxdepth; 
00573         cross = graph_crossings (); 
00574         alt = 0; 
00575         if (cross < nr_crossings)  
00576         { 
00577             changed = 1; 
00578             copy_layers (layer, tmp_layer); 
00579             nr_crossings = cross; 
00580             alt_startlevel = tmp_startlevel; 
00581         } else if (have_alternative)    { 
00582 
00583             copy_layers (tmp_layer, layer); 
00584             phase2_startlevel = tmp_startlevel = alt_startlevel; 
00585             phase2_up (); 
00586             tmp_startlevel = phase2_startlevel; 
00587             if (tmp_startlevel < 0) tmp_startlevel = maxdepth; 
00588             cross = graph_crossings (); 
00589             if (cross < nr_crossings)  
00590             { 
00591                 changed = 1; 
00592                 copy_layers (layer, tmp_layer); 
00593                 nr_crossings = cross; 
00594                 alt_startlevel = tmp_startlevel; 
00595             } 
00596             else if (cross > nr_crossings)  
00597             { 
00598                 copy_layers (tmp_layer, layer); 
00599                 tmp_startlevel = alt_startlevel; 
00600             } 
00601             else 
00602                 alt = 1; 
00603         } else if (cross == nr_crossings) alt = 1; 
00604         else  
00605         { 
00606             copy_layers (tmp_layer, layer); 
00607             tmp_startlevel = alt_startlevel; 
00608         } 
00609         have_alternative = alt; 
00610         if (nr_crossings == 0) 
00611             return; 
00612     }
00613 }

STATIC int compare_bary const GNODE a,
const GNODE b
 

Definition at line 7 of file bary_functions.c.

References GNODE.

00008 { 
00009     if ((((*a)->bary) == 0.0) || (((*b)->bary) == 0.0)) return (0); 
00010     if (((*a)->bary) > ((*b)->bary)) return (1); 
00011     if (((*a)->bary) < ((*b)->bary)) return (-1); 
00012     return (0);
00013 }

void copy_layers DEPTH l1,
DEPTH l2
[static]
 

Definition at line 326 of file bary_functions.c.

References DEPTH, GNLIST, maxdepth, and tmpnodelist_alloc().

Referenced by barycentering(), tree_horizontal_order(), and unmerge_connected_parts().

00327 { 
00328     int i; 
00329     GNLIST h1, h2; 
00330     for (i = 0; i <= maxdepth + 1; i++) 
00331     { 
00332         ((l1[i]).cross) = ((l2[i]).cross); 
00333         h1 = ((l1[i]).succlist); 
00334         h2 = ((l2[i]).succlist); 
00335         if (((l1[i]).anz) == ((l2[i]).anz)) 
00336         { 
00337             while (h2) { 
00338                 ((h1)->node) = ((h2)->node); 
00339                 h1 = ((h1)->next); 
00340                 h2 = ((h2)->next); 
00341             } 
00342         } 
00343         else 
00344         { 
00345             while (h2) { 
00346                 ((h1)->node) = ((h2)->node); 
00347                 h2 = ((h2)->next); 
00348                 if (h2 && !((h1)->next)) 
00349                     ((h1)->next) = tmpnodelist_alloc (); 
00350                 h1 = ((h1)->next); 
00351             } 
00352             ((l1[i]).anz) = ((l2[i]).anz); 
00353         } 
00354     }
00355 }

STATIC int cycle_sort_array int  siz  ) 
 

Definition at line 126 of file bary_functions.c.

References GNODE, sort_array, and STATIC.

Referenced by phase2_down(), and phase2_up().

00127 { 
00128     int j, k; 
00129     int original_sit; 
00130     int start_region; 
00131     GNODE h; 
00132     original_sit = 1; // is there no change?
00133     start_region = -1;  // is there a run
00134     for (j = 0; j < siz - 1; j++) { 
00135 
00136         // is there a run in the array?
00137         if (((sort_array[j])->bary) == ((sort_array[j + 1])->bary)) { 
00138 
00139             // set the start region to be the beginning of the run
00140             if (start_region == -1) 
00141                 start_region = j; 
00142         } 
00143         else if (start_region != -1) // there is a run already?
00144         { 
00145             // void runsort(j,start_region,original_sit) 
00146             h = sort_array[j]; 
00147 
00148             //k=j .down.to..> start region
00149             for (k = j; k > start_region; k--) 
00150                 sort_array[k] = sort_array[k - 1]; 
00151 
00152             sort_array[start_region] = h; // the beginning of the start region
00153         
00154             // set the flag
00155             start_region = -1; 
00156             original_sit = 0; 
00157 
00158         } 
00159     } 
00160 
00161     if (start_region != -1) 
00162     { 
00163         // void runsort(j,start_region,original_sit) 
00164         h = sort_array[j]; 
00165         for (k = j; k > start_region; k--) 
00166             sort_array[k] = sort_array[k - 1]; 
00167         sort_array[start_region] = h; 
00168         original_sit = 0; 
00169     } 
00170 
00171     return (!original_sit);
00172 }

STATIC void init_barycentering void   ) 
 

Definition at line 378 of file bary_functions.c.

References have_alternative, phase1_allowed, and STATIC.

Referenced by main().

00378                                       { 
00379     have_alternative = 0; 
00380     phase1_allowed = 1;
00381 }

STATIC void mark_all_nodes GNODE  node,
int  i
 

Definition at line 80 of file bary_functions.c.

References ADJEDGE, GNODE, max_horder_num, and STATIC.

Referenced by unmerge_connected_parts().

00081 {
00082     ADJEDGE e;
00083     if (((node)->bary)) return; 
00084     if (((node)->nhorder) >= 0)
00085         ((node)->bary) = (float) i *(float) (max_horder_num + 1) + (float) ((node)->nhorder); 
00086     else 
00087         ((node)->bary) = (float) i *(float) (max_horder_num + 1); 
00088     e = ((node)->succ); 
00089     while (e) { 
00090         mark_all_nodes ((((((e)->kante))->end)), i); 
00091         e = ((e)->next); 
00092     } 
00093 
00094     e = ((node)->pred); 
00095     while (e) { 
00096         mark_all_nodes ((((((e)->kante))->start)), i); 
00097         e = ((e)->next); 
00098     }
00099 
00100 }

STATIC void phase1_down void   ) 
 

Definition at line 102 of file bary_functions.c.

References gs_wait_message(), maxdepth, resort_down_layer(), and STATIC.

Referenced by barycentering().

00102                               { 
00103     int i;
00104     gs_wait_message ('b'); 
00105     for (i = 0; i <= maxdepth; i++) 
00106         (void) resort_down_layer (i);
00107 }

STATIC void phase1_up void   ) 
 

Definition at line 109 of file bary_functions.c.

References gs_wait_message(), maxdepth, resort_up_layer(), and STATIC.

Referenced by barycentering().

00109                             { 
00110     int i;
00111     gs_wait_message ('b'); 
00112     for (i = maxdepth; i >= 0; i--)
00113         (void) resort_up_layer (i);
00114 }

STATIC void resort_down_up_layer int  level  ) 
 

Definition at line 28 of file bary_functions.c.

References maxdepth, resort_down_layer(), resort_up_layer(), and STATIC.

Referenced by phase2_up().

00029 { int change; int i; change = 1;
00030  if (level <= maxdepth) { for (i = level; i <= maxdepth; i++) { // INDEX1
00031      change = resort_down_layer (i); // branch down
00032      if (!change) break; } }
00033  if (level > 0) { for (i = level - 1; i >= 0; i--) {// INDEX2
00034      change = resort_up_layer (i); // brach up
00035      if (!change) break; } }
00036 }

STATIC void resort_up_down_layer int  level  ) 
 

Definition at line 19 of file bary_functions.c.

References maxdepth, resort_down_layer(), resort_up_layer(), and STATIC.

Referenced by phase2_down().

00020 { int change; int i; change = 1;
00021  if (level > 0) { for (i = level - 1; i >= 0; i--) {// INDEX2
00022      change = resort_up_layer (i); // branch up
00023      if (!change) break; } }
00024  if (level <= maxdepth) { for (i = level; i <= maxdepth; i++) {// INDEX1
00025      change = resort_down_layer (i); // branch down
00026      if (!change) break; } }}

STATIC void restore_level int  i  ) 
 

Definition at line 367 of file bary_functions.c.

References GNLIST, save_array, STATIC, and tmp_layer.

Referenced by resort_down_layer(), and resort_up_layer().

00367                                  {
00368     int j; GNLIST hn; ; j = 0; 
00369     hn = ((tmp_layer[i]).succlist); 
00370     while (hn) { 
00371         ((hn)->node) = save_array[j++]; 
00372         hn = ((hn)->next); 
00373     }
00374 }

STATIC void save_level int  i  ) 
 

Definition at line 358 of file bary_functions.c.

References GNLIST, save_array, STATIC, and tmp_layer.

Referenced by resort_down_layer(), and resort_up_layer().

00358                               { 
00359     int j; GNLIST hn; ; j = 0; 
00360     hn = ((tmp_layer[i]).succlist); 
00361     while (hn) { 
00362         save_array[j++] = ((hn)->node); 
00363         hn = ((hn)->next); 
00364     } 
00365 }

STATIC void tree_horizontal_order void   ) 
 

Definition at line 182 of file bary_functions.c.

References ADJEDGE, array_to_level(), compare_bary(), copy_layers(), GEDGE, GNLIST, GNODE, adjedge::kante, layer, level_to_array(), max_eprio, maxdepth, gnlist::next, adjedge::next, gnlist::node, predbary(), sort_array, STATIC, gnode::succ, tmp_layer, and gedge::weights.

00183 { 
00184     GNLIST li; 
00185     int i, prio; 
00186     GNODE node; 
00187     ADJEDGE a; 
00188     GEDGE e; 
00189     double maxbary;
00190 
00191     //  init each layer, following the succ list , setting the weights to 0
00192     for (i = 0; i <= maxdepth + 1; i++){  
00193         // for each successor in the list 1
00194         li = ((tmp_layer[i]).succlist);  // for each layer
00195         while (li){ 
00196             a = li->node->succ;
00197             while (a){ a->kante->weights=0;a = a->next; }  // follow the next in the succ list of the node
00198             li = li->next; 
00199         } // follow the next in the succ list of the layer
00200     }
00201 
00202 // for each depth, and in the order of priority,
00203 // visit each node in the graph
00204 // get each edge, and the end of the edge,
00205 // mark the node if not marked, and the set the weight edge to 1
00206 
00207     for (i = 0; i <= maxdepth + 1; i++) { 
00208         for (prio = max_eprio; prio >= 0; prio--) {  // for each prio
00209         // for each successor in the list 2
00210             li = ((tmp_layer[i]).succlist);  // start to follow the succ list
00211             while (li) { 
00212                 a = ((((li)->node))->succ); // follow the node succ list
00213                 while (a) { 
00214                     e = ((a)->kante); 
00215                     if (((e)->priority) == prio) { // check the priority
00216                         node = (((((a)->kante))->end));  // get the end node
00217                         if (!((node)->markiert)) { 
00218                             ((node)->markiert) = 1;  // mark the node
00219                             ((e)->weights) = 1; // set the weights to 1
00220                         } 
00221                     } 
00222                     a = ((a)->next); 
00223                 } 
00224                 li = ((li)->next); 
00225             }
00226         }
00227     }
00228  
00229     // second passs
00230     for (i = 1; i <= maxdepth + 1; i++) { 
00231         level_to_array (i, 'd');  // convers the level to an array
00232         maxbary = 0.1; 
00233 
00234         // for each successor in the list 3
00235         li = ((tmp_layer[i]).succlist); 
00236         while (li) { 
00237             node = ((li)->node); 
00238             ((node)->bary) = predbary (node);  // calc the predbary
00239             if (((node)->bary) > maxbary) maxbary = ((node)->bary); // calc the maxbary 
00240             li = ((li)->next); 
00241         }
00242 
00243         maxbary = maxbary + 1.0; 
00244 
00245         // for each successor in the list 4
00246         li = ((tmp_layer[i - 1]).succlist); 
00247         while (li) { 
00248             a = ((((li)->node))->succ); 
00249             while (a) { 
00250                 e = ((a)->kante); 
00251                 if (((e)->weights)) { // marked by this algorithm
00252                     node = (((((a)->kante))->end)); 
00253                     ((node)->bary) = (double) (((((li)->node))->position)) + ((node)->bary) / maxbary;  // scale the bary down by the max and the position
00254                 } 
00255                 a = ((a)->next); 
00256             } 
00257             li = ((li)->next); 
00258         } 
00259         
00260         
00261         if (((layer[i]).anz)) 
00262             qsort (sort_array, ((layer[i]).anz), sizeof (GNODE), (int (*)(const void *, const void *)) compare_bary); 
00263     } 
00264     array_to_level (i); 
00265     
00266     // set the marking to 0
00267     for (i = 0; i <= maxdepth + 1; i++) 
00268     { 
00269         li = ((tmp_layer[i]).succlist); 
00270         while (li) { 
00271             ((((li)->node))->markiert) = 0; li = ((li)->next); 
00272         } 
00273     } 
00274 
00275     // copy the layers from tmp to main
00276     copy_layers (layer, tmp_layer);
00277 }

STATIC void unmerge_connected_parts void   ) 
 

Definition at line 279 of file bary_functions.c.

References array_to_level(), compare_bary(), copy_layers(), GNLIST, GNODE, gs_wait_message(), layer, mark_all_nodes(), maxdepth, sort_array, STATIC, and tmp_layer.

00279                                           { 
00280     GNLIST li; 
00281     int i, j; 
00282     int part_is_missing; 
00283     GNODE node; int act_graph;
00284 
00285 
00286     // set bary to 0
00287     for (i = 0; i <= maxdepth + 1; i++) { 
00288         li = ((tmp_layer[i]).succlist); 
00289         while (li) { 
00290             ((((li)->node))->bary) = 0; li = ((li)->next); 
00291         } 
00292     } 
00293     act_graph = 1; 
00294     part_is_missing = 1; 
00295     while (part_is_missing) { 
00296         gs_wait_message ('u'); part_is_missing = 0; node = (GNODE) 0; act_graph++; 
00297         for (i = 0; i <= maxdepth + 1; i++) { 
00298             li = ((layer[i]).succlist); 
00299             while (li) { 
00300                 if (((((li)->node))->bary) == 0) { 
00301                     node = ((li)->node); break; 
00302                 } 
00303                 li = ((li)->next); 
00304             } 
00305             if (node) break; 
00306         } 
00307         if (node) { 
00308             part_is_missing = 1; mark_all_nodes (node, act_graph); 
00309         } 
00310     } 
00311     for (i = 0; i <= maxdepth + 1; i++) { 
00312         li = ((tmp_layer[i]).succlist); j = 0; 
00313         while (li) { 
00314             sort_array[j++] = ((li)->node); li = ((li)->next); 
00315         } 
00316         
00317         if (((layer[i]).anz)) qsort (sort_array, ((layer[i]).anz), sizeof (GNODE), (int (*)(const void *, const void *)) compare_bary); 
00318         array_to_level (i); 
00319     } 
00320     copy_layers (layer, tmp_layer);
00321 }


Variable Documentation

STATIC int have_alternative
 

Definition at line 376 of file bary_functions.c.

Referenced by barycentering(), and init_barycentering().

int mark_all_nodes_merger
 

Definition at line 323 of file bary_functions.c.

STATIC int phase1_allowed
 

Definition at line 377 of file bary_functions.c.

Referenced by barycentering(), and init_barycentering().


Generated on Sat Aug 6 11:49:19 2005 for VCGIntrospector by doxygen 1.3.6