Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MinimumCutNagamochiIbaraki.h
Go to the documentation of this file.
1
32#pragma once
33
34#define OGDF_MINCUTNI_MAXLISTSIZE 100
35#define OGDF_MINCUTNI_PRTHR 100
36#define OGDF_MINCUTNI_CLUSTERSIZE 10
37
39#include <ogdf/basic/Graph.h>
42#include <ogdf/basic/List.h>
43#include <ogdf/basic/Logger.h>
44#include <ogdf/basic/basic.h>
46
47#include <algorithm>
48#include <unordered_set>
49#include <vector>
50
51namespace ogdf {
52
60public:
67 MinimumCutNagamochiIbaraki(bool p = true, bool preprocessing = false,
68 Logger::Level logLevel = Logger::Level::Default);
69
73 virtual ~MinimumCutNagamochiIbaraki() override;
74
80 const int& minCutWeighted(const Graph& G, const std::vector<int>& capacity);
81
86 const int& minCutUnweighted(const Graph& G);
87
89 virtual inline int call(const Graph& G) override { return minCutUnweighted(G); }
90
92 virtual int call(const Graph& G, const EdgeArray<int>& weights) override {
93 init(G);
94 for (edge e : G.edges) {
95 edgeCapacity[m_GC.copy(e)->index()] = weights[e];
96 }
97 const int& value {minCutWeighted()};
98 delete hiddenEdges;
99 return value;
100 }
101
103 int value() const override { return barLambda; };
104
105 // @warning Currently this algorithm does not support returning the cut edges.
106 virtual const ArrayBuffer<edge>& edges() override { return m_cutEdges; };
107
108 // @warning Currently this algorithm does not support returning a min cut partition.
109 virtual const ArrayBuffer<node>& nodes() override { return m_partition; };
110
114 const unsigned int& getPrRounds() const { return prRounds; };
115
119 const unsigned int& getNIRounds() const { return NIRounds; };
120
121private:
122 struct BoundedList {
123 explicit BoundedList(ListPure<node> l_init = ListPure<node>(), int nodesInList_init = 0,
124 int size_init = 0) {
125 list = l_init;
126 nodesInList = nodesInList_init;
127 size = size_init;
128 }
129
132 int size;
133 };
134
135 struct adjInfo {
136 int adj = 0;
137 ListIterator<node> placeInL = nullptr;
138 };
139
144
146 void init(const Graph& G);
147
152 const int& minCutWeighted();
153
157 void minCut();
158
163 void contractClusters(const std::vector<clusterstruct>& clusters);
164
172 void contract(const node& s, const ListPure<node>& toContract, const int& clusterlevel,
173 const std::vector<clusterstruct>& clusters);
174
179 void PRPass1_2(const node& lastContracted);
180
185 inline bool PRTest1(const unsigned int& eIndex) { return (edgeCapacity[eIndex] >= barLambda); };
186
193 inline bool PRTest2(const unsigned int& eIndex, const unsigned int& uIndex,
194 const unsigned int& vIndex) {
195 return 2 * edgeCapacity[eIndex] >= min(degree[uIndex], degree[vIndex]);
196 };
197
205 void updateClusters(const node& head, const node& currentNode,
206 std::vector<clusterstruct>& clusters, int& level);
207
213
220
228 void fillL(const int& maxAdj, ListPure<node>& unviewed, BoundedList& L,
229 std::vector<adjInfo>& adjToViewed);
230
236
243 static edge getAdjEdge(const adjEntry& adj, const node& s, node& opposite) {
244 auto e = adj->theEdge();
245 opposite = e->opposite(s);
246 return e;
247 }
248
253 inline void updateLambda(const int nodeDegree) {
254 if (nodeDegree < barLambda && size >= 2) {
255 barLambda = nodeDegree;
256 }
257 }
258
259 bool m_preprocess; //if preprocessing should be used
260
261 bool pr; //if pr should be used
262
263 int size; //G.numberOfNodes()
264
265 unsigned int NIRounds = 0;
266 unsigned int prRounds = 0; //successful rounds of PR1_2
267 //unsigned int pr3Rounds = 0;
268 int barLambda = 0; //mincut value
269
270 GraphCopy m_GC; //Copy of the Graph for changing nodes and edges
271 int N; //original size
272 int M; //original |E|
273 std::vector<int> edgeCapacity; //capacity in graphcopy
274 std::vector<int> degree;
275 std::vector<int> setid;
276
278
279 std::unordered_set<node> allNodes;
280
282
284};
285}
Declaration and implementation of ArrayBuffer class.
Includes declaration of graph class.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Declaration of ogdf::MinimumCutModule.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:161
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
Class for the representation of edges.
Definition Graph_d.h:364
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:1222
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Encapsulates a pointer to a list element.
Definition List.h:113
Doubly linked lists.
Definition List.h:233
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:102
Level
supported log-levels from lowest to highest importance
Definition Logger.h:105
Serves as an interface for various methods to compute minimum cuts with or without edge weights.
Calculate minimum cut value for a given Graph.
virtual int call(const Graph &G, const EdgeArray< int > &weights) override
Computes a minimum cut on graph G with non-negative weights on edges.
bool PRTest1(const unsigned int &eIndex)
Test for rule 1 of Padberg-Rinaldi.
void updateClusters(const node &head, const node &currentNode, std::vector< clusterstruct > &clusters, int &level)
Add new node to an existing cluster of head or create new cluster with head as head.
void contract(const node &s, const ListPure< node > &toContract, const int &clusterlevel, const std::vector< clusterstruct > &clusters)
Contracts one clusters.
node getFirstNode(BoundedList &L)
Return first node of L and adjust values of L.
static edge getAdjEdge(const adjEntry &adj, const node &s, node &opposite)
Returns edge corresponding to adj.
void minCut()
Underlying function for minCut computation.
void updateLambda(const int nodeDegree)
Checks for new upper bound.
virtual const ArrayBuffer< edge > & edges() override
Returns the edges defining the computed mincut.
const unsigned int & getPrRounds() const
Output the number of Padberg-Rinaldi rounds.
virtual int call(const Graph &G) override
Computes a minimum cut on graph G.
virtual const ArrayBuffer< node > & nodes() override
Returns a list of nodes belonging to one side of the bipartition.
void fillL(const int &maxAdj, ListPure< node > &unviewed, BoundedList &L, std::vector< adjInfo > &adjToViewed)
Refills L, if it's empty but nodes with the same adjacency exists.
virtual ~MinimumCutNagamochiIbaraki() override
Standard destructor of the class.
void deleteFromL(BoundedList &L, ListIterator< node > &placeInL)
Deletes the node given through placeInL from L.
node MAOComputation(const node &s)
Compute a MAO and contract clusters in it.
const unsigned int & getNIRounds() const
Output the number of Nagamochi-Ibaraki rounds (equals to MAO-Computations)
const int & minCutUnweighted(const Graph &G)
Compute a minimum cut value for the given unweighted graph.
const int & minCutWeighted(const Graph &G, const std::vector< int > &capacity)
Compute a minimum cut value for the given weighted graph.
void PRPass1_2(const node &lastContracted)
Tests rule 1 and 2 of Padberg-Rinaldi of all incident edges of lastContracted and contracts on succes...
const int & minCutWeighted()
Compute a minimum cut value for the given weighted graph, assuming that m_GC and edgeCapacity have al...
void init(const Graph &G)
Initializes member variables.
void contractClusters(const std::vector< clusterstruct > &clusters)
Contracts all Clusters trough contraction of each cluster using contractClusters.
MinimumCutNagamochiIbaraki(bool p=true, bool preprocessing=false, Logger::Level logLevel=Logger::Level::Default)
Standard constructor of the class.
bool PRTest2(const unsigned int &eIndex, const unsigned int &uIndex, const unsigned int &vIndex)
Test for rule 2 of Padberg-Rinaldi.
int value() const override
Output value of last minimum cut computation.
Class for the representation of nodes.
Definition Graph_d.h:241
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
The namespace for all OGDF objects.
BoundedList(ListPure< node > l_init=ListPure< node >(), int nodesInList_init=0, int size_init=0)