53 template<
typename TCost>
75 bool preferredImplyPlanar =
false)
override 87 if(pCost !=
nullptr) {
96 copy.
sort(v, newOrder);
103 set[v] = components.makeSet();
108 for (
edge currentEdge : edges) {
111 if (includeEdges[currentEdge])
continue;
117 node source = currentEdge->source();
118 node target = currentEdge->target();
120 edge triangleEdge1 =
nullptr, triangleEdge2 =
nullptr;
121 node triangleNode =
nullptr;
122 int triangleSet = -1;
128 int potentialSet = components.find(
set[v]);
129 if (potentialSet == triangleSet)
return false;
131 if (triangleNode ==
nullptr) {
136 triangleSet = potentialSet;
142 includeEdges[currentEdge] = includeEdges[triangleEdge1] = includeEdges[triangleEdge2]
143 = includeEdges[e1] = includeEdges[e2] =
true;
146 int sourceSet = components.find(
set[source]);
147 int targetSet = components.find(
set[target]);
148 components.link(components.link(components.link(sourceSet, targetSet), triangleSet), potentialSet);
156 for (
edge currentEdge : edges) {
158 if (includeEdges[currentEdge])
continue;
160 node source = currentEdge->source();
161 node target = currentEdge->target();
164 includeEdges[currentEdge] = includeEdges[e1] = includeEdges[e2] =
true;
165 int potentialSet = components.find(
set[v]);
166 int sourceSet = components.find(
set[source]);
167 int targetSet = components.find(
set[target]);
168 components.link(components.link(sourceSet, targetSet), potentialSet);
175 for (
edge currentEdge : edges) {
176 node source = currentEdge->source();
177 node target = currentEdge->target();
178 int sourceSet = components.find(
set[source]);
179 int targetSet = components.find(
set[target]);
180 if (sourceSet != targetSet) {
181 includeEdges[currentEdge] =
true;
182 components.link(sourceSet, targetSet);
185 if (!includeEdges[currentEdge]) delEdges.
pushBack(copy.
original(currentEdge));
205 while (connectionIterator != source->
adjEntries.end()) {
206 if ((*connectionIterator)->twinNode() == target) {
207 return (*connectionIterator)->theEdge();
209 connectionIterator++;
238 int sourceSet = components.
find(
set[source]);
239 int targetSet = components.
find(
set[target]);
241 if (sourceSet == targetSet)
return;
244 if ((*sourceIt)->theEdge() == currentEdge) {
248 if ((*targetIt)->theEdge() == currentEdge) {
256 node potentialConnection;
258 if (pCost ==
nullptr || (*pCost)[copy.
original((*sourceIt)->theEdge())] > (*pCost)[copy.
original((*targetIt)->theEdge())]) {
259 potentialConnector = *sourceIt;
260 potentialConnection = target;
261 potentialConnectionIterator = targetIt;
265 potentialConnector = *targetIt;
266 potentialConnection = source;
267 potentialConnectionIterator = sourceIt;
273 int potentialSet = components.
find(
set[potentialNode]);
276 if (potentialSet != sourceSet && potentialSet != targetSet) {
277 edge potentialEdge =
searchEdge(potentialNode, potentialConnection, potentialConnectionIterator);
278 if (potentialEdge !=
nullptr) {
283 if (callback(potentialNode, potentialEdge, potentialConnector->
theEdge())) {
node target() const
Returns the target node of the edge.
void clear()
Removes all elements from the list.
edge theEdge() const
Returns the edge associated with this adjacency entry.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
void sort(node v, const ADJ_ENTRY_LIST &newOrder)
Sorts the adjacency list of node v according to newOrder.
Maximum planar subgraph approximation algorithms by Chalermsook/Schmid and Calinescu et al...
ReturnType
The return type of a module.
void findTriangle(GraphCopy ©, edge currentEdge, const EdgeArray< TCost > *pCost, DisjointSets<> &components, NodeArray< int > &set, std::function< bool(node, edge, edge)> callback)
Finds all triangles from a given edge and calls a callback function on them.
void quicksort()
Sorts the list using Quicksort.
Interface for planar subgraph algorithms.
static void copy(const T &from, T &to)
The solution is feasible.
PlanarSubgraphTriangles(bool onlyTriangles=false)
Creates a planarization module based on triangle or diamond matching.
int find(disjoint_sets::CompressionOption< CompressionOptions::PathCompression >, int set)
edge searchEdge(node target, node source, internal::GraphIterator< adjEntry > connectionIterator)
Finds an edge, starting at a given iterator.
A Union/Find data structure for maintaining disjoint sets.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
void allAdjEntries(ADJLIST &adjList) const
Returns a list with all adjacency entries of this node.
Copies of graphs supporting edge splitting.
Class for the representation of nodes.
const Graph & original() const
Returns a reference to the original graph.
virtual Module::ReturnType doCall(const Graph &graph, const List< edge > &, List< edge > &delEdges, const EdgeArray< TCost > *pCost, bool preferredImplyPlanar=false) override
Computes the set of edges delEdges which have to be deleted to obtain the planar subgraph.
bool isSimpleUndirected(const Graph &G)
Returns true iff G contains neither self-loops nor undirected parallel edges.
Declaration of simple graph algorithms.
Implementation of disjoint sets data structures (union-find functionality).
node source() const
Returns the source node of the edge.
bool m_onlyTriangles
Whether we want to only check for triangles.
The namespace for all OGDF objects.
void allEdges(CONTAINER &edgeContainer) const
Returns a container with all edges of the graph.
Declaration of interface for planar subgraph algorithms.
int numberOfNodes() const
Returns the number of nodes in the graph.
Compare elements based on a single comparable attribute.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
virtual PlanarSubgraphTriangles * clone() const override
Returns a new instance of the planarization module with the same settings.
bool isConnected(const Graph &G)
Returns true iff G is connected.
Class for adjacency list elements.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.