Open
Graph Drawing
Framework

 v. 2025.10-dev (Foxglove)
 

Loading...
Searching...
No Matches
EdgePairPartition.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/basic.h>
38
39#include <list>
40#include <memory>
41#include <set>
42#include <stack>
43#include <vector>
44
46
48template<typename GraphElementPointer>
50private:
51 GraphElementPointer m_first, m_second;
52
53public:
55 OrderedPair(GraphElementPointer a, GraphElementPointer b) {
56 OGDF_ASSERT(a && b);
57 OGDF_ASSERT(a->graphOf() == b->graphOf());
58 OGDF_ASSERT(a != b);
59 if (a->index() < b->index()) {
60 m_first = a;
61 m_second = b;
62 } else {
63 m_first = b;
64 m_second = a;
65 }
66 }
67
69 GraphElementPointer first() const { return m_first; }
70
72 GraphElementPointer second() const { return m_second; }
73
75 bool contains(GraphElementPointer el) const { return m_first == el || m_second == el; }
76
77 bool operator==(const OrderedPair& rhs) const {
78 OGDF_ASSERT(graphOf() == rhs.graphOf());
79 OGDF_ASSERT(m_first->index() <= m_second->index());
80 OGDF_ASSERT(rhs.m_first->index() <= rhs.m_second->index());
81
82 return m_first == rhs.m_first && m_second == rhs.m_second;
83 }
84
85 bool operator!=(const OrderedPair& rhs) const { return !operator==(rhs); }
86
87 bool operator<(const OrderedPair& rhs) const {
88 OGDF_ASSERT(graphOf() == rhs.graphOf());
89 OGDF_ASSERT(m_first->index() <= m_second->index());
90 OGDF_ASSERT(rhs.m_first->index() <= rhs.m_second->index());
91
92 return m_first->index() < rhs.m_first->index()
93 || ((m_first->index() == rhs.m_first->index())
94 && (m_second->index() < rhs.m_second->index()));
95 }
96
97#ifdef OGDF_DEBUG
98 const Graph* graphOf() const { return m_first->graphOf(); }
99#endif
100};
101
104
107 Normal,
108 NIC,
109 IC
110};
111
113
118private:
120 std::set<EdgePair> m_crossings;
121 std::set<VertexPair> m_kiteEdges;
122 std::set<EdgePair> m_nonCrossingPairs;
123 std::list<EdgePair> m_todoCrossings;
124 std::unique_ptr<EdgePair> m_previousCrossing = nullptr;
125 };
126
127 OneplanMode m_mode = OneplanMode::Normal;
130 std::set<VertexPair> m_kiteEdges;
131 std::set<EdgePair> m_crossingEdgePairs;
132 std::set<EdgePair> m_freeEdgePairs;
133
134 std::stack<UndoInformation> m_undoInformation;
135
136public:
138
142 explicit EdgePairPartition(const Graph& g, OneplanMode m = OneplanMode::Normal)
143 : m_mode(m), m_graph(g), m_crossedEdges(m_graph) {
144 for (edge e1 : m_graph.edges) {
145 for (edge e2 : m_graph.edges) {
146 if (!e1->isAdjacent(e2)) {
147 m_freeEdgePairs.emplace(e1, e2);
148 }
149 }
150 }
151 }
152
155 : m_mode(other.m_mode)
156 , m_graph(other.m_graph)
157 , m_crossedEdges(other.m_crossedEdges)
158 , m_kiteEdges(other.m_kiteEdges)
159 , m_crossingEdgePairs(other.m_crossingEdgePairs)
160 , m_freeEdgePairs(other.m_freeEdgePairs) { }
161
163 const Graph& graph() const { return m_graph; }
164
166 const std::set<VertexPair>& kiteEdges() const { return m_kiteEdges; }
167
169 const std::set<EdgePair>& crossingEdgePairs() const { return m_crossingEdgePairs; }
170
172 void startTransaction() { m_undoInformation.emplace(); }
173
175 void startTransaction(std::vector<EdgePair>& todoCrossings) {
176 UndoInformation& ui = m_undoInformation.emplace();
177 ui.m_todoCrossings.assign(todoCrossings.begin(), todoCrossings.end());
178 }
179
182
185 if (m_undoInformation.empty()) {
186 return false;
187 }
188 return !m_undoInformation.top().m_todoCrossings.empty();
189 }
190
193 OGDF_ASSERT(hasTodoCrossing());
194 EdgePair ep = m_undoInformation.top().m_todoCrossings.front();
195 m_undoInformation.top().m_todoCrossings.pop_front();
196 m_undoInformation.top().m_previousCrossing = std::make_unique<EdgePair>(ep);
197 return ep;
198 }
199
201 void crossEdgePair(const EdgePair& pair);
202
204 void setNonCrossing(const EdgePair& pair) {
205 if (m_freeEdgePairs.count(pair) > 0) {
206 m_freeEdgePairs.erase(pair);
207 m_undoInformation.top().m_nonCrossingPairs.insert(pair);
208 }
209 }
210
212 bool isFree(const EdgePair& pair) const {
213 OGDF_ASSERT(pair.graphOf() == &m_graph);
214 if (m_crossedEdges.contains(pair.first()) || m_crossedEdges.contains(pair.second())) {
215 return false;
216 }
217 if (m_kiteEdges.count({pair.first()->source(), pair.first()->target()}) > 0
218 || m_kiteEdges.count({pair.second()->source(), pair.second()->target()}) > 0) {
219 return false;
220 }
221 return m_freeEdgePairs.count(pair) > 0;
222 }
223
225 bool isFree(edge e) const {
226 if (m_kiteEdges.count({e->source(), e->target()}) > 0 || m_crossedEdges.contains(e)) {
227 return false;
228 }
229 for (EdgePair ep : m_freeEdgePairs) {
230 if (ep.contains(e)) {
231 return true;
232 }
233 }
234 return false;
235 }
236
238 bool isCrossed(edge e) const {
239 for (EdgePair ep : m_crossingEdgePairs) {
240 if (ep.contains(e)) {
241 return true;
242 }
243 }
244 return false;
245 }
246
249 for (adjEntry adj : a->adjEntries) {
250 if (adj->twinNode() == b) {
251 return adj->theEdge();
252 }
253 }
254 return nullptr;
255 }
256
257private:
258 void computeKiteEdges(const EdgePair& crossedPair);
259
261 OGDF_ASSERT(e->graphOf() == &m_graph);
262 if (!m_crossedEdges.contains(e)) {
263 addKiteEdge({e->source(), e->target()});
264 }
265 }
266
267 void addKiteEdge(const VertexPair& vp) {
268 if (m_kiteEdges.count(vp) == 0) {
269 m_kiteEdges.insert(vp);
270 m_undoInformation.top().m_kiteEdges.insert(vp);
271 }
272 }
273};
274}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Class for the representation of edges.
Definition Graph_d.h:364
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition Graph_d.h:441
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Edge sets.
Definition GraphSets.h:86
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition Graph_d.h:932
Class for the representation of nodes.
Definition Graph_d.h:241
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
bool contains(element_type v) const
Returns the same as isMember()
A partial solution for a 1-Planarity instance, representing a node in the backtracking tree.
void startTransaction()
Starts a new transaction that can later be undone.
EdgePairPartition(const EdgePairPartition &other)
Creates a new EdgePairPartition as a copy of other, but does not copy its transaction stack.
const std::set< EdgePair > & crossingEdgePairs() const
Returns the set of all crossed edge pairs.
bool isFree(const EdgePair &pair) const
Returns whether pair is still allowed to cross.
void computeKiteEdges(const EdgePair &crossedPair)
std::stack< UndoInformation > m_undoInformation
void startTransaction(std::vector< EdgePair > &todoCrossings)
Starts a new transaction and associates an exhaustive set of crossings that will be branched over.
void setNonCrossing(const EdgePair &pair)
Marks pair as non-crossing.
EdgePair getNextTodoCrossing()
Removes and returns the next stored crossing that should be considered.
const std::set< VertexPair > & kiteEdges() const
Returns the set of kite edges.
void undoTransaction()
Reverts the previous transaction.
bool isFree(edge e) const
Returns whether there exists an edge that e may cross.
bool hasTodoCrossing()
Returns whether there are crossings that should be branched over.
bool isCrossed(edge e) const
Returns whether e is part of a crossing.
void crossEdgePair(const EdgePair &pair)
Crosses pair and computes the corresponding kite edges.
EdgePairPartition(const Graph &g, OneplanMode m=OneplanMode::Normal)
Creates a new EdgePairPartition, where all pairs of independent edges are crossable.
const Graph & graph() const
Returns the associated graph.
static edge getEdgeBetween(node a, node b)
Returns an edge between a and b, or null.
A pair of distinct graph elements, ordered by their index.
OrderedPair(GraphElementPointer a, GraphElementPointer b)
Creates a new pair that consists of a and b.
bool operator==(const OrderedPair &rhs) const
bool contains(GraphElementPointer el) const
Returns whether el is contained in the pair.
bool operator!=(const OrderedPair &rhs) const
GraphElementPointer second() const
Returns the element with larger index.
bool operator<(const OrderedPair &rhs) const
GraphElementPointer first() const
Returns the element with smaller index.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:118
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
OneplanMode
The different modes for 1-Planarity.
@ NIC
1-Planarity, where two crossed edge pairs may share at most one vertex (NIC-Planarity)
@ IC
1-Planarity, where no two crossed edges may share a vertex (IC-Planarity)