Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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