Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

NewMultipoleMethod.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/List.h>
36 #include <ogdf/basic/Array2D.h>
37 #include <ogdf/basic/geometry.h>
41 #include <complex>
42 
43 namespace ogdf {
44 namespace energybased {
45 namespace fmmm {
46 
48 {
49 public:
52 
54  void calculate_repulsive_forces(const Graph &G,
56  NodeArray<DPoint>& F_rep);
57 
59  void make_initialisations (const Graph &G,
60  double boxlength,
61  DPoint down_left_corner,
62  int particles_in_leaves,
63  int precision,
64  FMMMOptions::ReducedTreeConstruction tree_construction_way,
65  FMMMOptions::SmallestCellFinding find_small_cell);
66 
68  void deallocate_memory();
69 
71  void update_boxlength_and_cornercoordinate(double b_l,DPoint d_l_c);
72 
73 private:
80  bool using_NMM;
82 
86  int _precision;
87 
88  double boxlength;
90 
92  double ** BK;
93 
97 
98  // private helping functions
99 
101  int power_of_two(int i);
102 
104  int maxboxindex (int level);
105 
107  void calculate_repulsive_forces_by_NMM(const Graph &G, NodeArray
108  <NodeAttributes>& A, NodeArray<DPoint>& F_rep);
109 
112  void calculate_repulsive_forces_by_exact_method(const Graph &G,
114  NodeArray<DPoint>& F_rep);
115 
117 
120  void build_up_red_quad_tree_path_by_path(const Graph& G,
122  QuadTreeNM& T);
123 
128  void make_copy_and_init_Lists(List<ParticleInfo>& L_x_orig,
129  List<ParticleInfo>& L_x_copy,
130  List<ParticleInfo>& L_y_orig,
131  List<ParticleInfo>& L_y_copy);
132 
134  void build_up_root_node(const Graph& G,NodeArray<NodeAttributes>& A, QuadTreeNM& T);
135 
137  void create_sorted_coordinate_Lists(const Graph& G,NodeArray<NodeAttributes>& A,
139 
143  void decompose_subtreenode(QuadTreeNM& T,
144  List<ParticleInfo>& act_x_List_copy,
145  List<ParticleInfo>& act_y_List_copy,
146  List<QuadTreeNodeNM*>& new_leaf_List);
147 
149  void calculate_boundaries_of_act_node(QuadTreeNodeNM* act_ptr,
150  double& x_min,
151  double& x_max,
152  double& y_min,
153  double& y_max);
154 
157  bool in_lt_quad(QuadTreeNodeNM* act_ptr, double x_min,double x_max, double y_min, double y_max);
158  bool in_rt_quad(QuadTreeNodeNM* act_ptr, double x_min,double x_max, double y_min, double y_max);
159  bool in_lb_quad(QuadTreeNodeNM* act_ptr, double x_min,double x_max, double y_min, double y_max);
160  bool in_rb_quad(QuadTreeNodeNM* act_ptr, double x_min,double x_max, double y_min, double y_max);
161  bool quadHelper(double x_min, double x_max, double y_min, double y_max, double l, double r, double b, double t, QuadTreeNodeNM* act_ptr);
162 
168  void split_in_x_direction(
169  QuadTreeNodeNM* act_ptr,
170  List<ParticleInfo>*& L_x_left_ptr,
171  List<ParticleInfo>*& L_y_left_ptr,
172  List<ParticleInfo>*& L_x_right_ptr,
173  List <ParticleInfo>*& L_y_right_ptr);
174 
177  void split_in_y_direction(
178  QuadTreeNodeNM* act_ptr,
179  List<ParticleInfo>*& L_x_bottom_ptr,
180  List<ParticleInfo>*& L_y_bottom_ptr,
181  List<ParticleInfo>*& L_x_top_ptr,
182  List<ParticleInfo>*& L_y_top_ptr);
183 
184 
190  void x_delete_right_subLists(
191  QuadTreeNodeNM* act_ptr,
192  List<ParticleInfo>*& L_x_left_ptr,
193  List <ParticleInfo>*& L_y_left_ptr,
194  List<ParticleInfo>*& L_x_right_ptr,
195  List <ParticleInfo>*& L_y_right_ptr,
196  ListIterator<ParticleInfo> last_left_item);
197 
199  void x_delete_left_subLists(
200  QuadTreeNodeNM* act_ptr,
201  List<ParticleInfo>*& L_x_left_ptr,
202  List <ParticleInfo>*& L_y_left_ptr,
203  List<ParticleInfo>*& L_x_right_ptr,
204  List <ParticleInfo>*& L_y_right_ptr,
205  ListIterator<ParticleInfo> last_left_item);
206 
210  void y_delete_right_subLists(
211  QuadTreeNodeNM* act_ptr,
212  List<ParticleInfo>*& L_x_left_ptr,
213  List<ParticleInfo>*& L_y_left_ptr,
214  List<ParticleInfo>*& L_x_right_ptr,
215  List <ParticleInfo>*& L_y_right_ptr,
216  ListIterator<ParticleInfo> last_left_item);
217 
219  void y_delete_left_subLists(
220  QuadTreeNodeNM* act_ptr,
221  List<ParticleInfo>*& L_x_left_ptr,
222  List<ParticleInfo>*& L_y_left_ptr,
223  List<ParticleInfo>*& L_x_right_ptr,
224  List <ParticleInfo>*& L_y_right_ptr,
225  ListIterator<ParticleInfo> last_left_item);
226 
227 
230  void split_in_y_direction(
231  QuadTreeNodeNM* act_ptr,
232  List<ParticleInfo>*& L_x_ptr,
233  List<ParticleInfo>*& L_x_b_ptr,
234  List<ParticleInfo>*& L_x_t_ptr,
235  List<ParticleInfo>*& L_y_ptr,
236  List<ParticleInfo>*& L_y_b_ptr,
237  List<ParticleInfo>*& L_y_t_ptr);
238 
243  void y_move_left_subLists(List<ParticleInfo>*& L_x_ptr,
244  List<ParticleInfo>*& L_x_b_ptr,
245  List<ParticleInfo>*& L_x_t_ptr,
246  List<ParticleInfo>*& L_y_ptr,
247  List <ParticleInfo>*& L_y_b_ptr,
248  List<ParticleInfo>*& L_y_t_ptr,
249  ListIterator<ParticleInfo> last_left_item);
250 
252  void y_move_right_subLists(List<ParticleInfo>*& L_x_ptr,
253  List<ParticleInfo>*& L_x_b_ptr,
254  List<ParticleInfo>*& L_x_t_ptr,
255  List<ParticleInfo>*&L_y_ptr,
256  List <ParticleInfo>*& L_y_b_ptr,
257  List<ParticleInfo>*& L_y_t_ptr,
258  ListIterator<ParticleInfo> last_left_item);
259 
262  void build_up_sorted_subLists(List<ParticleInfo>& L_x_copy,
263  List<ParticleInfo>& act_y_List_copy);
264 
268 
271  void build_up_red_quad_tree_subtree_by_subtree(const Graph& G,
273  QuadTreeNM& T);
274 
277  void build_up_root_vertex(const Graph&G, QuadTreeNM& T);
278 
284  void construct_subtree(NodeArray<NodeAttributes>& A,
285  QuadTreeNM& T,
286  QuadTreeNodeNM* subtree_root_ptr,
287  List<QuadTreeNodeNM*>& new_subtree_root_List);
288 
294  void construct_complete_subtree(QuadTreeNM& T,
295  int subtree_depth,
296  Array2D<QuadTreeNodeNM*>& leaf_ptr,
297  int act_depth,
298  int act_x_index,
299  int act_y_index);
300 
305  void set_contained_nodes_for_leaves(NodeArray<NodeAttributes>& A,
306  QuadTreeNodeNM* subtree_root_ptr,
307  Array2D<QuadTreeNodeNM*>& leaf_ptr,
308  int maxindex);
309 
312  void set_particlenumber_in_subtree_entries(QuadTreeNM& T);
313 
318  void construct_reduced_subtree(NodeArray<NodeAttributes>& A,
319  QuadTreeNM& T,
320  List<QuadTreeNodeNM*>& new_subtree_root_List);
321 
324  void delete_empty_subtrees(QuadTreeNM& T);
325 
331  bool check_and_delete_degenerated_node(QuadTreeNM& T);
332 
337  void delete_sparse_subtree(QuadTreeNM& T, QuadTreeNodeNM* new_leaf_ptr);
338 
342  void collect_contained_nodes(QuadTreeNM& T, QuadTreeNodeNM* new_leaf_ptr);
343 
350  bool find_smallest_quad(NodeArray<NodeAttributes>& A, QuadTreeNM& T);
351 
353 
356  void find_small_cell_iteratively(QuadTreeNodeNM* act_ptr,
357  double x_min,
358  double x_max,
359  double y_min,
360  double y_max);
361 
364  void find_small_cell_by_formula(QuadTreeNodeNM* act_ptr,
365  double x_min,
366  double x_max,
367  double y_min,
368  double y_max);
369 
372  inline void find_small_cell(QuadTreeNodeNM* act_ptr,
373  double x_min, double x_max,
374  double y_min, double y_max) {
375  switch (find_sm_cell()) {
377  find_small_cell_iteratively(act_ptr, x_min, x_max, y_min, y_max);
378  break;
380  find_small_cell_by_formula(act_ptr, x_min, x_max, y_min, y_max);
381  break;
382  }
383  }
384 
386  void delete_red_quad_tree_and_count_treenodes(QuadTreeNM& T);
387 
390  void form_multipole_expansions(NodeArray<NodeAttributes>& A,
391  QuadTreeNM& T,
392  List<QuadTreeNodeNM*>& quad_tree_leaves);
393 
396  void form_multipole_expansion_of_subtree(NodeArray<NodeAttributes>& A,
397  QuadTreeNM& T,
398  List<QuadTreeNodeNM*>& quad_tree_leaves);
399 
401  void init_expansion_Lists(QuadTreeNodeNM* act_ptr);
402 
404  void set_center(QuadTreeNodeNM* act_ptr);
405 
407  void form_multipole_expansion_of_leaf_node(NodeArray<NodeAttributes>& A,
408  QuadTreeNodeNM* act_ptr);
409 
412  void add_shifted_expansion_to_father_expansion(QuadTreeNodeNM* act_ptr);
413 
417  void calculate_local_expansions_and_WSPRLS(NodeArray<NodeAttributes>&A,
418  QuadTreeNodeNM* act_node_ptr);
419 
422  bool well_separated(QuadTreeNodeNM* ptr_1, QuadTreeNodeNM* ptr_2);
423 
425  bool bordering(QuadTreeNodeNM* ptr_1, QuadTreeNodeNM* ptr_2);
426 
429  void add_shifted_local_exp_of_parent(QuadTreeNodeNM* node_ptr);
430 
433  void add_local_expansion(QuadTreeNodeNM* ptr_1, QuadTreeNodeNM* ptr_2);
434 
438  void add_local_expansion_of_leaf(NodeArray<NodeAttributes>&A,
439  QuadTreeNodeNM* leaf_ptr,
440  QuadTreeNodeNM* act_ptr);
441 
444  void transform_local_exp_to_forces(NodeArray <NodeAttributes>&A,
445  List<QuadTreeNodeNM*>& quad_tree_leaves,
446  NodeArray<DPoint>& F_local_exp);
447 
450  void transform_multipole_exp_to_forces(NodeArray<NodeAttributes>& A,
451  List<QuadTreeNodeNM*>& quad_tree_leaves,
452  NodeArray<DPoint>& F_multipole_exp);
453 
456  void calculate_neighbourcell_forces(NodeArray<NodeAttributes>& A,
457  List<QuadTreeNodeNM*>& quad_tree_leaves,
458  NodeArray<DPoint>& F_direct);
459 
461  void add_rep_forces(const Graph& G,
462  NodeArray<DPoint>& F_direct,
463  NodeArray<DPoint>& F_multipole_exp,
464  NodeArray<DPoint>& F_local_exp,
465  NodeArray<DPoint>& F_rep);
466 
468  double f_rep_scalar (double d);
469 
471  void init_binko(int t);
472 
474  void free_binko();
475 
477  double binko(int n, int k);
478 
480  FMMMOptions::ReducedTreeConstruction tree_construction_way() const { return _tree_construction_way; }
481 
483  _tree_construction_way = rtc;
484  }
485 
488  FMMMOptions::SmallestCellFinding find_sm_cell() const { return _find_small_cell; }
489 
491  _find_small_cell = scf;
492  }
493 
495  void particles_in_leaves (int b) { _particles_in_leaves = ((b>= 1)? b : 1); }
496  int particles_in_leaves () const { return _particles_in_leaves; }
497 
499  void precision (int p) { _precision = ((p >= 1 ) ? p : 1); }
500  int precision () const { return _precision; }
501 };
502 
503 }
504 }
505 }
FruchtermanReingold ExactMethod
needed in case that using_NMM == false
FMMMOptions::SmallestCellFinding find_sm_cell() const
Returns the way the smallest quadratic cell that surrounds the particles of a node in the reduced buc...
void find_small_cell(QuadTreeNodeNM *act_ptr, double x_min, double x_max, double y_min, double y_max)
Finds the small cell of the actual node using the selected algorithm.
helping data structure that stores the graphical attributes of a node that are needed for the force-d...
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
double ** BK
holds the binomial coefficients
ReducedTreeConstruction
Specifies how the reduced bucket quadtree is constructed.
Definition: FMMMOptions.h:136
Real points.
Definition: geometry.h:219
FMMMOptions::ReducedTreeConstruction _tree_construction_way
int _precision
precision for p-term multipole expansion
bool using_NMM
Indicates whether the exact method or NMM is used for force calculation (value depends on MIN_NODE_NU...
Helping data structure that stores the information needed to represent a node of the reduced quad tre...
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
According to formula by Aluru et al.
Declaration of Fast Multipole Multilevel Method (FM^3) options.
List< DPoint > rep_forces
stores the rep. forces of the last iteration needed for error calculation)
Helping data structure that stores the information needed to represent the modified quadtree in the N...
Definition: QuadTreeNM.h:42
FMMMOptions::SmallestCellFinding _find_small_cell
The parameterized class Array2D implements dynamic two-dimensional arrays.
Definition: Array2D.h:46
Encapsulates a pointer to a list element.
Definition: List.h:41
void find_sm_cell(FMMMOptions::SmallestCellFinding scf)
void particles_in_leaves(int b)
Max. number of particles that are contained in a leaf of the red. quadtree.
Includes declaration of graph class.
Declaration of class FruchtermanReingold (computation of forces).
void precision(int p)
The precision p for the p-term multipole expansions.
FMMMOptions::ReducedTreeConstruction tree_construction_way() const
Returns the way to construct the reduced tree.
DPoint down_left_corner
down left corner of drawing box
Declaration of class QuadTreeNM.
The namespace for all OGDF objects.
Declaration of classes DPoint, DPolyline, DLine, DRect, DIntersectableRect, DScaler.
SmallestCellFinding
Specifies how to calculate the smallest quadratic cell that surrounds the particles of a node in the ...
Definition: FMMMOptions.h:143
int MIN_NODE_NUMBER
The minimum number of nodes for which the forces are calculated using NMM (for lower values the exact...
void tree_construction_way(FMMMOptions::ReducedTreeConstruction rtc)
Declaration of doubly linked lists and iterators.
Declaration and implementation of class Array2D which implements dynamic two dimensional arrays...