44namespace planar_separators {
138 levelOfNode.init(*pGraph, -1);
139 parentOfNode.init(*pGraph,
nullptr);
140 childrenOfNode.init(*pGraph);
141 edgeToParent.init(*pGraph,
nullptr);
142 descendantsOfNode.init(*pGraph,
144 inTree.init(*pGraph,
false);
145 mark.init(*pGraph,
false);
157 return pGraph->numberOfNodes();
172#ifdef OGDF_HEAVY_DEBUG
176 marked.
init(*pGraph);
177 for (
node no : pGraph->nodes) {
178 marked[
no] =
no->index();
181 for (
edge e : pGraph->edges) {
183 node s = e->source();
184 node t = e->target();
186 int newIdx = marked[s] < marked[
t] ? marked[s] : marked[
t];
187 int otherIdx = marked[s] < marked[
t] ? marked[
t] : marked[s];
189 for (
node no : pGraph->nodes) {
198 int lowest = marked[pGraph->firstNode()];
199 for (edge e : pGraph->edges) {
235 bool findLevelsSimple =
false);
346 int currentLevel = 0;
347 bool belowMiddle =
true;
402 std::string
getName()
const override {
return "NE"; }
417 std::string
getName()
const override {
return "DMD"; }
538 nodes = std::move(
other.nodes);
539 edges = std::move(
other.edges);
540 isOnCycle = std::move(
other.isOnCycle);
541 isEdgeOnCycle = std::move(
other.isEdgeOnCycle);
542 cycleRoot =
other.cycleRoot;
543 costClock =
other.costClock;
544 costCounter =
other.costCounter;
545 isClockwise =
other.isClockwise;
547 other.tree =
nullptr;
548 other.cycleRoot =
nullptr;
557 , isOnCycle(
std::move(
other.isOnCycle))
558 , isEdgeOnCycle(
std::move(
other.isEdgeOnCycle))
559 , cycleRoot {
other.cycleRoot}
560 , costClock {
other.costClock}
561 , costCounter {
other.costCounter}
562 , isClockwise {
other.isClockwise} {
563 other.tree =
nullptr;
564 other.cycleRoot =
nullptr;
692 : cycle {
cyc}, m_current {
cyc->getCurrentExpandEdge()}, isClockwise {
clockwise} {
715 m_current = next(m_current);
716 while (m_current !=
nullptr
718 m_current = next(m_current);
910using namespace planar_separators;
996 for (
node n : first) {
1012 std::string name = getSpecificName();
1013 for (
const auto&
post : postProcessors) {
1014 name +=
"_" +
post->getName();
1041 int startNodeIndex = -1;
1053 if (startNodeIndex == -1) {
1054 return G.chooseNode();
1056 return G.chooseNode([&](
node n) {
return (n->
index() == startNodeIndex); });
1086 exitPoint =
"graph_trivial";
1093 graph = std::make_shared<GraphCopy>(G);
1102 if (!graph->representsCombEmbedding()) {
1129 for (
int i = 0; i < G.numberOfNodes() / 2.0; i++) {
Includes declaration of graph class.
Declaration of graph copy classes.
Class for adjacency list elements.
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
edge theEdge() const
Returns the edge associated with this adjacency entry.
adjEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
node theNode() const
Returns the node whose adjacency list contains this element.
Dynamic arrays indexed with edges.
Class for the representation of edges.
Copies of graphs supporting edge splitting.
Data type for general directed graphs (adjacency list representation).
Doubly linked lists (maintaining the length of the list).
iterator pushBack(const E &x)
Adds element x at the end of the list.
bool empty() const
Returns true iff the list is empty.
Dynamic arrays indexed with nodes.
const Graph * graphOf() const
Returns a pointer to the associated graph.
void init()
Reinitializes the array. Associates the array with no graph.
Class for the representation of nodes.
int index() const
Returns the (unique) node index.
Abstract description of all planar separator algorithms.
virtual bool separate(const Graph &G, NodeArray< short > &assignments, bool checkPreconditions=true) final
Separates a planar graph.
int connectedComponents(const Graph &G, NodeArray< int > &component, std::map< int, int > &compSizes) const
Finds all connected components within the graph.
void addPostProcessor(Postprocessor &post)
Adds a postprocessor to this separator, which will always be applied.
bool setup(const Graph &G, List< node > &separator, List< node > &first, List< node > &second, bool checkPreconditions=true)
Performs some initial setup to ensure that all preconditions hold and takes trivial steps to separate...
node getStartNode(const Graph &G) const
Selects the starting node for the BFS.
virtual std::string getName() const
Returns the full name of this algorithm.
virtual ~PlanarSeparatorModule()
bool cleanup(const Graph &G, List< node > &separator, List< node > &first, List< node > &second)
Performs built-in post-processing: For small instances, it can happen that all nodes are assigned to ...
std::vector< Postprocessor * > postProcessors
virtual bool doSeparate(const Graph &G, List< node > &separator, List< node > &first, List< node > &second)=0
Core of the specific separation algorithm - override this in inheriting classes.
void setStartIndex(int index)
virtual std::string getSpecificName() const =0
Returns the unique name of the core algorithm, to be combined with postprocessors later.
virtual void reset()
Reset everything to enable reuse of the module.
std::shared_ptr< GraphCopy > graph
virtual double getMaxSeparatorSize(int n) const =0
Provides the maximal separator size that this algorithm guarantees as a function of the number of nod...
bool separateComponents(GraphCopy &G, List< node > &separator, List< node > &first, List< node > &second, bool skip=false) const
Checks if the graph consists of multiple connected components, takes necessary steps for fixing that,...
std::string getExitPoint() const
Returns the exitPoint, i.e.
void clearPostProcessors()
Deletes all appended postprocessors from this separator.
virtual bool separate(const Graph &G, List< node > &separator, List< node > &first, List< node > &second, bool checkPreconditions=true) final
Separates a planar graph.
bool postProcess(const Graph &G, List< node > &separator, List< node > &first, List< node > &second)
Apply all postprocessors.
Abstract BFSTree that is realized via NodeArrays.
int getLevelOfNode(node n) const override
Returns the level (=depth in the tree) for a node.
adjEntry getAdjToParent(node n) const override
Returns the adjEntry that leads up to the parent of n.
node getRoot() const override
Gets the current root node of the tree.
void init()
Initializes all internal arrays.
NodeArray< int > descendantsOfNode
int getGraphSize() const override
Gets the number of nodes of the graph.
NodeArray< adjEntry > edgeToParent
node getParentOfNode(node n) const override
Returns the node that is the parent of n in the tree.
NodeArray< node > parentOfNode
int getDescendantsOfNode(node n) const override
Returns the total number of children, grandchildren etc.
NodeArray< int > levelOfNode
NodeArray< List< node > > childrenOfNode
bool isInTree(edge e) const override
Checks if an edge is a tree-edge.
GraphCopy * getGraph() const override
Allows access to a copy of the graph.
ArrayBFSTree(GraphCopy &G, node rootNode)
Constructor.
List< node > getChildrenOfNode(node n) const override
Returns all (immediate) children of a node.
BFS tree used by both classical algorithms (LT and Dual).
void createNewRoot(bool useTriBFS=false)
Creates a new root node for the graph, replacing all levels below t0.
List< List< node > > levels
List< node > getNodesFrom(int start) const
Returns all nodes from a given level onwards.
List< node > getNodesFromTo(int start, int end) const
Returns all nodes between two levels.
void findLevels()
Finds the levels t0 and t2 of the tree that might serve as separators.
void removeSeparatorLevels(List< node > &separator, List< node > &second)
Removes the two separator levels t0 and t2 from the tree.
void findLevelsSimple()
Simplified version of findLevels that simply finds a level smaller than sqrt(n).
int getSizeOfLevel(int level) const
Gets the size of a specific level.
List< node > getLevel(int level) const
Returns a level of the tree.
void reconstruct()
Reconstructs the tree using triangulating bfs.
unsigned int heightMaxIterations
void restructure(List< node > &separator, List< node > &second, bool useTriBFS=false)
Restructures the tree by adding a new root and deleting all nodes below t0 and above t2,...
bool isVisited(node n) const
Checks whether a node is visited by BFS.
void construct(node rootNode, unsigned int numIterations)
Constructs the tree.
void visit(node v, node parent, adjEntry adj, SListPure< node > &bfs)
BFSTreeClassical(GraphCopy &G, node rootNode, unsigned int heightMaxIterations, bool findLevelsSimple=false)
Constructor.
int getSeparatorLevel() const
Abstract description of a Breadth First Search tree.
virtual node getParentOfNode(node n) const =0
Returns the node that is the parent of n in the tree.
virtual List< node > getChildrenOfNode(node n) const =0
Returns all (immediate) children of a node.
virtual int getDescendantsOfNode(node n) const =0
Returns the total number of children, grandchildren etc.
virtual bool isInTree(edge e) const =0
Checks if an edge is a tree-edge.
virtual int getGraphSize() const =0
Gets the number of nodes of the graph.
virtual node getRoot() const =0
Gets the current root node of the tree.
virtual int getLevelOfNode(node n) const =0
Returns the level (=depth in the tree) for a node.
virtual GraphCopy * getGraph() const =0
Allows access to a copy of the graph.
virtual ~BFSTree()=default
virtual adjEntry getAdjToParent(node n) const =0
Returns the adjEntry that leads up to the parent of n.
Special iterator to walk over the inward-pointing edges of the cycle.
adjEntry operator*() const
friend bool operator!=(const Iterator &a, const Iterator &b)
Iterator(const Cycle *cyc, bool clockwise)
Constructor.
bool isOutEdge()
Checks whether the current adjEntry is the one that leads up to the root.
adjEntry next(adjEntry current) const
Yields the next adjEntry, given the current one (internal use only).
Iterator(const Cycle *cyc)
Constructor.
friend bool operator==(const Iterator &a, const Iterator &b)
Auxiliary data structure to represent Cycles in planar graphs.
void fillLists(List< node > &separator, List< node > &first, List< node > &second, bool useRoot=false)
Fills the lists of nodes, by putting all nodes on this cycle into the list of separator nodes and put...
int getSize() const
Returns the size of the cycle = the number of nodes on the cycle.
Iterator begin() const
Iterators for clockwise iteration over edges on the "inside", starting and ending at currentExpandEdg...
Cycle expandWithoutTreeEdges(node y, const node v, const node w, const adjEntry vy, const adjEntry yw)
Expand the cycle if none of the inner edges of the triangle is a tree edge.
bool findAlphaCycle(Cycle &cyc, const List< node > &pathNodes, const List< adjEntry > &pathAdjEntries, const node z, const node propRoot, const adjEntry yw, List< node > &oldNodes, List< adjEntry > &oldEdges) const
Used during expansion without tree edges.
Cycle(BFSTree *tree, List< node > &nodeList, List< adjEntry > &edgeList, node root, bool clockwise)
Constructor.
Cycle & operator=(Cycle &&other)
void findBetaCycle(Cycle &cyc, const List< node > &pathNodes, const List< adjEntry > &pathAdjEntries, const node z, const node propRoot, const adjEntry vy, List< node > &oldNodes, List< adjEntry > &oldEdges, bool foundRootOnAlpha) const
Used during expansion without tree edges.
int getInsideCost() const
Gets the cost on the inside of the cycle.
EdgeArray< bool > isEdgeOnCycle
Cycle expandCycle()
Expands the cycle, as described by Lipton and Tarjan 1979, by examining the triangle adjacent to the ...
Cycle(BFSTree *tree, edge startEdge)
Constructor.
void collectChildrenOfNode(const node no, NodeArray< bool > &marked, List< node > &list, bool useRoot=false) const
Recursively creates a list containing all descendants of a node.
std::pair< node, node > findPathToCycle(node &y, List< node > &pathNodes, List< adjEntry > &pathAdjEntries) const
Used during expansion without tree edges.
void popBackNode()
Access methods for adding and removing nodes from the cycle.
const node & getRoot() const
Gives access to the root node of the cycle.
adjEntry getCurrentExpandEdge() const
Gets the current non-tree edge on the cycle, which is the one that will be used to expand the cycle f...
void init(List< node > &nodeList, List< adjEntry > &edgeList, node root)
Initializes the cycle (used by constructors).
void pushFrontEdge(adjEntry adj)
NodeArray< bool > isOnCycle
void print() const
Utility method for printing the cycle to the console.
Cycle(BFSTree *tree, bool clockwise)
Constructor.
const List< adjEntry > & getEdges() const
Gets the adjEntries on the cycle.
const List< node > & getNodes() const
Gets the nodes on the cycle.
void expandWithTreeEdge(node y, node v, node w, adjEntry vy, adjEntry yw)
Expand the Cycle when one of the inner edges of the triangle is a tree edge.
int getOutsideCost() const
Gets the cost on the outside of the cycle.
void computeCosts()
Computes the costs on both sides of the cycle.
void increaseCost(adjEntry adj, bool clockwise)
Increases the cost on the inside of this cycle by following the given adjEntry and adding the cost of...
bool getClockwise() const
Checks if the cycle is clockwise, i.e.
Dulmage-Mendelsohn-Decomposition.
void chooseBalancedDecomposition(const Graph &G, List< node > &separator, List< node > &first, List< node > &second)
Given the subsets SI / SX / SR and BI / BX / BR, creates a separator with minimal size so that the tw...
std::string getName() const override
Returns the human-readable identifier of this postprocessor.
bool apply(const Graph &G, List< node > &separator, List< node > &first, List< node > &second) override
Applies the postprocessor to a given separation.
bool alternatingBFS(const Graph &G, const List< node > &startNodes, List< node > &reachableSep, List< node > &reachableB)
Performs an alternating breadth first search to find all nodes in the separator that are reachable,...
void decompose(const Graph &graph, const List< node > &bipart, List< node > &reachableSep, List< node > &reachableB)
Given all nodes in the bipartite graph, selects starting points for the BFS and finds the reachable n...
NodeArray< short > assignments
void reset()
Resets the component so it can be reused.
void setupAssignments(const Graph &G, const List< node > &separator, const List< node > &first, const List< node > &second)
Fills a the NodeArray assignments with the values 0, 1 and 2 to represent the assignments of nodes to...
NodeArray< node > unclone
void bipartiteGraph(Graph &graph, const List< node > &separator)
Creates a bipartite graph from the nodes in the separator and those in the bigger component.
void calculateRemainders(const Graph &graph)
Calculates the subset SR and BR once SI / SX and BI / BX have been found.
void translateAssignments(const Graph &G, List< node > &separator, List< node > &first, List< node > &second) const
Translates the assignments stored in the NodeArray assignments back to the lists, which can then be r...
NodeExpulsor: Remove all nodes that are not connected to both halves of the separation.
std::string getName() const override
Returns the human-readable identifier of this postprocessor.
NodeExpulsor(bool balance=true)
Constructor.
bool apply(const Graph &G, List< node > &separator, List< node > &first, List< node > &second) override
Applies the postprocessor to a given separation.
Abstract description of postprocessors.
virtual bool apply(const Graph &G, List< node > &separator, List< node > &first, List< node > &second)=0
Applies the postprocessor to a given separation.
virtual std::string getName() const =0
Returns the human-readable identifier of this postprocessor.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Declaration of extended graph algorithms.
bool isConnected(const Graph &G)
Returns true iff G is connected.
bool isSimpleUndirected(const Graph &G)
Returns true iff G contains neither self-loops nor undirected parallel edges.
void makeSimpleUndirected(Graph &G)
Removes all self-loops and all but one edge of each bundle of undirected parallel edges.
bool planarEmbedPlanarGraph(Graph &G)
Constructs a planar embedding of G. It assumes that G is planar!
bool isPlanar(const Graph &G)
Returns true, if G is planar, false otherwise.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
@ tree
for every hyperedge e a minimal subcubic tree connecting all hypernodes incident with e together is a...
Declaration of simple graph algorithms.