Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

CPlanarityMaster.h
Go to the documentation of this file.
1 
36 #pragma once
37 
38 #include <ogdf/basic/GraphCopy.h>
39 #include <ogdf/basic/Logger.h>
40 #include <ogdf/basic/ArrayBuffer.h>
41 
46 
47 namespace ogdf {
48 namespace cluster_planarity {
49 
51 
52  friend class CPlanaritySub;
53 
54 #if 0
55  const ClusterGraph *m_C;
57  const Graph *m_G;
58 
59 
63 
64  List<nodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
65 #endif
66 
67 public:
68 
69  // Construction and default values
70  explicit CPlanarityMaster(const ClusterGraph &C,
71  //Check what we really still need here
72  int heuristicLevel=0,
73  int heuristicRuns=2,
74  double heuristicOEdgeBound=0.3,
75  int heuristicNPermLists=5,
76  int kuratowskiIterations=3,
77  int subdivisions=10,
78  int kSupportGraphs=3,
79  double kuratowskiHigh=0.75,
80  double kuratowskiLow=0.3,
81  bool perturbation=false,
82  double branchingGap=0.4,
83  const char *time="00:20:00" /* maximum computation time */ );
84 
86  virtual ~CPlanarityMaster();
87 
88  // Initialization of the first Subproblem
89  virtual abacus::Sub *firstSub() override;
90 
91  // Returns the number of variables
92  int nMaxVars() const {return m_nMaxVars;}
93 
94  // Returns a pointer to the underlying Graph
95  const Graph *getGraph() const {return m_G;}
96 
97  // Returns a pointer to the given Clustergraph.
98  const ClusterGraph *getClusterGraph() const {return m_C;}
99 
100  // Returns a pointer on the search space graph, which is
101  // a copy of the input graph with all edges added that
102  // correspond to variables add at initialization.
103  // Be aware that this is not dynamically updated, e.g. for pricing.
104 
105  const GraphCopy *searchSpaceGraph() const {return m_ssg; }
106  // Updates the "best" Subgraph #m_solutionGraph found so far and fills edge lists with
107  // corresponding edges (nodePairs).
108  void updateBestSubGraph(List<NodePair> &connection) override;
109 
110  // Returns the optimal solution induced Clustergraph
111  Graph *solutionInducedGraph() override {return static_cast<Graph*>(m_solutionGraph);}
112 
113  // Returns nodePairs of connecting optimal solution edges in list \p edges.
114  void getConnectionOptimalSolutionEdges(List<NodePair> &egdes) const override;
115 
116  // Get parameters
118  int getNSubdivisions() const {return m_nSubdivisions;}
120  int getHeuristicLevel() const {return m_heuristicLevel;}
121  int getHeuristicRuns() const {return m_nHeuristicRuns;}
122  double getKBoundHigh() const {return m_kuratowskiBoundHigh;}
123  double getKBoundLow() const {return m_kuratowskiBoundLow;}
124  bool perturbation() const {return m_usePerturbation;}
125  double branchingOEdgeSelectGap() const {return m_branchingGap;}
128  bool getMPHeuristic() const {return m_mpHeuristic;}
129  int getNumAddVariables() const {return m_numAddVariables;}
132 
133 #if 0
134  // Read global constraint counter, i.e. the number of added constraints of specific type.
135  int addedKConstraints() const {return m_nKConsAdded;}
136  int addedCConstraints() const {return m_nCConsAdded;}
137 #endif
138 
139 
140  // Set parameters
145  void setKBoundHigh(double n) {m_kuratowskiBoundHigh = ((n>0.0 && n<1.0) ? n : 0.8);}
146  void setKBoundLow(double n) {m_kuratowskiBoundLow = ((n>0.0 && n<1.0) ? n : 0.2);}
147  void heuristicLevel(int level) {m_heuristicLevel = level;}
149  void setPertubation(bool b) {m_usePerturbation = b;}
152  void setMPHeuristic(bool b) {m_mpHeuristic = b;}
156  void setSearchSpaceShrinking(bool b) {m_shrink = b;}
157 
158 #if 0
159  void updateAddedCCons(int n) {m_nCConsAdded += n;}
161  void updateAddedKCons(int n) {m_nKConsAdded += n;}
162 
164  double getPrimalBound() {return globalPrimalBound;}
165  double getDualBound() {return globalDualBound;}
166 
167  // Cut pools for connectivity and planarity
169  StandardPool<Constraint, Variable> *getCutConnPool() {return m_cutConnPool;}
171  StandardPool<Constraint, Variable> *getCutKuraPool() {return m_cutKuraPool;}
172 
175  bool &useDefaultCutPool() { return m_useDefaultCutPool;}
176 #endif
177 
178 #ifdef OGDF_DEBUG
179  bool m_solByHeuristic;
181 
184  void printGraph(const Graph &G);
185 #endif
186 
190  {
191  return "StdConstraints.txt";
192  }
193 
194  int getNumInactiveVars() { return m_inactiveVariables.size();}
195 
198  return m_cNodes[c];
199  }
202  void getClusterNodes(cluster c, List<node> &nodeList) const {
203  ListConstIterator<node> it = m_cNodes[c].begin();
204  while (it.valid())
205  {
206  nodeList.pushBack(*it);
207  ++it;
208  }
209  }
210 
211 protected:
212 
213  // Initializes constraints and variables and an initial dual bound.
214  virtual void initializeOptimization() override;
215 
216  // Function that is invoked at the end of the optimization
217  virtual void terminateOptimization() override;
218 
219  double heuristicInitialLowerBound() override;
220 
223  void createInitialVariables(List<CPlanarEdgeVar*>& initVars) override;
224 
226  void addInnerConnections(cluster c, List<CPlanarEdgeVar*>& connectVars);
227 
231 
232 
233  bool isCP() override {return feasibleFound();}//(dualBound()!=-infinity());}
234 
236  bool goodVar(node a, node b) override;
237 
238 private:
239 
244  double heuristicInitialUpperBound() override;
245 
247  double clusterConnection(cluster c, GraphCopy &GC) override;
248 
250  void createCompConnVars(List<CPlanarEdgeVar*>& initVars) override;
251 
253  void nodeDistances(node u, NodeArray<NodeArray<int> > &dist) override;
254 
255 
256  // Parameters
257 #if 0
258  int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
259  int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
260  int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
261  int m_nMaxVars; // Max Number of variables
262  int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
263  int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
264 
265  bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
266  double m_branchingGap; // Modifies the branching behaviour
268  int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
269  bool m_mpHeuristic;
270  // should be used to derive lower bound if only root cluster exists
271 
272  double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
273  double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
274 
275  int m_numAddVariables; // how many variables should i add maximally per pricing round?
276  double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
277  double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
278 
279  AbaString *m_maxCpuTime; // Time threshold for optimization
280 
283  double m_largestConnectionCoeff;
284 
285  // Counters for the number of added constraints
286  int m_nCConsAdded;
287  int m_nKConsAdded;
288  int m_solvesLP;
289  int m_varsInit;
290  int m_varsAdded;
291  int m_varsPotential;
292  int m_varsMax;
293  int m_varsCut;
294  int m_varsKura;
295  int m_varsPrice;
296  int m_varsBranch;
297  int m_activeRepairs;
299  inline void clearActiveRepairs() {
300  if(m_activeRepairs) {
301  m_repairStat.push(m_activeRepairs);
302  m_activeRepairs = 0;
303  }
304  }
305 
306  double globalPrimalBound;
307  double globalDualBound;
308 
309  inline double getDoubleTime(const Stopwatch* act) {
310  long tempo = act->centiSeconds()+100*act->seconds()+6000*act->minutes()+360000*act->hours();
311  return ((double) tempo)/ 100.0;
312  }
313 
315  const int m_fastHeuristicRuns;
316 
318  StandardPool< Constraint, Variable > *m_cutConnPool;
319  StandardPool< Constraint, Variable > *m_cutKuraPool;
320 
323  bool m_useDefaultCutPool;
324 
325  double m_delta;
326  double m_deltaCount;
327 #endif
328 
330  virtual double nextConnectCoeff() override {return 1.0;}
331 #if 0
332  double nextConnectCoeff() { return -1 + m_deltaCount--*m_delta; };
333 #endif
334  virtual CPlanarEdgeVar* createVariable(ListIterator<NodePair>& it) override {
336  ++m_varsAdded;
337  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
338  v->printMe(Logger::slout());
339  m_inactiveVariables.del(it);
340  //we don't need to check symmetry
341  m_varCreated[(*it).source][(*it).target] = true;
342  return v;
343  }
345  virtual CPlanarEdgeVar* createVariable(node a, node b, double lbound) {
346  OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
347  ++m_varsAdded;
348  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), lbound, a, b);
349  v->printMe(Logger::slout());
350  //we don't need to check symmetry
351  m_varCreated[a][b] = true;
352  return v;
353  }
355  virtual CPlanarEdgeVar* createVariable(node a, node b) override {
356  OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
357  ++m_varsAdded;
358  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
359  v->printMe(Logger::slout());
360  //we don't need to check symmetry
361  m_varCreated[a][b] = true;
362  return v;
363  }
364 
365 #if 0
367 #endif
368 
369  //used in initialization
370  virtual void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
371 
372 #if 0
375 #endif
376 
379  virtual void getCoefficients(abacus::Constraint* con, const List<CPlanarEdgeVar* > & connect,
380  List<double> & coeffs) override;
381 
385 
389  bool m_shrink;
391  int m_nSep;
393 };
394 
395 }
396 }
virtual CPlanarEdgeVar * createVariable(node a, node b, double lbound)
Variable creation for pair of nodes with lower bound.
void addExternalConnections(cluster c, List< CPlanarEdgeVar *> &connectVars)
Create variables for external cluster connections in case we search only in the bag-reduced search sp...
void printMe(ostream &out) override
const ClusterGraph * m_C
Pointers to the given Clustergraph and underlying Graph are stored.
void addInnerConnections(cluster c, List< CPlanarEdgeVar *> &connectVars)
Adds inner cluster connection variables in bag-reduced search space.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
const GraphCopy * searchSpaceGraph() const
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
virtual double nextConnectCoeff() override
Switch to minimization of additional edges, no delta necessary.
Declaration and implementation of ArrayBuffer class.
bool m_mpHeuristic
Indicates if simple max planar subgraph heuristic.
int m_nSep
Stores number of separation calls.
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition: Stopwatch.h:121
double getDoubleTime(const Stopwatch *act)
The subproblem.
Definition: sub.h:68
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:95
const List< node > & getClusterNodes(cluster c) const
Returns reference to cluster nodes member list for c.
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:107
CPlanarityMaster(const ClusterGraph &C, int heuristicLevel=0, int heuristicRuns=2, double heuristicOEdgeBound=0.3, int heuristicNPermLists=5, int kuratowskiIterations=3, int subdivisions=10, int kSupportGraphs=3, double kuratowskiHigh=0.75, double kuratowskiLow=0.3, bool perturbation=false, double branchingGap=0.4, const char *time="00:20:00")
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutConnPool()
Returns cut pool for connectivity.
virtual void initializeOptimization() override
The default implementation of initializeOptimization() does nothing.
void createInitialVariables(List< CPlanarEdgeVar *> &initVars) override
All variables that have to be present at start of optimization are created here. Their number is retu...
virtual ~CPlanarityMaster()
Destruction.
ClusterAnalysis * m_ca
Used to check if variables are truly needed wrt to search space reduction (Chimani/Klein) ...
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
virtual abacus::Sub * firstSub() override
Should return a pointer to the first subproblem of the optimization, i.e., the root node of the enume...
void getConnectionOptimalSolutionEdges(List< NodePair > &egdes) const override
Returns nodePairs of connecting optimal solution edges in list edges.
double heuristicInitialUpperBound() override
Computes a dual bound for the optimal solution. Tries to find as many edge-disjoint Kuratowski subdiv...
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
bool m_useDefaultCutPool
Defines if the ABACUS default cut pool or the separate Connectivity and Kuratowski constraint pools a...
Representation of clustered graphs.
Definition: ClusterGraph.h:291
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
Declaration of the ClusterAnalysis class for the Branch&Cut algorithm for c-planarity testing via an ...
const ClusterGraph * getClusterGraph() const
Contains logging functionality.
virtual CPlanarEdgeVar * createVariable(ListIterator< NodePair > &it) override
Variable creation for nodePair.
const char * getStdConstraintsFileName()
The name of the file that contains the standard, i.e., non-cut, constraints (may be deleted by ABACUS...
void nodeDistances(node u, NodeArray< NodeArray< int > > &dist) override
Computes the graphtheoretical distances of edges incident to node u.
bool feasibleFound() const
We use this function, e.g., to adapt the enumeration strategy in the DiveAndBest-Strategy.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
Declaration of base class for master of Branch&Cut based algorithms for c-planarity testing via an ex...
Declaration of graph copy classes.
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutConnPool
Cut pools for connectivity and Kuratowski constraints.
Dynamic arrays indexed with clusters.
Definition: ClusterArray.h:110
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
Declaration of the variable class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph prob...
List< NodePair > m_connectionOneEdges
stores optimization success state
Class for the representation of nodes.
Definition: Graph_d.h:167
ClusterArray< List< node > > m_cNodes
Static storage of cluster node lists to avoid repeated computation.
bool isCP() override
Derives and returns c-planarity property either directly or indirectly from computation results...
Encapsulates a pointer to a list element.
Definition: List.h:41
virtual void generateVariablesForFeasibility(const List< ChunkConnection *> &ccons, List< CPlanarEdgeVar *> &connectVars)
void updateBestSubGraph(List< NodePair > &connection) override
Updates the "best" Subgraph m_solutionGraph found so far and fills connection with.
static std::ostream & slout(Level l=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
double clusterConnection(cluster c, GraphCopy &GC) override
Is invoked by heuristicInitialLowerBound()
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
GraphCopy * m_ssg
Search space graph, input graph plus edges modelled by initial variables.
NodeArray< NodeArray< bool > > m_varCreated
Keeps track of variables that are currently inactive during optimization.
virtual void terminateOptimization() override
Function that is invoked at the end of the optimization. Does nothing but output in CP_MasterBase...
void getClusterNodes(cluster c, List< node > &nodeList) const
Copies cluster nodes from member list to parameter list. Should be used if node list needs to be alte...
virtual CPlanarEdgeVar * createVariable(node a, node b) override
Variable creation for pair of nodes which is not stored in m_inactiveVariables.
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition: Stopwatch.h:114
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutKuraPool
Kuratowski Cuts.
bool goodVar(node a, node b) override
Node pair is potential candidate for new edge variable.
int m_nKuratowskiSupportGraphs
Keeps track of created variables.
int64_t hours() const
Returns the currently elapsed time in hours.
Definition: Stopwatch.h:128
bool & useDefaultCutPool()
Returns true if default cut pool is used. Otherwise, separate connectivity and Kuratowski pools are g...
The namespace for all OGDF objects.
void createCompConnVars(List< CPlanarEdgeVar *> &initVars) override
Creates variables for complete connectivity.
Graph * solutionInducedGraph() override
Returns the optimal solution induced Clustergraph.
void setMPHeuristic(bool b)
Switches use of lower bound heuristic.
bool m_shrink
If set to true, search space reduction is performed. Reduction is only feasible when only a single in...
void setSearchSpaceShrinking(bool b)
Toggles reduction of search space (using only some bag/satchel connections) on/off.
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
string * m_maxCpuTime
Time threshold for optimization.
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112
Realizes a stopwatch for measuring elapsed time.
Definition: Stopwatch.h:43
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
virtual void getCoefficients(abacus::Constraint *con, const List< CPlanarEdgeVar * > &connect, List< double > &coeffs) override
writes coefficients of all orig and connect variables in constraint con into emptied list coeffs ...