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
38#include <ogdf/basic/Array.h>
40#include <ogdf/basic/Graph_d.h>
41#include <ogdf/basic/List.h>
42#include <ogdf/basic/Logger.h>
43#include <ogdf/basic/Math.h>
44#include <ogdf/basic/SList.h>
47
48#include <queue>
49#include <unordered_map>
50#include <unordered_set>
51
52namespace ogdf {
53
61public:
68 MinimumCutNagamochiIbaraki(bool p = true, bool preprocessing = false,
69 Logger::Level logLevel = Logger::Level::Default);
70
74 virtual ~MinimumCutNagamochiIbaraki() override;
75
81 const int& minCutWeighted(const Graph& G, const std::vector<int>& capacity);
82
87 const int& minCutUnweighted(const Graph& G);
88
90 virtual inline int call(const Graph& G) override { return minCutUnweighted(G); }
91
93 virtual int call(const Graph& G, const EdgeArray<int>& weights) override {
94 init(G);
95 for (edge e : G.edges) {
96 edgeCapacity[m_GC.copy(e)->index()] = weights[e];
97 }
98 const int& value {minCutWeighted()};
99 delete hiddenEdges;
100 return value;
101 }
102
104 int value() const override { return barLambda; };
105
106 // @warning Currently this algorithm does not support returning the cut edges.
107 virtual const ArrayBuffer<edge>& edges() override { return m_cutEdges; };
108
109 // @warning Currently this algorithm does not support returning a min cut partition.
110 virtual const ArrayBuffer<node>& nodes() override { return m_partition; };
111
115 const unsigned int& getPrRounds() const { return prRounds; };
116
120 const unsigned int& getNIRounds() const { return NIRounds; };
121
122private:
123 struct BoundedList {
125 int size_init = 0) {
126 list = l_init;
127 nodesInList = nodesInList_init;
128 size = size_init;
129 }
130
133 int size;
134 };
135
136 struct adjInfo {
137 int adj = 0;
138 ListIterator<node> placeInL = nullptr;
139 };
140
145
147 void init(const Graph& G);
148
153 const int& minCutWeighted();
154
158 void minCut();
159
164 void contractClusters(const std::vector<clusterstruct>& clusters);
165
173 void contract(const node& s, const ListPure<node>& toContract, const int& clusterlevel,
174 const std::vector<clusterstruct>& clusters);
175
181
186 inline bool PRTest1(const unsigned int& eIndex) { return (edgeCapacity[eIndex] >= barLambda); };
187
194 inline bool PRTest2(const unsigned int& eIndex, const unsigned int& uIndex,
195 const unsigned int& vIndex) {
196 return 2 * edgeCapacity[eIndex] >= min(degree[uIndex], degree[vIndex]);
197 };
198
206 void updateClusters(const node& head, const node& currentNode,
207 std::vector<clusterstruct>& clusters, int& level);
208
214
221
230 std::vector<adjInfo>& adjToViewed);
231
237
244 static edge getAdjEdge(const adjEntry& adj, const node& s, node& opposite) {
245 auto e = adj->theEdge();
246 opposite = e->opposite(s);
247 return e;
248 }
249
254 inline void updateLambda(const int nodeDegree) {
256 barLambda = nodeDegree;
257 }
258 }
259
260 bool m_preprocess; //if preprocessing should be used
261
262 bool pr; //if pr should be used
263
264 int size; //G.numberOfNodes()
265
266 unsigned int NIRounds = 0;
267 unsigned int prRounds = 0; //successful rounds of PR1_2
268 //unsigned int pr3Rounds = 0;
269 int barLambda = 0; //mincut value
270
271 GraphCopy m_GC; //Copy of the Graph for changing nodes and edges
272 int N; //original size
273 int M; //original |E|
274 std::vector<int> edgeCapacity; //capacity in graphcopy
275 std::vector<int> degree;
276 std::vector<int> setid;
277
279
280 std::unordered_set<node> allNodes;
281
283
285};
286}
Declaration and implementation of Array class and Array algorithms.
Pure declaration header, find template implementation in Graph.h.
Declaration of graph copy classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Declaration of ogdf::MinimumCutModule.
Declaration of singly linked lists and iterators.
Mathematical Helpers.
Class for adjacency list elements.
Definition Graph_d.h:79
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:97
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:56
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:821
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:254
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Encapsulates a pointer to a list element.
Definition List.h:103
Doubly linked lists.
Definition List.h:217
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:100
Level
supported log-levels from lowest to highest importance
Definition Logger.h:103
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:177
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Declaration of simple graph algorithms.
BoundedList(ListPure< node > l_init=ListPure< node >(), int nodesInList_init=0, int size_init=0)