gmsh-TingyuanDoc  0.1
An Open-Source Timing-driven Analytical Mixed-size FPGA Placer
SpanningTree.h
Go to the documentation of this file.
1 // Gmsh - Copyright (C) 1997-2022 C. Geuzaine, J.-F. Remacle
2 //
3 // See the LICENSE.txt file in the Gmsh root directory for license information.
4 // Please report all issues on https://gitlab.onelab.info/gmsh/gmsh/issues.
5 // Contributed by Nicolas Marsic.
6 
7 #ifndef SPANNING_TREE_H
8 #define SPANNING_TREE_H
9 
10 #include <list>
11 #include "Plugin.h"
12 
13 extern "C" {
15 }
16 
18 private:
19  class DSU { // Disjoint Set Union
20  // (https://en.wikipedia.org/wiki/Disjoint-set_data_structure)
21  // (https://fr.wikipedia.org/wiki/Union-find)
22  // (https://www.cs.auckland.ac.nz/software/AlgAnim/mst.html)
23  private:
24  std::vector<int> parent;
25  std::vector<int> rank;
26 
27  public:
28  DSU(size_t n);
29  ~DSU();
30 
31  int find(int a);
32  void join(int a, int b);
33 
34  std::string toString();
35  };
36 
37  struct Sort {
38  bool operator()(const std::pair<int, int> &a,
39  const std::pair<int, int> &b) const;
40  };
41 
42  typedef std::set<const MElement *, MElementPtrLessThan> ElementSet;
43  typedef std::set<std::pair<int, int>, Sort> EdgeSet;
44  typedef std::list<std::pair<int, int> > Tree;
45 
46 public:
48 
49  std::string getName() const;
50  std::string getShortHelp() const;
51  std::string getHelp() const;
52  std::string getAuthor() const;
53 
54  int getNbOptions() const;
55  StringXNumber *getOption(int iopt);
56 
57  int getNbOptionsStr() const;
58  StringXString *getOptionStr(int iopt);
59 
60  int run();
61 
62 private:
63  static void spanningTree(EdgeSet &edge, DSU &vertex, Tree &tree);
64 
65  static std::string parse(std::string str, std::list<int> &physical);
66  static void getAllMElement(GModel &model, int physical, int dim,
68  static void getAllMEdge(ElementSet &element, EdgeSet &edge);
69  static void addToModel(GModel &model, Tree &tree, int tag);
70 
71  static std::pair<int, int> minmax(const std::pair<int, int> &p);
72 };
73 
74 #endif
GMSH_SpanningTreePlugin::DSU
Definition: SpanningTree.h:19
StringXString
Definition: Options.h:910
GMSH_SpanningTreePlugin::DSU::toString
std::string toString()
Definition: SpanningTree.cpp:315
Plugin.h
GMSH_Plugin
Definition: Plugin.h:26
GMSH_SpanningTreePlugin::getOption
StringXNumber * getOption(int iopt)
Definition: SpanningTree.cpp:74
StringXNumber
Definition: Options.h:918
GMSH_SpanningTreePlugin::DSU::join
void join(int a, int b)
Definition: SpanningTree.cpp:297
GMSH_SpanningTreePlugin::addToModel
static void addToModel(GModel &model, Tree &tree, int tag)
Definition: SpanningTree.cpp:213
GMSH_SpanningTreePlugin::EdgeSet
std::set< std::pair< int, int >, Sort > EdgeSet
Definition: SpanningTree.h:43
GMSH_SpanningTreePlugin::getNbOptions
int getNbOptions() const
Definition: SpanningTree.cpp:69
GMSH_SpanningTreePlugin::getAllMElement
static void getAllMElement(GModel &model, int physical, int dim, ElementSet &element)
Definition: SpanningTree.cpp:184
GMSH_SpanningTreePlugin::DSU::rank
std::vector< int > rank
Definition: SpanningTree.h:25
GMSH_SpanningTreePlugin::parse
static std::string parse(std::string str, std::list< int > &physical)
Definition: SpanningTree.cpp:160
GMSH_SpanningTreePlugin::ElementSet
std::set< const MElement *, MElementPtrLessThan > ElementSet
Definition: SpanningTree.h:42
GMSH_SpanningTreePlugin
Definition: SpanningTree.h:17
GMSH_SpanningTreePlugin::GMSH_SpanningTreePlugin
GMSH_SpanningTreePlugin()
Definition: SpanningTree.cpp:34
GMSH_SpanningTreePlugin::getAllMEdge
static void getAllMEdge(ElementSet &element, EdgeSet &edge)
Definition: SpanningTree.cpp:201
GMSH_SpanningTreePlugin::Sort
Definition: SpanningTree.h:37
GMSH_SpanningTreePlugin::DSU::parent
std::vector< int > parent
Definition: SpanningTree.h:24
GMSH_SpanningTreePlugin::DSU::~DSU
~DSU()
Definition: SpanningTree.cpp:283
GMSH_RegisterSpanningTreePlugin
GMSH_Plugin * GMSH_RegisterSpanningTreePlugin()
Definition: SpanningTree.cpp:28
GMSH_SpanningTreePlugin::getHelp
std::string getHelp() const
Definition: SpanningTree.cpp:43
GModel
Definition: GModel.h:44
GMSH_SpanningTreePlugin::Tree
std::list< std::pair< int, int > > Tree
Definition: SpanningTree.h:44
GMSH_SpanningTreePlugin::DSU::find
int find(int a)
Definition: SpanningTree.cpp:289
GMSH_SpanningTreePlugin::minmax
static std::pair< int, int > minmax(const std::pair< int, int > &p)
Definition: SpanningTree.cpp:266
element
Definition: shapeFunctions.h:12
GMSH_SpanningTreePlugin::getAuthor
std::string getAuthor() const
Definition: SpanningTree.cpp:67
GMSH_SpanningTreePlugin::DSU::DSU
DSU(size_t n)
Definition: SpanningTree.cpp:274
GMSH_SpanningTreePlugin::getName
std::string getName() const
Definition: SpanningTree.cpp:36
GMSH_SpanningTreePlugin::spanningTree
static void spanningTree(EdgeSet &edge, DSU &vertex, Tree &tree)
Definition: SpanningTree.cpp:145
GMSH_SpanningTreePlugin::run
int run()
Definition: SpanningTree.cpp:89
GMSH_MeshPlugin
Definition: Plugin.h:143
GMSH_SpanningTreePlugin::getShortHelp
std::string getShortHelp() const
Definition: SpanningTree.cpp:38
GMSH_SpanningTreePlugin::getNbOptionsStr
int getNbOptionsStr() const
Definition: SpanningTree.cpp:79
GMSH_SpanningTreePlugin::Sort::operator()
bool operator()(const std::pair< int, int > &a, const std::pair< int, int > &b) const
Definition: SpanningTree.cpp:325
GMSH_SpanningTreePlugin::getOptionStr
StringXString * getOptionStr(int iopt)
Definition: SpanningTree.cpp:84