Open
Graph Drawing
Framework

 v.2012.05
 

FMMMLayout.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046  
00047 #ifndef OGDF_FMMMLAYOUT_H
00048 #define OGDF_FMMMLAYOUT_H
00049 
00050 #include <ogdf/basic/Graph.h>
00051 #include <ogdf/cluster/ClusterGraphAttributes.h>
00052 #include <ogdf/module/LayoutModule.h>
00053 #include <ogdf/basic/geometry.h>
00054 #include <ogdf/internal/energybased/FruchtermanReingold.h>
00055 #include <ogdf/internal/energybased/NMM.h>
00056 
00057   
00058 namespace ogdf {
00059 
00060     class OGDF_EXPORT Rectangle;
00061 
00249 class OGDF_EXPORT FMMMLayout : public LayoutModule
00250 {
00251 public:
00253     enum PageFormatType {
00254         pfPortrait,  
00255         pfLandscape, 
00256         pfSquare     
00257     };
00258 
00260     enum QualityVsSpeed { 
00261         qvsGorgeousAndEfficient,  
00262         qvsBeautifulAndFast,      
00263         qvsNiceAndIncredibleSpeed 
00264     };
00265 
00267     enum EdgeLengthMeasurement { 
00268         elmMidpoint,      
00269         elmBoundingCircle 
00270     };
00271 
00273     enum AllowedPositions { 
00274         apAll, 
00275         apInteger, 
00276         apExponent 
00277     };
00278 
00280     enum TipOver { 
00281         toNone, 
00282         toNoGrowingRow, 
00283         toAlways 
00284     };
00285 
00287     enum PreSort { 
00288         psNone, 
00289         psDecreasingHeight, 
00290         psDecreasingWidth   
00291     };
00292 
00294     enum GalaxyChoice { 
00295         gcUniformProb, 
00296         gcNonUniformProbLowerMass, 
00297         gcNonUniformProbHigherMass 
00298     };
00299 
00301     enum MaxIterChange { 
00302         micConstant, 
00303         micLinearlyDecreasing, 
00304         micRapidlyDecreasing 
00305     };
00306 
00308     enum InitialPlacementMult { 
00309         ipmSimple, 
00310         ipmAdvanced 
00311     };
00312 
00314     enum ForceModel { 
00315         fmFruchtermanReingold, 
00316         fmEades,               
00317         fmNew                  
00318     };
00319 
00321     enum RepulsiveForcesMethod { 
00322         rfcExact,             
00323         rfcGridApproximation, 
00324         rfcNMM                
00325     };
00326 
00328     enum StopCriterion { 
00329         scFixedIterations,           
00330         scThreshold,                 
00331         scFixedIterationsOrThreshold 
00332     };
00333 
00335     enum InitialPlacementForces { 
00336         ipfUniformGrid,      
00337         ipfRandomTime,       
00338         ipfRandomRandIterNr, 
00339         ipfKeepPositions     
00340     };
00341 
00343     enum ReducedTreeConstruction { 
00344         rtcPathByPath,      
00345         rtcSubtreeBySubtree 
00346     };
00347 
00349     enum SmallestCellFinding { 
00350         scfIteratively, 
00351         scfAluru        
00352     };
00353   
00354 
00356     FMMMLayout();
00357  
00358     // destructor
00359     virtual ~FMMMLayout() { }
00360  
00361  
00367 
00368     void call(GraphAttributes &GA);
00369  
00373         void call(ClusterGraphAttributes &GA);
00374 
00376 
00380     void call(GraphAttributes &GA,   //graph and layout
00381         const EdgeArray<double> &edgeLength); //factor for desired edge lengths 
00382 
00384 
00388     void call(GraphAttributes &AG, char* ps_file);
00389  
00391 
00397     void call(GraphAttributes &AG,   //graph and layout
00398         const EdgeArray<double> &edgeLength, //factor for desired edge lengths
00399         char* ps_file); 
00400 
00406 
00407     double getCpuTime();
00408 
00409 
00416 
00417 
00422     bool useHighLevelOptions() const { return m_useHighLevelOptions; }
00423 
00425     void useHighLevelOptions(bool uho) { m_useHighLevelOptions = uho; } 
00426 
00428 
00434     PageFormatType pageFormat() const { return m_pageFormat; }
00435 
00437     void pageFormat(PageFormatType t) { m_pageFormat = t; }
00438  
00440     double unitEdgeLength() const { return m_unitEdgeLength; }
00441 
00443     void unitEdgeLength(double x) {m_unitEdgeLength = (( x > 0.0) ? x : 1);}
00444 
00446 
00451     bool newInitialPlacement() const { return m_newInitialPlacement; }
00452 
00454     void newInitialPlacement(bool nip) { m_newInitialPlacement = nip; }
00455   
00457 
00463     QualityVsSpeed qualityVersusSpeed() const { return m_qualityVersusSpeed; }
00464 
00466     void qualityVersusSpeed(QualityVsSpeed qvs) {m_qualityVersusSpeed = qvs; }
00467         
00468 
00476 
00477     void randSeed(int p) { m_randSeed = ((0<=p) ? p : 1);}
00478 
00480     int randSeed() const {return m_randSeed;}
00481          
00483 
00490     EdgeLengthMeasurement edgeLengthMeasurement() const {
00491         return m_edgeLengthMeasurement;
00492     }
00493 
00495     void edgeLengthMeasurement(EdgeLengthMeasurement elm) { m_edgeLengthMeasurement = 
00496                                    elm; }
00497  
00499 
00508     AllowedPositions allowedPositions() const { return m_allowedPositions; }
00509 
00511     void allowedPositions(AllowedPositions ap) { m_allowedPositions = ap; }
00512  
00514 
00517     int maxIntPosExponent() const { return m_maxIntPosExponent; }
00518 
00520     void maxIntPosExponent(int e) {
00521         m_maxIntPosExponent = (((e >= 31)&&(e<=51))? e : 31);
00522     }
00523 
00524 
00530 
00531 
00534     double pageRatio() const { return m_pageRatio; }
00535 
00537     void pageRatio(double r) {m_pageRatio = (( r > 0) ? r : 1);}
00538  
00540 
00544     int stepsForRotatingComponents() const { return m_stepsForRotatingComponents; }
00545 
00547     void stepsForRotatingComponents(int n) {
00548         m_stepsForRotatingComponents = ((0<=n) ? n : 0);
00549     }
00550  
00552 
00559     TipOver tipOverCCs() const { return m_tipOverCCs; }
00560 
00562     void tipOverCCs(TipOver to) { m_tipOverCCs = to; }
00563  
00565     double minDistCC() const { return m_minDistCC; }
00566 
00568     void minDistCC(double x) { m_minDistCC = (( x > 0) ? x : 1);}
00569   
00571 
00579     PreSort presortCCs() const { return m_presortCCs; }
00580 
00582     void presortCCs(PreSort ps) { m_presortCCs = ps; }
00583  
00584     
00590 
00591 
00596     int minGraphSize() const { return m_minGraphSize; }
00597 
00599     void minGraphSize(int n) { m_minGraphSize = ((n >= 2)? n : 2);}
00600  
00602 
00610     GalaxyChoice galaxyChoice() const { return m_galaxyChoice; }
00611 
00613     void galaxyChoice(GalaxyChoice gc) { m_galaxyChoice = gc; }
00614  
00616 
00621     int randomTries() const { return m_randomTries; }
00622 
00624     void randomTries(int n) {m_randomTries = ((n>=1)? n: 1);}
00625  
00627 
00636     MaxIterChange maxIterChange() const { return m_maxIterChange; }
00637 
00639     void maxIterChange(MaxIterChange mic) { m_maxIterChange = mic; }
00640  
00642 
00647     int maxIterFactor() const { return m_maxIterFactor; }
00648 
00650     void maxIterFactor(int f) { m_maxIterFactor = ((f>=1) ? f : 1 );}   
00651  
00653 
00660     InitialPlacementMult initialPlacementMult() const {
00661         return m_initialPlacementMult;
00662     }
00663     
00665     void initialPlacementMult(InitialPlacementMult ipm) { 
00666       m_initialPlacementMult = ipm; 
00667     }
00668 
00669 
00675 
00676 
00682     ForceModel forceModel() const { return m_forceModel; }
00683 
00685     void forceModel(ForceModel fm) { m_forceModel = fm; }
00686  
00688     double springStrength() const { return m_springStrength; }
00689 
00691     void springStrength(double x) { m_springStrength  = ((x > 0)? x : 1);}
00692  
00694     double repForcesStrength() const { return m_repForcesStrength; }
00695 
00697     void repForcesStrength(double x) { m_repForcesStrength =((x > 0)? x : 1);}
00698           
00700 
00707     RepulsiveForcesMethod repulsiveForcesCalculation() const {
00708         return m_repulsiveForcesCalculation;
00709     }
00710 
00712     void repulsiveForcesCalculation(RepulsiveForcesMethod rfc) {
00713         m_repulsiveForcesCalculation = rfc;
00714     }
00715  
00717 
00724     StopCriterion stopCriterion() const { return m_stopCriterion; }
00725 
00727     void stopCriterion(StopCriterion rsc) { m_stopCriterion = rsc; }
00728  
00730 
00734     double threshold() const { return m_threshold; }
00735 
00737     void threshold(double x) {m_threshold = ((x > 0) ? x : 0.1);}
00738        
00740     int fixedIterations() const { return m_fixedIterations; }
00741 
00743     void fixedIterations(int n) { m_fixedIterations = ((n >= 1) ? n : 1);}
00744          
00746     double forceScalingFactor() const { return m_forceScalingFactor; }
00747 
00749     void forceScalingFactor(double f) { m_forceScalingFactor = ((f > 0) ? f : 1);}
00750         
00752 
00756     bool coolTemperature() const { return m_coolTemperature; }
00757 
00759     void coolTemperature(bool b) { m_coolTemperature = b; }
00760  
00762 
00766     double coolValue() const { return m_coolValue; }
00767 
00769     void coolValue(double x) { m_coolValue = (((x >0 )&&(x<=1) )? x : 0.99);}
00770  
00771  
00773 
00781     InitialPlacementForces initialPlacementForces() const {
00782         return m_initialPlacementForces;
00783     }
00784 
00786     void initialPlacementForces(InitialPlacementForces ipf) { 
00787       m_initialPlacementForces = ipf;
00788     }
00789   
00790     
00796 
00797 
00801     bool resizeDrawing() const { return m_resizeDrawing; }
00802 
00804     void resizeDrawing(bool b) { m_resizeDrawing = b; }
00805  
00807 
00811     double resizingScalar() const { return m_resizingScalar; }
00812 
00814     void resizingScalar(double s) { m_resizingScalar = ((s > 0) ? s : 1);}
00815  
00817     int fineTuningIterations() const { return m_fineTuningIterations; }
00818 
00820     void fineTuningIterations(int n) { m_fineTuningIterations =((n >= 0) ? n : 0);}
00821  
00823 
00827     double fineTuneScalar() const { return m_fineTuneScalar; }
00828 
00830     void fineTuneScalar(double s) { m_fineTuneScalar = ((s >= 0) ? s : 1);}
00831 
00833 
00838     bool adjustPostRepStrengthDynamically() const {
00839         return m_adjustPostRepStrengthDynamically; 
00840     }
00841 
00843     void adjustPostRepStrengthDynamically(bool b) {
00844         m_adjustPostRepStrengthDynamically = b;
00845     }
00846 
00848     double postSpringStrength() const { return m_postSpringStrength; }
00849 
00851     void postSpringStrength(double x) { m_postSpringStrength  = ((x > 0)? x : 1);}
00852  
00854     double postStrengthOfRepForces() const { return m_postStrengthOfRepForces; }
00855 
00857     void postStrengthOfRepForces(double x) {
00858         m_postStrengthOfRepForces = ((x > 0)? x : 1);
00859     }
00860 
00861     
00867 
00868 
00872     int  frGridQuotient() const {return m_frGridQuotient;}
00873 
00875     void frGridQuotient(int p) { m_frGridQuotient = ((0<=p) ? p : 2);}
00876 
00878 
00884     ReducedTreeConstruction nmTreeConstruction() const { return m_NMTreeConstruction; }
00885 
00887     void nmTreeConstruction(ReducedTreeConstruction rtc) { m_NMTreeConstruction = rtc; }
00888  
00890 
00897     SmallestCellFinding nmSmallCell() const { return m_NMSmallCell; }
00898 
00900     void nmSmallCell(SmallestCellFinding scf) { m_NMSmallCell = scf; }
00901   
00903 
00907     int nmParticlesInLeaves() const { return m_NMParticlesInLeaves; }
00908 
00910     void nmParticlesInLeaves(int n) { m_NMParticlesInLeaves = ((n>= 1)? n : 1);}
00911        
00913     int nmPrecision() const { return m_NMPrecision; }
00914 
00916     void nmPrecision(int p) { m_NMPrecision  = ((p >= 1 ) ? p : 1);}
00917 
00919 
00920 private:
00921       
00922     //high level options
00923     bool                  m_useHighLevelOptions; 
00924     PageFormatType        m_pageFormat; 
00925     double                m_unitEdgeLength; 
00926     bool                  m_newInitialPlacement; 
00927     QualityVsSpeed        m_qualityVersusSpeed; 
00928 
00929     //low level options
00930     //general options
00931     int                   m_randSeed; 
00932     EdgeLengthMeasurement m_edgeLengthMeasurement; 
00933     AllowedPositions      m_allowedPositions; 
00934     int                   m_maxIntPosExponent; 
00935 
00936     //options for divide et impera step
00937     double                m_pageRatio; 
00938     int                   m_stepsForRotatingComponents; 
00939     TipOver               m_tipOverCCs; 
00940     double                m_minDistCC; 
00941     PreSort               m_presortCCs; 
00942 
00943     //options for multilevel step
00944     int                   m_minGraphSize; 
00945     GalaxyChoice          m_galaxyChoice; 
00946     int                   m_randomTries; 
00947     MaxIterChange         m_maxIterChange; 
00948 
00949 
00950 
00951     int                   m_maxIterFactor; 
00952     InitialPlacementMult m_initialPlacementMult; 
00953 
00954     //options for force calculation step
00955     ForceModel            m_forceModel; 
00956     double                m_springStrength; 
00957     double                m_repForcesStrength; 
00958     RepulsiveForcesMethod m_repulsiveForcesCalculation; 
00959     StopCriterion         m_stopCriterion; 
00960     double                m_threshold; 
00961     int                   m_fixedIterations; 
00962     double                m_forceScalingFactor; 
00963     bool                  m_coolTemperature; 
00964     double                m_coolValue; 
00965     InitialPlacementForces m_initialPlacementForces; 
00966 
00967     //options for postprocessing step
00968     bool                  m_resizeDrawing; 
00969     double                m_resizingScalar; 
00970     int                   m_fineTuningIterations; 
00971     double                m_fineTuneScalar; 
00972     bool                  m_adjustPostRepStrengthDynamically; 
00973     double                m_postSpringStrength; 
00974     double                m_postStrengthOfRepForces; 
00975 
00976     //options for repulsive force approximation methods
00977     int                   m_frGridQuotient; 
00978     ReducedTreeConstruction m_NMTreeConstruction; 
00979     SmallestCellFinding   m_NMSmallCell; 
00980     int                   m_NMParticlesInLeaves; 
00981     int                   m_NMPrecision; 
00982 
00983     //other variables
00984     double max_integer_position; 
00985     double cool_factor; 
00986     double average_ideal_edgelength; 
00987     double boxlength; 
00988     int number_of_components; 
00989     DPoint down_left_corner; 
00990     NodeArray<double> radius; 
00991     double time_total; 
00992 
00993     FruchtermanReingold FR; 
00994     NMM NM; 
00995 
00996 
00997     //------------------- most important functions ----------------------------
00998 
01000     void call_DIVIDE_ET_IMPERA_step (Graph& G,NodeArray<NodeAttributes>& A,
01001                    EdgeArray<EdgeAttributes>& E);
01002       
01004     void call_MULTILEVEL_step_for_subGraph (Graph& G,NodeArray<NodeAttributes>
01005                       & A,EdgeArray<EdgeAttributes>& E, int
01006                       comp_index);
01007 
01009 
01014     void call_FORCE_CALCULATION_step (Graph& G,NodeArray<NodeAttributes>& A,
01015                 EdgeArray<EdgeAttributes>& E,int act_level,
01016                 int max_level);
01017 
01019     void call_POSTPROCESSING_step(Graph& G, NodeArray<NodeAttributes>& A,EdgeArray
01020                 <EdgeAttributes>& E,NodeArray<DPoint>& F,NodeArray
01021                 <DPoint>& F_attr, NodeArray<DPoint>& F_rep,
01022                 NodeArray<DPoint>& last_node_movement);
01023 
01024 
01025     //---------------- functions for pre/pos-processing -----------------------------
01026 
01028     void initialize_all_options();
01029 
01031     void update_low_level_options_due_to_high_level_options_settings();
01032 
01034     void import_NodeAttributes(
01035         const Graph& G, 
01036         GraphAttributes& GA, 
01037         NodeArray<NodeAttributes>& A);
01038 
01040     void import_EdgeAttributes (
01041         const Graph& G, 
01042         const EdgeArray<double>& edgeLength, 
01043         EdgeArray <EdgeAttributes>& E);
01044 
01046     void init_ind_ideal_edgelength(
01047         const Graph& G,
01048         NodeArray<NodeAttributes>&A, 
01049         EdgeArray <EdgeAttributes>& E);
01050 
01052     void set_radii(const Graph& G,NodeArray<NodeAttributes>& A);
01053 
01055     void export_NodeAttributes(
01056         Graph& G_reduced, 
01057         NodeArray<NodeAttributes>& A_reduced,
01058         GraphAttributes& GA);
01059 
01061 
01066     void make_simple_loopfree(
01067         const Graph& G,
01068         NodeArray<NodeAttributes>& A, 
01069         EdgeArray<EdgeAttributes>E, 
01070         Graph& G_reduced,
01071         NodeArray<NodeAttributes>& A_reduced,
01072         EdgeArray<EdgeAttributes>& E_reduced);
01073 
01075 
01079     void delete_parallel_edges(
01080         const Graph& G,
01081         EdgeArray<EdgeAttributes>& E,
01082         Graph& G_reduced,
01083         List<edge>& S,
01084         EdgeArray<double>& new_edgelength);
01085 
01087 
01090     void update_edgelength(
01091         List<edge>& S,
01092         EdgeArray <double>& new_edgelength,
01093         EdgeArray<EdgeAttributes>& E_reduced);
01094 
01096 
01099     double get_post_rep_force_strength(int n);
01100 
01102 
01107     void make_positions_integer(Graph& G, NodeArray<NodeAttributes>& A);
01108 
01110     void create_postscript_drawing(GraphAttributes& AG, char* ps_file);
01111 
01112 
01113     //------------------ functions for divide et impera step -----------------------
01114 
01116 
01120     void create_maximum_connected_subGraphs(
01121         Graph& G,
01122         NodeArray<NodeAttributes>&A, 
01123         EdgeArray<EdgeAttributes>&E,
01124         Graph G_sub[],
01125         NodeArray<NodeAttributes> A_sub[],
01126         EdgeArray<EdgeAttributes> E_sub[],
01127         NodeArray<int>& component);
01128 
01130 
01134     void pack_subGraph_drawings(
01135         NodeArray<NodeAttributes>& A,
01136         Graph G_sub[],
01137         NodeArray<NodeAttributes> A_sub[]);
01138 
01140     void  calculate_bounding_rectangles_of_components(
01141         List<Rectangle>& R,
01142         Graph  G_sub[],
01143         NodeArray<NodeAttributes> A_sub[]);
01144 
01146     Rectangle calculate_bounding_rectangle(
01147         Graph& G,
01148         NodeArray<NodeAttributes>& A,
01149         int componenet_index);
01150 
01157     void rotate_components_and_calculate_bounding_rectangles(
01158         List<Rectangle>&R,
01159         Graph G_sub[],
01160         NodeArray<NodeAttributes> A_sub[]);
01161 
01166     double calculate_area(double width,double height,int comp_nr);
01167 
01174     void export_node_positions(
01175         NodeArray<NodeAttributes>& A,
01176         List<Rectangle>& R,
01177         Graph G_sub[],
01178         NodeArray<NodeAttributes> A_sub[]);
01179 
01181     void delete_all_subGraphs(
01182         Graph G_sub[],
01183         NodeArray<NodeAttributes> A_sub[],
01184         EdgeArray<EdgeAttributes> E_sub[]);
01185 
01186 
01187     //------------------  functions for multilevel step    --------------------------
01188 
01194     int get_max_mult_iter(int act_level, int max_level, int node_nr);
01195 
01196 
01197     //------------------  functions for force calculation ---------------------------
01198 
01200     void calculate_forces(
01201         Graph& G, 
01202         NodeArray<NodeAttributes>& A,
01203         EdgeArray<EdgeAttributes>& E,NodeArray<DPoint>& F,
01204         NodeArray<DPoint>& F_attr, 
01205         NodeArray<DPoint>& F_rep,
01206         NodeArray<DPoint>& last_node_movement,
01207         int iter,
01208         int fine_tuning_step);
01209 
01211     void init_boxlength_and_cornercoordinate(Graph& G,NodeArray<NodeAttributes>& A);
01212 
01214     void create_initial_placement (Graph& G,NodeArray<NodeAttributes>& A);
01215 
01217     void  init_F (Graph& G, NodeArray<DPoint>& F);
01218 
01219 
01221     void make_initialisations_for_rep_calc_classes(
01222         Graph& G/*,
01223         NodeArray<NodeAttributes> &A, 
01224         NodeArray<DPoint>& F_rep*/);
01225 
01227     void calculate_repulsive_forces(
01228         Graph &G,
01229         NodeArray<NodeAttributes>& A,
01230         NodeArray<DPoint>& F_rep);
01231 
01233     void deallocate_memory_for_rep_calc_classes();
01234 
01236     void calculate_attractive_forces(
01237         Graph& G,
01238         NodeArray<NodeAttributes> & A,
01239         EdgeArray<EdgeAttributes>& E, 
01240         NodeArray<DPoint>& F_attr);
01241 
01243     double f_attr_scalar (double d,double ind_ideal_edge_length);
01244 
01246     void add_attr_rep_forces(
01247         Graph& G,
01248         NodeArray<DPoint>& F_attr,
01249         NodeArray<DPoint>& F_rep,
01250         NodeArray<DPoint>& F,
01251         int iter,
01252         int fine_tuning_step);
01253 
01255     void move_nodes(Graph& G,NodeArray<NodeAttributes>& A,NodeArray<DPoint>& F);
01256 
01258 
01261     void update_boxlength_and_cornercoordinate(Graph& G,NodeArray<NodeAttributes>& A);
01262 
01264     double max_radius(int iter);
01265 
01267     void set_average_ideal_edgelength(Graph& G,EdgeArray<EdgeAttributes>& E);
01268 
01273     double get_average_forcevector_length (Graph& G, NodeArray<DPoint>& F);
01274 
01279     void prevent_oscilations(
01280         Graph& G, 
01281         NodeArray<DPoint>& F,
01282         NodeArray<DPoint>&
01283         last_node_movement,
01284         int iter);
01285 
01287     double angle(DPoint& P, DPoint& Q, DPoint& R);
01288 
01290     void init_last_node_movement(
01291         Graph& G, 
01292         NodeArray<DPoint>& F,
01293         NodeArray<DPoint>& last_node_movement);  
01294 
01299     void adapt_drawing_to_ideal_average_edgelength(
01300         Graph& G,
01301         NodeArray<NodeAttributes>& A,
01302         EdgeArray<EdgeAttributes>& E);
01303                       
01308     void restrict_force_to_comp_box(DPoint& force);
01309 
01310 
01311     //------------------- functions for analytic information -------------------------
01312 
01314     void init_time() { time_total = 0; }
01315 };
01316 
01317 } //end namespace ogdf 
01318 
01319 #endif
01320