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/Array.h>
39 #include <ogdf/basic/GraphCopy.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 
52 namespace ogdf {
53 
61 public:
68  MinimumCutNagamochiIbaraki(bool p = true, bool preprocessing = false,
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 
122 private:
123  struct BoundedList {
124  explicit BoundedList(ListPure<node> l_init = ListPure<node>(), int nodesInList_init = 0,
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 
141  struct clusterstruct {
144  };
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 
180  void PRPass1_2(const node& lastContracted);
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 
213  node MAOComputation(const node& s);
214 
220  void deleteFromL(BoundedList& L, ListIterator<node>& placeInL);
221 
229  void fillL(const int& maxAdj, ListPure<node>& unviewed, BoundedList& L,
230  std::vector<adjInfo>& adjToViewed);
231 
236  node getFirstNode(BoundedList& L);
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) {
255  if (nodeDegree < barLambda && size >= 2) {
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 }
ogdf::ArrayBuffer< edge >
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::MinimumCutNagamochiIbaraki::m_partition
ArrayBuffer< node > m_partition
Definition: MinimumCutNagamochiIbaraki.h:282
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:93
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1216
ogdf::MinimumCutNagamochiIbaraki::allNodes
std::unordered_set< node > allNodes
Definition: MinimumCutNagamochiIbaraki.h:280
ogdf::MinimumCutNagamochiIbaraki::hiddenEdges
Graph::HiddenEdgeSet * hiddenEdges
Definition: MinimumCutNagamochiIbaraki.h:278
ogdf::MinimumCutNagamochiIbaraki::pr
bool pr
Definition: MinimumCutNagamochiIbaraki.h:262
ogdf::MinimumCutModule
Serves as an interface for various methods to compute minimum cuts with or without edge weights.
Definition: MinimumCutModule.h:45
ogdf::MinimumCutNagamochiIbaraki::getAdjEdge
static edge getAdjEdge(const adjEntry &adj, const node &s, node &opposite)
Returns edge corresponding to adj.
Definition: MinimumCutNagamochiIbaraki.h:244
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
ogdf::Logger::Level
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:103
ogdf::MinimumCutNagamochiIbaraki::getNIRounds
const unsigned int & getNIRounds() const
Output the number of Nagamochi-Ibaraki rounds (equals to MAO-Computations)
Definition: MinimumCutNagamochiIbaraki.h:120
ogdf::Logger::Level::Default
@ Default
ogdf::MinimumCutNagamochiIbaraki::N
int N
Definition: MinimumCutNagamochiIbaraki.h:272
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::MinimumCutNagamochiIbaraki::BoundedList
Definition: MinimumCutNagamochiIbaraki.h:123
Logger.h
Contains logging functionality.
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
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:194
ogdf::MinimumCutNagamochiIbaraki::PRTest1
bool PRTest1(const unsigned int &eIndex)
Test for rule 1 of Padberg-Rinaldi.
Definition: MinimumCutNagamochiIbaraki.h:186
ogdf::MinimumCutNagamochiIbaraki::clusterstruct::clusterhead
node clusterhead
Definition: MinimumCutNagamochiIbaraki.h:143
ogdf::MinimumCutNagamochiIbaraki::clusterstruct
Definition: MinimumCutNagamochiIbaraki.h:141
SList.h
Declaration of singly linked lists and iterators.
ogdf::MinimumCutNagamochiIbaraki::value
int value() const override
Output value of last minimum cut computation.
Definition: MinimumCutNagamochiIbaraki.h:104
ogdf::MinimumCutNagamochiIbaraki::adjInfo
Definition: MinimumCutNagamochiIbaraki.h:136
ogdf::MinimumCutNagamochiIbaraki::BoundedList::nodesInList
int nodesInList
Definition: MinimumCutNagamochiIbaraki.h:132
ogdf::MinimumCutNagamochiIbaraki::m_GC
GraphCopy m_GC
Definition: MinimumCutNagamochiIbaraki.h:271
ogdf::MinimumCutNagamochiIbaraki::updateLambda
void updateLambda(const int nodeDegree)
Checks for new upper bound.
Definition: MinimumCutNagamochiIbaraki.h:254
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:862
ogdf::MinimumCutNagamochiIbaraki::getPrRounds
const unsigned int & getPrRounds() const
Output the number of Padberg-Rinaldi rounds.
Definition: MinimumCutNagamochiIbaraki.h:115
ogdf::MinimumCutNagamochiIbaraki::m_preprocess
bool m_preprocess
Definition: MinimumCutNagamochiIbaraki.h:260
Math.h
Mathematical Helpers.
ogdf::ListPure
Doubly linked lists.
Definition: List.h:44
ogdf::MinimumCutNagamochiIbaraki
Calculate minimum cut value for a given Graph.
Definition: MinimumCutNagamochiIbaraki.h:60
ogdf::graphics::init
void init()
Definition: graphics.h:446
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:142
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::MinimumCutNagamochiIbaraki::nodes
virtual const ArrayBuffer< node > & nodes() override
Returns a list of nodes belonging to one side of the bipartition.
Definition: MinimumCutNagamochiIbaraki.h:110
ogdf::MinimumCutNagamochiIbaraki::edges
virtual const ArrayBuffer< edge > & edges() override
Returns the edges defining the computed mincut.
Definition: MinimumCutNagamochiIbaraki.h:107
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
List.h
Declaration of doubly linked lists and iterators.
ogdf::MinimumCutNagamochiIbaraki::size
int size
Definition: MinimumCutNagamochiIbaraki.h:264
ogdf::MinimumCutNagamochiIbaraki::BoundedList::BoundedList
BoundedList(ListPure< node > l_init=ListPure< node >(), int nodesInList_init=0, int size_init=0)
Definition: MinimumCutNagamochiIbaraki.h:124
ogdf::MinimumCutNagamochiIbaraki::degree
std::vector< int > degree
Definition: MinimumCutNagamochiIbaraki.h:275
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:46
Graph_d.h
Pure declaration header, find template implementation in Graph.h.
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:100
ogdf::MinimumCutNagamochiIbaraki::M
int M
Definition: MinimumCutNagamochiIbaraki.h:273
ogdf::MinimumCutNagamochiIbaraki::setid
std::vector< int > setid
Definition: MinimumCutNagamochiIbaraki.h:276
ogdf::MinimumCutNagamochiIbaraki::m_cutEdges
ArrayBuffer< edge > m_cutEdges
Definition: MinimumCutNagamochiIbaraki.h:284
ogdf::MinimumCutNagamochiIbaraki::edgeCapacity
std::vector< int > edgeCapacity
Definition: MinimumCutNagamochiIbaraki.h:274
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::MinimumCutNagamochiIbaraki::BoundedList::list
ListPure< node > list
Definition: MinimumCutNagamochiIbaraki.h:131
ogdf::MinimumCutNagamochiIbaraki::BoundedList::size
int size
Definition: MinimumCutNagamochiIbaraki.h:133
simple_graph_alg.h
Declaration of simple graph algorithms.
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::MinimumCutNagamochiIbaraki::call
virtual int call(const Graph &G) override
Computes a minimum cut on graph G.
Definition: MinimumCutNagamochiIbaraki.h:90