Adaptagrams
peeling.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_PEELING_H
26 #define DIALECT_PEELING_H
27 
28 #include <memory>
29 #include <vector>
30 
31 #include "libdialect/commontypes.h"
32 #include "libdialect/graphs.h"
33 
34 namespace dialect {
35 
36 class PeeledNode;
37 struct Stem;
38 
39 typedef std::shared_ptr<PeeledNode> PeeledNode_SP;
40 typedef std::shared_ptr<Stem> Stem_SP;
41 
47 PeeledNode_SP identifyRootNode(const Graph &graph);
48 
50 class PeeledNode : public GhostNode {
51  friend struct Stem;
52  friend PeeledNode_SP identifyRootNode(const Graph &graph);
53 public:
57  static PeeledNode_SP allocate(const Node &node) { return PeeledNode_SP(new PeeledNode(node)); }
58 
60  PeeledNode &operator=(const PeeledNode&) = default;
61 
63  virtual ~PeeledNode(void) = default;
64 
65 private:
67  PeeledNode(void) = delete;
68 
70  PeeledNode(const PeeledNode&) = delete;
71 
73  PeeledNode(const Node &node)
74  : GhostNode(node),
75  m_treeSerialNumber(nextTreeSerialNumber++) {}
76 
79  static id_type nextTreeSerialNumber;
80  id_type m_treeSerialNumber;
81  void updateSerialNumber(void) { m_treeSerialNumber = nextTreeSerialNumber++; }
82 
83 };
84 
85 
87 struct Stem {
88  Stem(const Node_SP &leaf, const Node_SP &root) : m_plain_leaf(leaf), m_plain_root(root) {}
89  Node_WP m_plain_leaf;
90  Node_WP m_plain_root;
91  void addSelfToGraph(Graph &H);
92 };
93 
95 std::vector<Stem_SP> makeStemsFromLeaves(const NodesById &leaves);
96 
101 struct NodeBuckets {
106  NodeBuckets(Graph &graph);
107 
109  NodesById takeLeaves(void);
110 
118  bool moveNode(id_type id, unsigned oldDegree, unsigned newDegree);
119 
128  void severNodes(const NodesById &nodes);
129 
130  Graph &m_graph;
131  unsigned m_maxDegree;
132  std::vector<NodesById> m_buckets;
133 };
134 
157 Trees peel(Graph &G);
158 
159 } // namespace dialect
160 
161 #endif // DIALECT_PEELING_H
The Graph class represents graphs consisting of nodes and edges.
Definition: graphs.h:180
bool moveNode(id_type id, unsigned oldDegree, unsigned newDegree)
Move a node from one bucket to another.
Definition: peeling.cpp:137
NodesById takeLeaves(void)
Return a copy of the bucket of leaves, and clear the latter.
Definition: peeling.cpp:128
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
NodeBuckets(Graph &graph)
Initialize a set of node buckets for the given Graph.
Definition: peeling.cpp:115
void severNodes(const NodesById &nodes)
Sever the given Nodes from our Graph.
Definition: peeling.cpp:152
Trees peel(Graph &G)
Perform the "peeling" process, in which the exterior trees are removed from the given Graph...
Definition: peeling.cpp:168
PeeledNode_SP identifyRootNode(const Graph &graph)
Mark as "root" the PeeledNode having largest serial number.
Definition: peeling.cpp:92
std::vector< Stem_SP > makeStemsFromLeaves(const NodesById &leaves)
Make a Stem object to represent each leaf.
Definition: peeling.cpp:72
static PeeledNode_SP allocate(const Node &node)
Factory function.
Definition: peeling.h:57
Definition: peeling.h:101
friend PeeledNode_SP identifyRootNode(const Graph &graph)
Mark as "root" the PeeledNode having largest serial number.
A PeeledNode is a type of GhostNode, used in the peeling process.
Definition: peeling.h:50
virtual ~PeeledNode(void)=default
Destructor.
A GhostNode represents another Node.
Definition: graphs.h:939
The Node class represents nodes in a graph.
Definition: graphs.h:713
Represents a leaf node, along with its one edge and neighbour.
Definition: peeling.h:87
PeeledNode & operator=(const PeeledNode &)=default
Copy-assignment operator.