Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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/ArrayBuffer.h>
39 #include <ogdf/basic/Graph.h>
40 #include <ogdf/basic/GraphCopy.h>
41 #include <ogdf/basic/GraphList.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 
51 namespace ogdf {
52 
60 public:
67  MinimumCutNagamochiIbaraki(bool p = true, bool preprocessing = false,
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 
121 private:
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 
140  struct clusterstruct {
143  };
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 
212  node MAOComputation(const node& s);
213 
219  void deleteFromL(BoundedList& L, ListIterator<node>& placeInL);
220 
228  void fillL(const int& maxAdj, ListPure<node>& unviewed, BoundedList& L,
229  std::vector<adjInfo>& adjToViewed);
230 
235  node getFirstNode(BoundedList& L);
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 }
ogdf::ArrayBuffer< edge >
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
Graph.h
Includes declaration of graph class.
ogdf::MinimumCutNagamochiIbaraki::m_partition
ArrayBuffer< node > m_partition
Definition: MinimumCutNagamochiIbaraki.h:281
ogdf::MinimumCutNagamochiIbaraki::call
virtual int call(const Graph &G, const EdgeArray< int > &weights) override
Computes a minimum cut on graph G with non-negative weights on edges.
Definition: MinimumCutNagamochiIbaraki.h:92
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1224
ogdf::MinimumCutNagamochiIbaraki::allNodes
std::unordered_set< node > allNodes
Definition: MinimumCutNagamochiIbaraki.h:279
ogdf::MinimumCutNagamochiIbaraki::hiddenEdges
Graph::HiddenEdgeSet * hiddenEdges
Definition: MinimumCutNagamochiIbaraki.h:277
ogdf::MinimumCutNagamochiIbaraki::pr
bool pr
Definition: MinimumCutNagamochiIbaraki.h:261
ogdf::MinimumCutModule
Serves as an interface for various methods to compute minimum cuts with or without edge weights.
Definition: MinimumCutModule.h:47
ogdf::MinimumCutNagamochiIbaraki::getAdjEdge
static edge getAdjEdge(const adjEntry &adj, const node &s, node &opposite)
Returns edge corresponding to adj.
Definition: MinimumCutNagamochiIbaraki.h:243
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::Logger::Level
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:105
ogdf::MinimumCutNagamochiIbaraki::getNIRounds
const unsigned int & getNIRounds() const
Output the number of Nagamochi-Ibaraki rounds (equals to MAO-Computations)
Definition: MinimumCutNagamochiIbaraki.h:119
ogdf::Logger::Level::Default
@ Default
ogdf::MinimumCutNagamochiIbaraki::N
int N
Definition: MinimumCutNagamochiIbaraki.h:271
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::MinimumCutNagamochiIbaraki::BoundedList
Definition: MinimumCutNagamochiIbaraki.h:122
Logger.h
Contains logging functionality.
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::MinimumCutNagamochiIbaraki::PRTest2
bool PRTest2(const unsigned int &eIndex, const unsigned int &uIndex, const unsigned int &vIndex)
Test for rule 2 of Padberg-Rinaldi.
Definition: MinimumCutNagamochiIbaraki.h:193
ogdf::MinimumCutNagamochiIbaraki::PRTest1
bool PRTest1(const unsigned int &eIndex)
Test for rule 1 of Padberg-Rinaldi.
Definition: MinimumCutNagamochiIbaraki.h:185
ogdf::MinimumCutNagamochiIbaraki::clusterstruct::clusterhead
node clusterhead
Definition: MinimumCutNagamochiIbaraki.h:142
ogdf::MinimumCutNagamochiIbaraki::clusterstruct
Definition: MinimumCutNagamochiIbaraki.h:140
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::MinimumCutNagamochiIbaraki::value
int value() const override
Output value of last minimum cut computation.
Definition: MinimumCutNagamochiIbaraki.h:103
ogdf::MinimumCutNagamochiIbaraki::adjInfo
Definition: MinimumCutNagamochiIbaraki.h:135
ogdf::MinimumCutNagamochiIbaraki::BoundedList::nodesInList
int nodesInList
Definition: MinimumCutNagamochiIbaraki.h:131
ogdf::MinimumCutNagamochiIbaraki::m_GC
GraphCopy m_GC
Definition: MinimumCutNagamochiIbaraki.h:270
ogdf::MinimumCutNagamochiIbaraki::updateLambda
void updateLambda(const int nodeDegree)
Checks for new upper bound.
Definition: MinimumCutNagamochiIbaraki.h:253
GraphCopy.h
Declaration of graph copy classes.
MinimumCutModule.h
Declaration of ogdf::MinimumCutModule.
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::MinimumCutNagamochiIbaraki::getPrRounds
const unsigned int & getPrRounds() const
Output the number of Padberg-Rinaldi rounds.
Definition: MinimumCutNagamochiIbaraki.h:114
ogdf::MinimumCutNagamochiIbaraki::m_preprocess
bool m_preprocess
Definition: MinimumCutNagamochiIbaraki.h:259
ogdf::ListPure
Doubly linked lists.
Definition: List.h:55
ogdf::MinimumCutNagamochiIbaraki
Calculate minimum cut value for a given Graph.
Definition: MinimumCutNagamochiIbaraki.h:59
ogdf::graphics::init
void init()
Definition: graphics.h:450
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::MinimumCutNagamochiIbaraki::clusterstruct::clusterNodes
ListPure< node > clusterNodes
Definition: MinimumCutNagamochiIbaraki.h:141
ogdf::MinimumCutNagamochiIbaraki::nodes
virtual const ArrayBuffer< node > & nodes() override
Returns a list of nodes belonging to one side of the bipartition.
Definition: MinimumCutNagamochiIbaraki.h:109
ogdf::MinimumCutNagamochiIbaraki::edges
virtual const ArrayBuffer< edge > & edges() override
Returns the edges defining the computed mincut.
Definition: MinimumCutNagamochiIbaraki.h:106
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::MinimumCutNagamochiIbaraki::size
int size
Definition: MinimumCutNagamochiIbaraki.h:263
ogdf::MinimumCutNagamochiIbaraki::BoundedList::BoundedList
BoundedList(ListPure< node > l_init=ListPure< node >(), int nodesInList_init=0, int size_init=0)
Definition: MinimumCutNagamochiIbaraki.h:123
ogdf::MinimumCutNagamochiIbaraki::degree
std::vector< int > degree
Definition: MinimumCutNagamochiIbaraki.h:274
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:102
ogdf::MinimumCutNagamochiIbaraki::M
int M
Definition: MinimumCutNagamochiIbaraki.h:272
ogdf::MinimumCutNagamochiIbaraki::setid
std::vector< int > setid
Definition: MinimumCutNagamochiIbaraki.h:275
ogdf::MinimumCutNagamochiIbaraki::m_cutEdges
ArrayBuffer< edge > m_cutEdges
Definition: MinimumCutNagamochiIbaraki.h:283
ogdf::MinimumCutNagamochiIbaraki::edgeCapacity
std::vector< int > edgeCapacity
Definition: MinimumCutNagamochiIbaraki.h:273
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::MinimumCutNagamochiIbaraki::BoundedList::list
ListPure< node > list
Definition: MinimumCutNagamochiIbaraki.h:130
ogdf::MinimumCutNagamochiIbaraki::BoundedList::size
int size
Definition: MinimumCutNagamochiIbaraki.h:132
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::MinimumCutNagamochiIbaraki::call
virtual int call(const Graph &G) override
Computes a minimum cut on graph G.
Definition: MinimumCutNagamochiIbaraki.h:89