Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

CPlanaritySub.h
Go to the documentation of this file.
1 
35 #pragma once
36 
37 #include <ogdf/basic/ArrayBuffer.h>
38 #include <ogdf/basic/Graph.h>
39 #include <ogdf/basic/List.h>
40 #include <ogdf/basic/Logger.h>
41 #include <ogdf/basic/SList.h>
42 #include <ogdf/basic/basic.h>
45 
46 #include <ogdf/external/abacus.h>
47 
48 #include <ostream>
49 
50 namespace ogdf::cluster_planarity {
51 struct edgeValue;
52 } // namespace ogdf::cluster_planarity
53 
54 namespace ogdf {
55 class GraphCopy;
56 class KuratowskiWrapper;
57 
58 namespace cluster_planarity {
59 
60 class CPlanaritySub : public abacus::Sub {
61 public:
64  List<abacus::Constraint*>& criticalConstraints);
65 
66  virtual ~CPlanaritySub();
67 
68  // Creation of a child-node in the Branch&Bound tree according to the
69  // branching rule \p rule
70  virtual abacus::Sub* generateSon(abacus::BranchRule* rule) override;
71 
72 protected:
73  // Checks if the current solution of the LP relaxation is also a feasible solution to the ILP,
74  // i.e. Integer-feasible + satisfying all Kuratowski- and Cut-constraints.
75  virtual bool feasible() override;
76 
77  // to trick Sub::solveLp...
78  virtual int makeFeasible() override { return 0; }
79 #if 0
80  // to trick Sub::solveLp into returning 2
81  virtual int removeNonLiftableCons() { return 0; }
82 #endif
83  int repair();
84 
85  virtual int optimize() override {
86  Logger::slout() << "OPTIMIZE BEGIN\tNode=" << this->id() << "\n";
87  int ret = abacus::Sub::optimize();
88  Logger::slout() << "OPTIMIZE END\tNode=" << this->id() << " db=" << dualBound()
89  << "\tReturn=" << (ret ? "(error)" : "(ok)") << "\n";
90  return ret;
91  }
92 
93  //functions for testing properties of the clustered graph
94 
97  bool checkCConnectivity(const GraphCopy& support);
98  bool checkCConnectivityOld(const GraphCopy& support);
99 
103  while (v != parent[v]) {
104  v = parent[v];
105  }
106  return v;
107  }
108 
109  // Todo: Think about putting this into extended_graph_alg.h to make it
110  // publically available
111  int clusterBags(ClusterGraph& CG, cluster c);
112 
113 #if 0
114  // using the below two functions iunstead (and instead of solveLp) we would get a more traditional situation
115  virtual int separate() {
116  return separateRealO(0.001);
117  }
118  virtual int pricing() {
119  return pricingRealO(0.001);
120  }
121 #endif
122 
128  int separateReal(double minViolate);
129 #if 0
130  int pricingReal(double minViolate);
131 #endif
132 
133  inline int separateRealO(double minViolate) {
134  Logger::slout() << "\tSeparate (minViolate=" << minViolate << ")..";
135  int r = separateReal(minViolate);
136  Logger::slout() << "..done: " << r << "\n";
137  return r;
138  }
139 #if 0
140  inline int pricingRealO(double minViolate) {
141  Logger::slout() << "\tPricing (minViolate=" << minViolate << ")..";
142  int r = pricingReal(minViolate);
143  master()->m_varsPrice += r;
144  Logger::slout() << "..done: " << r << "\n";
145  return r;
146  }
147 #endif
148 
149  virtual int separate() override {
150  Logger::slout()
151  << "\tReporting Separation: " << ((m_reportCreation > 0) ? m_reportCreation : 0)
152  << "\n";
153  return (m_reportCreation > 0) ? m_reportCreation : 0;
154  }
155 
156  virtual int pricing() override {
157  if (inOrigSolveLp) {
158  return 1;
159  }
160  Logger::slout()
161  << "\tReporting Prizing: " << ((m_reportCreation < 0) ? -m_reportCreation : 0)
162  << "\n";
163  return (m_reportCreation < 0) ? -m_reportCreation : 0;
164  }
165 
166  virtual int solveLp() override;
167 
168  // Implementation of virtual function improve() inherited from ABA::SUB.
169  // Invokes the function heuristicImprovePrimalBound().
170  // This function belongs to the ABACUS framework. It is invoked after each separation-step.
171  // Since the heuristic is rather time consuming and because it is not very advantageous
172  // to run the heuristic even if additional constraints have been found, the heuristic
173  // is run "by hand" each time no further constraints could be found, i.e. after having solved
174  // the LP-relaxation optimally.
175  virtual int improve(double& primalValue) override;
176 
177  // Two functions inherited from ABACUS and overritten to manipulate the branching behaviour.
178  virtual int selectBranchingVariableCandidates(ArrayBuffer<int>& candidates) override;
179  virtual int selectBranchingVariable(int& variable) override;
180 
184  return (master()->useDefaultCutPool()) ? addCons(cons) : addCons(cons, pool);
185  }
186 
188  double minViolation) {
189  return (master()->useDefaultCutPool()) ? 0 : constraintPoolSeparation(0, pool, minViolation);
190  }
191 
192 private:
193  CPlanarityMaster* master() { return static_cast<CPlanarityMaster*>(master_); }
194 
195  // A flag indicating if constraints have been found in the current separation step.
196  // Is used to check, if the primal heuristic should be run or not.
201 
202  // used for the steering in solveLp
208 
210  int num = b.size();
211  ArrayBuffer<bool> keep(num, false);
212  for (int i = num; i-- > 0;) {
213  keep.push(true);
214  }
215 #ifdef OGDF_DEBUG
216  int r =
217 #endif
218  addVars(b, nullptr, &keep);
219  OGDF_ASSERT(r == num);
220  }
221 
222  // Computes the support graph for Kuratowski- constraints according to the current LP-solution.
223  // Parameter \p low defines a lower threshold, i.e all edges having value at most \p low
224  // are not added to the support graph.
225  // Parameter \p high defines an upper threshold, i.e all edges having value at least \p high,
226  // are added to the support graph.
227  // Edges having LP-value k that lies between \p low and \p high are added to the support graph
228  // randomly with a probability of k.
229  void kuratowskiSupportGraph(GraphCopy& support, double low, double high);
230 
231  // Computes the support graph for Connectivity- constraints according to the current LP-solution.
232  void connectivitySupportGraph(GraphCopy& support, EdgeArray<double>& weight);
233 
234  // Computes the integer solution induced Graph.
235  void intSolutionInducedGraph(GraphCopy& support);
236 
237  // Stores information about Kuratowski subdivision
238  // for violation check
239  struct KuraSize {
240  double lhs; //variable value sum
241  double varnum; //number of variables involved
242  };
243 
244  // Computes and returns the value of the lefthand side of the Kuratowski constraint
245  // induced by \p it and given support graph \p gc. Returns list of node pairs that
246  // correspond to connection edges in parameter \p subDivOrig.
248  SListPure<NodePair>& subDivOrig);
249 
250  // Updates the best known solution according to integer solution of this subproblem.
251  void updateSolution();
252 
253 
254  // The following four functions are used by the primal heuristic.
255 
256  int getArrayIndex(double lpValue);
257 
258  void childClusterSpanningTree(GraphCopy& GC, List<edgeValue>& clusterEdges,
259  List<NodePair>& MSTEdges);
260 
262  ClusterArray<List<edgeValue>>& clusterEdges);
263 
264  // Tries to improve the best primal solution by means of the current fractional LP-solution.
265  double heuristicImprovePrimalBound(List<NodePair>& connectionEdges);
266 
269  return addPoolCons(cons, static_cast<CPlanarityMaster*>(master_)->getCutConnPool());
270  }
271 
274  return addPoolCons(cons, static_cast<CPlanarityMaster*>(master_)->getCutKuraPool());
275  }
276 
277  //tries to regenerate connectivity cuts
278  inline int separateConnPool(double minViolation) {
279  return separateCutPool(static_cast<CPlanarityMaster*>(master_)->getCutConnPool(),
280  minViolation);
281  }
282 
283  //tries to regenerate kuratowski cuts
284  inline int separateKuraPool(double minViolation) {
285  return separateCutPool(static_cast<CPlanarityMaster*>(master_)->getCutKuraPool(),
286  minViolation);
287  }
288 };
289 
290 }
291 }
ogdf::ArrayBuffer< int >
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
abacus::Sub::constraintPoolSeparation
virtual int constraintPoolSeparation(int ranking=0, Pool< Constraint, Variable > *pool=nullptr, double minViolation=0.001)
Tries to generate inactive constraints from a pool.
ogdf::cluster_planarity::CPlanaritySub::selectBranchingVariable
virtual int selectBranchingVariable(int &variable) override
Chooses a branching variable.
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
ogdf::cluster_planarity::CPlanaritySub::getRepresentative
node getRepresentative(node v, NodeArray< node > &parent)
run through the pointer list parent and return the representative i.e. the node with parent[v] == v
Definition: CPlanaritySub.h:102
ogdf::cluster_planarity::CPlanaritySub::repair
int repair()
ogdf::cluster_planarity::CPlanaritySub::master
CPlanarityMaster * master()
Definition: CPlanaritySub.h:193
ogdf::cluster_planarity::CPlanaritySub
Definition: CPlanaritySub.h:60
Graph.h
Includes declaration of graph class.
abacus::BranchRule
Abstract base class for all branching rules.
Definition: branchrule.h:59
abacus.h
Includes Abacus.
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::cluster_planarity::CPlanaritySub::separateKuraPool
int separateKuraPool(double minViolation)
Definition: CPlanaritySub.h:284
ogdf::cluster_planarity::CPlanaritySub::clusterBags
int clusterBags(ClusterGraph &CG, cluster c)
ogdf::cluster_planarity::CPlanaritySub::pricing
virtual int pricing() override
Should generate inactive variables which do not price out correctly.
Definition: CPlanaritySub.h:156
abacus::Sub::branchRule
BranchRule * branchRule() const
Returns a pointer to the branching rule of the subproblem.
Definition: sub.h:355
ogdf::ClusterArrayBase
RegisteredArray for labeling the clusters of a ClusterGraph.
Definition: ClusterGraph.h:311
ogdf::SListIteratorBase
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:50
CPlanarityMaster.h
Declaration of the CPlanarityMaster class for the Branch&Cut algorithm for c-planarity testing via an...
ogdf::cluster_planarity::CPlanaritySub::myAddVars
void myAddVars(ArrayBuffer< abacus::Variable * > &b)
Definition: CPlanaritySub.h:209
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::cluster_planarity::CPlanaritySub::KuraSize
Definition: CPlanaritySub.h:239
ogdf::cluster_planarity::CPlanaritySub::m_constraintsFound
bool m_constraintsFound
Definition: CPlanaritySub.h:197
ogdf::cluster_planarity::CPlanaritySub::addKuraCons
int addKuraCons(ArrayBuffer< abacus::Constraint * > cons)
Adds the given constraints to the planarity cut pool.
Definition: CPlanaritySub.h:273
abacus::StandardPool< abacus::Constraint, abacus::Variable >
Logger.h
Contains logging functionality.
abacus::Sub::father
const Sub * father() const
Returns a pointer to the father of the subproblem in the branch-and-bound tree.
Definition: sub.h:198
ogdf::cluster_planarity::CPlanaritySub::addPoolCons
int addPoolCons(ArrayBuffer< abacus::Constraint * > &cons, abacus::StandardPool< abacus::Constraint, abacus::Variable > *pool)
Adds the given constraints to the given pool.
Definition: CPlanaritySub.h:182
abacus::Sub::variable
Variable * variable(int i) const
Returns a pointer to the i-th active variable.
Definition: sub.h:1863
ogdf::cluster_planarity::CPlanaritySub::getArrayIndex
int getArrayIndex(double lpValue)
ogdf::cluster_planarity::CPlanaritySub::optimize
virtual int optimize() override
Performs the optimization of the subproblem.
Definition: CPlanaritySub.h:85
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
ogdf::cluster_planarity::CPlanaritySub::separateConnPool
int separateConnPool(double minViolation)
Definition: CPlanaritySub.h:278
ogdf::cluster_planarity::CPlanaritySub::detectedInfeasibility
bool detectedInfeasibility
Definition: CPlanaritySub.h:198
r
int r[]
Definition: hierarchical-ranking.cpp:13
ogdf::cluster_planarity::CPlanaritySub::kuratowskiSupportGraph
void kuratowskiSupportGraph(GraphCopy &support, double low, double high)
ogdf::cluster_planarity::CPlanaritySub::CPlanaritySub
CPlanaritySub(abacus::Master *master)
ogdf::cluster_planarity::CPlanaritySub::connectivitySupportGraph
void connectivitySupportGraph(GraphCopy &support, EdgeArray< double > &weight)
abacus::Sub::master_
Master * master_
A pointer to the corresponding master of the optimization.
Definition: sub.h:1436
SList.h
Declaration of singly linked lists and iterators.
ogdf::cluster_planarity::CPlanaritySub::separateRealO
int separateRealO(double minViolate)
Definition: CPlanaritySub.h:133
ogdf::cluster_planarity::CPlanaritySub::solveLp
virtual int solveLp() override
Solves the LP-relaxation of the subproblem.
ogdf::cluster_planarity::CPlanaritySub::KuraSize::varnum
double varnum
Definition: CPlanaritySub.h:241
ogdf::cluster_planarity::CPlanaritySub::checkCConnectivityOld
bool checkCConnectivityOld(const GraphCopy &support)
ogdf::cluster_planarity::CPlanaritySub::separate
virtual int separate() override
Must be redefined in derived classes for the generation of cutting planes.
Definition: CPlanaritySub.h:149
ogdf::cluster_planarity::CPlanaritySub::m_sepFirst
bool m_sepFirst
Definition: CPlanaritySub.h:204
ogdf::cluster_planarity::CPlanaritySub::KuraSize::lhs
double lhs
Definition: CPlanaritySub.h:240
ogdf::ArrayBuffer::size
INDEX size() const
Returns number of elements in the buffer.
Definition: ArrayBuffer.h:244
ogdf::cluster_planarity::CPlanaritySub::checkCConnectivity
bool checkCConnectivity(const GraphCopy &support)
Checks if the cluster induced graphs and their complement are connected in the current solution.
ogdf::ArrayBuffer::push
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:217
ogdf::SListPure
Singly linked lists.
Definition: SList.h:52
ogdf::cluster_planarity::CPlanaritySub::intSolutionInducedGraph
void intSolutionInducedGraph(GraphCopy &support)
ogdf::cluster_planarity::CPlanaritySub::heuristicImprovePrimalBound
double heuristicImprovePrimalBound(List< NodePair > &connectionEdges)
ogdf::cluster_planarity::CPlanaritySub::subdivisionLefthandSide
KuraSize subdivisionLefthandSide(SListConstIterator< KuratowskiWrapper > it, GraphCopy *gc, SListPure< NodePair > &subDivOrig)
ogdf::cluster_planarity::CPlanaritySub::makeFeasible
virtual int makeFeasible() override
The default implementation of makeFeasible()does nothing.
Definition: CPlanaritySub.h:78
ogdf::List< abacus::Constraint * >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::cluster_planarity::CPlanaritySub::clusterSpanningTree
void clusterSpanningTree(ClusterGraph &C, cluster c, ClusterArray< List< NodePair >> &treeEdges, ClusterArray< List< edgeValue >> &clusterEdges)
ogdf::cluster_planarity::CPlanaritySub::m_reportCreation
int m_reportCreation
Definition: CPlanaritySub.h:203
abacus::Sub::id
int id() const
Returns the identity number of the subproblem.
Definition: sub.h:153
abacus::Sub::removeNonLiftableCons
virtual bool removeNonLiftableCons()
ogdf::cluster_planarity::CPlanaritySub::addCutCons
int addCutCons(ArrayBuffer< abacus::Constraint * > cons)
Adds the given constraints to the connectivity cut pool.
Definition: CPlanaritySub.h:268
abacus::Sub::optimize
virtual int optimize()
Performs the optimization of the subproblem.
ogdf::cluster_planarity::CPlanarityMaster
Definition: CPlanarityMaster.h:62
ogdf::cluster_planarity::CPlanaritySub::criticalSinceBranching
List< abacus::Constraint * > criticalSinceBranching
Definition: CPlanaritySub.h:205
basic.h
Basic declarations, included by all source files.
abacus::Sub
The subproblem.
Definition: sub.h:68
ogdf::cluster_planarity::CPlanaritySub::bufferedForCreation
ArrayBuffer< abacus::Constraint * > bufferedForCreation
Definition: CPlanaritySub.h:206
ogdf::cluster_planarity::CPlanaritySub::~CPlanaritySub
virtual ~CPlanaritySub()
ogdf::cluster_planarity::CPlanaritySub::feasible
virtual bool feasible() override
Must check the feasibility of a solution of the LP-relaxation.
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
ogdf::cluster_planarity::CPlanaritySub::selectBranchingVariableCandidates
virtual int selectBranchingVariableCandidates(ArrayBuffer< int > &candidates) override
Selects candidates for branching variables.
List.h
Declaration of doubly linked lists and iterators.
abacus::Sub::addCons
virtual int addCons(ArrayBuffer< Constraint * > &constraints, Pool< Constraint, Variable > *pool=nullptr, ArrayBuffer< bool > *keepInPool=nullptr, ArrayBuffer< double > *rank=nullptr)
Tries to add new constraints to the constraint buffer and a pool.
ogdf::cluster_planarity::CPlanaritySub::improve
virtual int improve(double &primalValue) override
Can be redefined in order to implement primal heuristics for finding feasible solutions.
abacus::Sub::addVars
virtual int addVars(ArrayBuffer< Variable * > &variables, Pool< Variable, Constraint > *pool=nullptr, ArrayBuffer< bool > *keepInPool=nullptr, ArrayBuffer< double > *rank=nullptr)
Tries to add new variables to the variable buffer and a pool.
ogdf::cluster_planarity::CPlanaritySub::realDualBound
double realDualBound
Definition: CPlanaritySub.h:200
ogdf::cluster_planarity::CPlanaritySub::separateReal
int separateReal(double minViolate)
these functions are mainly reporting to let abacus think everthing is normal.
ogdf::cluster_planarity
Definition: basics.h:42
ogdf::cluster_planarity::CPlanaritySub::createVariablesForBufferedConstraints
int createVariablesForBufferedConstraints()
ogdf::cluster_planarity::CPlanaritySub::inOrigSolveLp
bool inOrigSolveLp
Definition: CPlanaritySub.h:199
ogdf::cluster_planarity::CPlanaritySub::childClusterSpanningTree
void childClusterSpanningTree(GraphCopy &GC, List< edgeValue > &clusterEdges, List< NodePair > &MSTEdges)
abacus::Sub::dualBound
double dualBound() const
Returns a bound which is "better" than the optimal solution of the subproblem w.r....
Definition: sub.h:181
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::cluster_planarity::CP_MasterBase::m_varsPrice
int m_varsPrice
Definition: CP_MasterBase.h:306
ogdf::Logger::slout
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:193
ogdf::cluster_planarity::CPlanaritySub::separateCutPool
int separateCutPool(abacus::StandardPool< abacus::Constraint, abacus::Variable > *pool, double minViolation)
Definition: CPlanaritySub.h:187
ogdf::cluster_planarity::CPlanaritySub::generateSon
virtual abacus::Sub * generateSon(abacus::BranchRule *rule) override
Returns a pointer to an object of a problem specific subproblem, which is generated from the current ...
abacus::Master
The master of the optimization.
Definition: master.h:69
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::cluster_planarity::CPlanaritySub::updateSolution
void updateSolution()