Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

MaxCPlanarSub.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 MaxCPlanarSub : public abacus::Sub {
61 public:
64  List<abacus::Constraint*>& criticalConstraints);
65 
66  virtual ~MaxCPlanarSub();
67 
68  // Creation of a child-node in the Branch&Bound tree according to the
69  // branching rule #rule
70  virtual abacus::Sub* generateSon(abacus::BranchRule* rule) override;
71 
72 
73 protected:
74  // Checks if the current solution of the LP relaxation is also a feasible solution to the ILP,
75  // i.e. Integer-feasible + satisfying all Kuratowski- and Cut-constraints.
76  virtual bool feasible() override;
77 
78  // to trick Sub::solveLp...
79  virtual int makeFeasible() override { return 0; }
80 #if 0
81  // to trick Sub::solveLp into returning 2
82  virtual int removeNonLiftableCons() { return 0; }
83 #endif
84  int repair();
85 
86  virtual int optimize() override {
87  Logger::slout() << "OPTIMIZE BEGIN\tNode=" << this->id() << "\n";
88  int ret = abacus::Sub::optimize();
89  Logger::slout() << "OPTIMIZE END\tNode=" << this->id() << " db=" << dualBound()
90  << "\tReturn=" << (ret ? "(error)" : "(ok)") << "\n";
91  return ret;
92  }
93 
94  //functions for testing properties of the clustered graph
95 
98  bool checkCConnectivity(const GraphCopy& support);
99  bool checkCConnectivityOld(const GraphCopy& support);
100 
104  while (v != parent[v]) {
105  v = parent[v];
106  }
107  return v;
108  }
109 
110  // Todo: Think about putting this into extended_graph_alg.h to make it
111  // publically available
112  int clusterBags(ClusterGraph& CG, cluster c);
113 
114 #if 0
115  // using the below two functions iunstead (and instead of solveLp) we would get a more traditional situation
116  virtual int separate() {
117  return separateRealO(0.001);
118  }
119  virtual int pricing() {
120  return pricingRealO(0.001);
121  }
122 #endif
123 
129  int separateReal(double minViolate);
130 #if 0
131  int pricingReal(double minViolate);
132 #endif
133 
134  inline int separateRealO(double minViolate) {
135  Logger::slout() << "\tSeparate (minViolate=" << minViolate << ")..";
136  int r = separateReal(minViolate);
137  Logger::slout() << "..done: " << r << "\n";
138  return r;
139  }
140 #if 0
141  inline int pricingRealO(double minViolate) {
142  Logger::slout() << "\tPricing (minViolate=" << minViolate << ")..";
143  int r = pricingReal(minViolate);
144  master()->m_varsPrice += r;
145  Logger::slout() << "..done: " << r << "\n";
146  return r;
147  }
148 #endif
149 
150  virtual int separate() override {
151  Logger::slout()
152  << "\tReporting Separation: " << ((m_reportCreation > 0) ? m_reportCreation : 0)
153  << "\n";
154  return (m_reportCreation > 0) ? m_reportCreation : 0;
155  }
156 
157  virtual int pricing() override {
158  if (inOrigSolveLp) {
159  return 1;
160  }
161  Logger::slout()
162  << "\tReporting Prizing: " << ((m_reportCreation < 0) ? -m_reportCreation : 0)
163  << "\n";
164  return (m_reportCreation < 0) ? -m_reportCreation : 0;
165  }
166 
167  virtual int solveLp() override;
168 
169  // Implementation of virtual function improve() inherited from ABA::SUB.
170  // Invokes the function heuristicImprovePrimalBound().
171  // Tthis function belongs to the ABACUS framework. It is invoked after each separation-step.
172  // Since the heuristic is rather time consuming and because it is not very advantageous
173  // to run the heuristic even if additional constraints have been found, the heuristic
174  // is run "by hand" each time no further constraints coud be found, i.e. after having solved
175  // the LP-relaxation optimally.
176  virtual int improve(double& primalValue) override;
177 
178  // Two functions inherited from ABACUS and overritten to manipulate the branching behaviour.
179  virtual int selectBranchingVariableCandidates(ArrayBuffer<int>& candidates) override;
180  virtual int selectBranchingVariable(int& variable) override;
181 
185  return (master()->useDefaultCutPool()) ? addCons(cons) : addCons(cons, pool);
186  }
187 
189  double minViolation) {
190  return (master()->useDefaultCutPool()) ? 0 : constraintPoolSeparation(0, pool, minViolation);
191  }
192 
193 private:
194  MaxCPlanarMaster* master() const { return static_cast<MaxCPlanarMaster*>(master_); }
195 
196  // A flag indicating if constraints have been found in the current separation step.
197  // Is used to check, if the primal heuristic should be run or not.
202 
203  // used for the steering in solveLp
209 
211  int num = b.size();
212  ArrayBuffer<bool> keep(num, false);
213  for (int i = num; i-- > 0;) {
214  keep.push(true);
215  }
216 #ifdef OGDF_DEBUG
217  int r =
218 #endif
219  addVars(b, nullptr, &keep);
220  OGDF_ASSERT(r == num);
221  }
222 
223  // Computes the support graph for Kuratowski- constraints according to the current LP-solution.
224  // Parameter \p low defines a lower threshold, i.e all edges having value at most \p low
225  // are not added to the support graph.
226  // Parameter \p high defines an upper threshold, i.e all edges having value at least \p high,
227  // are added to the support graph.
228  // Edges having LP-value k that lies between \p low and \p high are added to the support graph
229  // randomly with a probability of k.
230  void kuratowskiSupportGraph(GraphCopy& support, double low, double high);
231 
232  // Computes the support graph for Connectivity- constraints according to the current LP-solution.
233  void connectivitySupportGraph(GraphCopy& support, EdgeArray<double>& weight);
234 
235  // Computes the integer solution induced Graph.
236  void intSolutionInducedGraph(GraphCopy& support);
237 
238  // Computes and returns the value of the lefthand side of the Kuratowski constraint
239  // induced by \p it and given support graph \p gc.
241 
242  // Updates the best known solution according to integer solution of this subproblem.
243  void updateSolution();
244 
245 
246  // The following four functions are used by the primal heuristic.
247 
248  int getArrayIndex(double lpValue);
249 
250  void childClusterSpanningTree(GraphCopy& GC, List<edgeValue>& clusterEdges,
251  List<NodePair>& MSTEdges);
252 
254  ClusterArray<List<edgeValue>>& clusterEdges);
255 
256  // Tries to improve the best primal solution by means of the current fractional LP-solution.
257  double heuristicImprovePrimalBound(List<NodePair>& originalEdges,
258  List<NodePair>& connectionEdges, List<edge>& deletedEdges);
259 
262  return addPoolCons(cons, static_cast<MaxCPlanarMaster*>(master_)->getCutConnPool());
263  }
264 
267  return addPoolCons(cons, static_cast<MaxCPlanarMaster*>(master_)->getCutKuraPool());
268  }
269 
270  //tries to regenerate connectivity cuts
271  inline int separateConnPool(double minViolation) {
272  return separateCutPool(static_cast<MaxCPlanarMaster*>(master_)->getCutConnPool(),
273  minViolation);
274  }
275 
276  //tries to regenerate kuratowski cuts
277  inline int separateKuraPool(double minViolation) {
278  return separateCutPool(static_cast<MaxCPlanarMaster*>(master_)->getCutKuraPool(),
279  minViolation);
280  }
281 #if 0
282  void minimumSpanningTree(
283  GraphCopy &GC,
284  List<NodePair> &clusterEdges,
285  List<NodePair> &MSTEdges);
286 
287  void recursiveMinimumSpanningTree(
288  ClusterGraph &C,
289  cluster c,
290  ClusterArray<List<NodePair> > &treeEdges,
291  List<NodePair> &edgesByIncLPValue,
292  List<node> &clusterNodes);
293 
294  double heuristicImprovePrimalBoundDet(
295  List<NodePair> &origEdges,
296  List<NodePair> &conEdges,
297  List<NodePair> &delEdges);
298 #endif
299 };
300 
301 }
302 }
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.
ArrayBuffer.h
Declaration and implementation of ArrayBuffer class.
ogdf::cluster_planarity::MaxCPlanarSub::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 ...
Graph.h
Includes declaration of graph class.
ogdf::cluster_planarity::MaxCPlanarSub::detectedInfeasibility
bool detectedInfeasibility
Definition: MaxCPlanarSub.h:199
ogdf::cluster_planarity::MaxCPlanarSub::selectBranchingVariableCandidates
virtual int selectBranchingVariableCandidates(ArrayBuffer< int > &candidates) override
Selects candidates for branching variables.
ogdf::cluster_planarity::MaxCPlanarSub
Definition: MaxCPlanarSub.h:60
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::MaxCPlanarSub::clusterBags
int clusterBags(ClusterGraph &CG, cluster c)
ogdf::cluster_planarity::MaxCPlanarSub::feasible
virtual bool feasible() override
Must check the feasibility of a solution of the LP-relaxation.
ogdf::cluster_planarity::MaxCPlanarSub::improve
virtual int improve(double &primalValue) override
Can be redefined in order to implement primal heuristics for finding feasible solutions.
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
ogdf::cluster_planarity::MaxCPlanarSub::m_constraintsFound
bool m_constraintsFound
Definition: MaxCPlanarSub.h:198
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::cluster_planarity::MaxCPlanarSub::separateRealO
int separateRealO(double minViolate)
Definition: MaxCPlanarSub.h:134
ogdf::cluster_planarity::MaxCPlanarSub::repair
int repair()
ogdf::cluster_planarity::MaxCPlanarSub::separateConnPool
int separateConnPool(double minViolation)
Definition: MaxCPlanarSub.h:271
ogdf::cluster_planarity::MaxCPlanarSub::checkCConnectivityOld
bool checkCConnectivityOld(const GraphCopy &support)
ogdf::cluster_planarity::MaxCPlanarSub::solveLp
virtual int solveLp() override
Solves the LP-relaxation of the subproblem.
ogdf::cluster_planarity::MaxCPlanarSub::getArrayIndex
int getArrayIndex(double lpValue)
ogdf::cluster_planarity::MaxCPlanarSub::subdivisionLefthandSide
double subdivisionLefthandSide(SListConstIterator< KuratowskiWrapper > it, GraphCopy *gc)
ogdf::cluster_planarity::MaxCPlanarSub::connectivitySupportGraph
void connectivitySupportGraph(GraphCopy &support, EdgeArray< double > &weight)
ogdf::cluster_planarity::MaxCPlanarSub::addCutCons
int addCutCons(ArrayBuffer< abacus::Constraint * > cons)
Adds the given constraints to the connectivity cut pool.
Definition: MaxCPlanarSub.h:261
ogdf::cluster_planarity::MaxCPlanarSub::clusterSpanningTree
void clusterSpanningTree(ClusterGraph &C, cluster c, ClusterArray< List< NodePair >> &treeEdges, ClusterArray< List< edgeValue >> &clusterEdges)
ogdf::cluster_planarity::MaxCPlanarSub::myAddVars
void myAddVars(ArrayBuffer< abacus::Variable * > &b)
Definition: MaxCPlanarSub.h:210
ogdf::cluster_planarity::MaxCPlanarSub::separateCutPool
int separateCutPool(abacus::StandardPool< abacus::Constraint, abacus::Variable > *pool, double minViolation)
Definition: MaxCPlanarSub.h:188
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
abacus::Sub::variable
Variable * variable(int i) const
Returns a pointer to the i-th active variable.
Definition: sub.h:1863
ogdf::cluster_planarity::MaxCPlanarSub::intSolutionInducedGraph
void intSolutionInducedGraph(GraphCopy &support)
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
ogdf::cluster_planarity::MaxCPlanarMaster
Definition: MaxCPlanarMaster.h:67
ogdf::cluster_planarity::MaxCPlanarSub::checkCConnectivity
bool checkCConnectivity(const GraphCopy &support)
Checks if the cluster induced graphs and their complement are connected in the current solution.
r
int r[]
Definition: hierarchical-ranking.cpp:13
ogdf::cluster_planarity::MaxCPlanarSub::criticalSinceBranching
List< abacus::Constraint * > criticalSinceBranching
Definition: MaxCPlanarSub.h:206
ogdf::cluster_planarity::MaxCPlanarSub::inOrigSolveLp
bool inOrigSolveLp
Definition: MaxCPlanarSub.h:200
ogdf::cluster_planarity::MaxCPlanarSub::master
MaxCPlanarMaster * master() const
Definition: MaxCPlanarSub.h:194
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::MaxCPlanarSub::addKuraCons
int addKuraCons(ArrayBuffer< abacus::Constraint * > cons)
Adds the given constraints to the planarity cut pool.
Definition: MaxCPlanarSub.h:266
ogdf::cluster_planarity::MaxCPlanarMaster::m_varsPrice
int m_varsPrice
Definition: MaxCPlanarMaster.h:304
ogdf::ArrayBuffer::size
INDEX size() const
Returns number of elements in the buffer.
Definition: ArrayBuffer.h:244
ogdf::ArrayBuffer::push
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:217
ogdf::cluster_planarity::MaxCPlanarSub::kuratowskiSupportGraph
void kuratowskiSupportGraph(GraphCopy &support, double low, double high)
MaxCPlanarMaster.h
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
ogdf::List< abacus::Constraint * >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
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::MaxCPlanarSub::separateReal
int separateReal(double minViolate)
these functions are mainly reporting to let abacus think everthing is normal.
ogdf::cluster_planarity::MaxCPlanarSub::separate
virtual int separate() override
Must be redefined in derived classes for the generation of cutting planes.
Definition: MaxCPlanarSub.h:150
ogdf::cluster_planarity::MaxCPlanarSub::optimize
virtual int optimize() override
Performs the optimization of the subproblem.
Definition: MaxCPlanarSub.h:86
ogdf::cluster_planarity::MaxCPlanarSub::separateKuraPool
int separateKuraPool(double minViolation)
Definition: MaxCPlanarSub.h:277
abacus::Sub::optimize
virtual int optimize()
Performs the optimization of the subproblem.
ogdf::cluster_planarity::MaxCPlanarSub::childClusterSpanningTree
void childClusterSpanningTree(GraphCopy &GC, List< edgeValue > &clusterEdges, List< NodePair > &MSTEdges)
ogdf::cluster_planarity::MaxCPlanarSub::m_sepFirst
bool m_sepFirst
Definition: MaxCPlanarSub.h:205
ogdf::cluster_planarity::MaxCPlanarSub::~MaxCPlanarSub
virtual ~MaxCPlanarSub()
basic.h
Basic declarations, included by all source files.
abacus::Sub
The subproblem.
Definition: sub.h:68
ogdf::cluster_planarity::MaxCPlanarSub::realDualBound
double realDualBound
Definition: MaxCPlanarSub.h:201
ogdf::cluster_planarity::MaxCPlanarSub::updateSolution
void updateSolution()
ogdf::cluster_planarity::MaxCPlanarSub::MaxCPlanarSub
MaxCPlanarSub(abacus::Master *master)
ogdf::cluster_planarity::MaxCPlanarSub::createVariablesForBufferedConstraints
int createVariablesForBufferedConstraints()
ogdf::cluster_planarity::MaxCPlanarSub::selectBranchingVariable
virtual int selectBranchingVariable(int &variable) override
Chooses a branching variable.
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
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.
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::MaxCPlanarSub::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: MaxCPlanarSub.h:103
ogdf::cluster_planarity
Definition: basics.h:42
ogdf::cluster_planarity::MaxCPlanarSub::m_reportCreation
int m_reportCreation
Definition: MaxCPlanarSub.h:204
ogdf::cluster_planarity::MaxCPlanarSub::bufferedForCreation
ArrayBuffer< abacus::Constraint * > bufferedForCreation
Definition: MaxCPlanarSub.h:207
ogdf::cluster_planarity::MaxCPlanarSub::heuristicImprovePrimalBound
double heuristicImprovePrimalBound(List< NodePair > &originalEdges, List< NodePair > &connectionEdges, List< edge > &deletedEdges)
ogdf::cluster_planarity::MaxCPlanarSub::pricing
virtual int pricing() override
Should generate inactive variables which do not price out correctly.
Definition: MaxCPlanarSub.h:157
ogdf::cluster_planarity::MaxCPlanarSub::makeFeasible
virtual int makeFeasible() override
The default implementation of makeFeasible()does nothing.
Definition: MaxCPlanarSub.h:79
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::Logger::slout
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:193
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::MaxCPlanarSub::addPoolCons
int addPoolCons(ArrayBuffer< abacus::Constraint * > &cons, abacus::StandardPool< abacus::Constraint, abacus::Variable > *pool)
Adds the given constraints to the given pool.
Definition: MaxCPlanarSub.h:183