Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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