Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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;}
153  void setMPHeuristic(bool b) {m_mpHeuristic = b;}
158  void setSearchSpaceShrinking(bool b) {m_shrink = b;}
159 
160 #if 0
161  void updateAddedCCons(int n) {m_nCConsAdded += n;}
163  void updateAddedKCons(int n) {m_nKConsAdded += n;}
164 
166  double getPrimalBound() {return globalPrimalBound;}
167  double getDualBound() {return globalDualBound;}
168 
169  // Cut pools for connectivity and planarity
171  StandardPool<Constraint, Variable> *getCutConnPool() {return m_cutConnPool;}
173  StandardPool<Constraint, Variable> *getCutKuraPool() {return m_cutKuraPool;}
174 
177  bool &useDefaultCutPool() { return m_useDefaultCutPool;}
178 #endif
179 
180 #ifdef OGDF_DEBUG
181  void printGraph(const Graph &G);
184 #endif
185 
189  {
190  return "StdConstraints.txt";
191  }
192 
193  int getNumInactiveVars() { return m_inactiveVariables.size();}
194 
197  return m_cNodes[c];
198  }
201  void getClusterNodes(cluster c, List<node> &nodeList) const {
202  ListConstIterator<node> it = m_cNodes[c].begin();
203  while (it.valid())
204  {
205  nodeList.pushBack(*it);
206  ++it;
207  }
208  }
209 
210 protected:
211 
212  // Initializes constraints and variables and an initial dual bound.
213  virtual void initializeOptimization() override;
214 
215  // Function that is invoked at the end of the optimization
216  virtual void terminateOptimization() override;
217 
218  double heuristicInitialLowerBound() override;
219 
222  void createInitialVariables(List<CPlanarEdgeVar*>& initVars) override;
223 
225  void addInnerConnections(cluster c, List<CPlanarEdgeVar*>& connectVars);
226 
230 
231  bool isCP() override {
232 #if 1
233  return feasibleFound();
234 #else
235  return dualBound() != -infinity();
236 #endif
237  }
238 
240  bool goodVar(node a, node b) override;
241 
242 private:
243 
248  double heuristicInitialUpperBound() override;
249 
251  double clusterConnection(cluster c, GraphCopy &GC) override;
252 
254  void createCompConnVars(List<CPlanarEdgeVar*>& initVars) override;
255 
257  void nodeDistances(node u, NodeArray<NodeArray<int> > &dist) override;
258 
259 
260  // Parameters
261 #if 0
262  int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
263  int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
264  int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
265  int m_nMaxVars; // Max Number of variables
266  int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
267  int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
268 
269  bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
270  double m_branchingGap; // Modifies the branching behaviour
272  int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
273  bool m_mpHeuristic;
274 
275  double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
276  double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
277 
278  int m_numAddVariables; // how many variables should i add maximally per pricing round?
279  double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
280  double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
281 
282  AbaString *m_maxCpuTime; // Time threshold for optimization
283 
286  double m_largestConnectionCoeff;
287 
288  // Counters for the number of added constraints
289  int m_nCConsAdded;
290  int m_nKConsAdded;
291  int m_solvesLP;
292  int m_varsInit;
293  int m_varsAdded;
294  int m_varsPotential;
295  int m_varsMax;
296  int m_varsCut;
297  int m_varsKura;
298  int m_varsPrice;
299  int m_varsBranch;
300  int m_activeRepairs;
302  inline void clearActiveRepairs() {
303  if(m_activeRepairs) {
304  m_repairStat.push(m_activeRepairs);
305  m_activeRepairs = 0;
306  }
307  }
308 
309  double globalPrimalBound;
310  double globalDualBound;
311 
312  inline double getDoubleTime(const Stopwatch* act) {
313  long tempo = act->centiSeconds()+100*act->seconds()+6000*act->minutes()+360000*act->hours();
314  return ((double) tempo)/ 100.0;
315  }
316 
318  const int m_fastHeuristicRuns;
319 
321  StandardPool< Constraint, Variable > *m_cutConnPool;
322  StandardPool< Constraint, Variable > *m_cutKuraPool;
323 
326  bool m_useDefaultCutPool;
327 
328  double m_delta;
329  double m_deltaCount;
330 #endif
331 
333  virtual double nextConnectCoeff() override {return 1.0;}
334 #if 0
335  double nextConnectCoeff() { return -1 + m_deltaCount--*m_delta; };
336 #endif
337  virtual CPlanarEdgeVar* createVariable(ListIterator<NodePair>& it) override {
339  ++m_varsAdded;
340  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
341  v->printMe(Logger::slout());
342  m_inactiveVariables.del(it);
343  //we don't need to check symmetry
344  m_varCreated[(*it).source][(*it).target] = true;
345  return v;
346  }
348  virtual CPlanarEdgeVar* createVariable(node a, node b, double lbound) {
349  OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
350  ++m_varsAdded;
351  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), lbound, a, b);
352  v->printMe(Logger::slout());
353  //we don't need to check symmetry
354  m_varCreated[a][b] = true;
355  return v;
356  }
358  virtual CPlanarEdgeVar* createVariable(node a, node b) override {
359  OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
360  ++m_varsAdded;
361  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
362  v->printMe(Logger::slout());
363  //we don't need to check symmetry
364  m_varCreated[a][b] = true;
365  return v;
366  }
367 
368 #if 0
370 #endif
371 
372  //used in initialization
373  virtual void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
374 
375 #if 0
378 #endif
379 
382  virtual void getCoefficients(abacus::Constraint* con, const List<CPlanarEdgeVar* > & connect,
383  List<double> & coeffs) override;
384 
388 
392  bool m_shrink;
394  int m_nSep;
396 };
397 
398 }
399 }
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...
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:1373
const GraphCopy * searchSpaceGraph() const
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
virtual double nextConnectCoeff() override
Switch to minimization of additional edges, no delta necessary.
Declaration and implementation of ArrayBuffer class.
double infinity() const
Provides a floating point value of "infinite" size.
Definition: global.h:159
bool m_mpHeuristic
Indicates if simple max planar subgraph heuristic should be used to derive lower bound if only root c...
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:102
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
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
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) ...
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
void printMe(std::ostream &out) override
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
double dualBound() const
Returns the value of the dual bound.
Definition: master.h:293
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:438
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:40
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:249
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:169
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:42
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.
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.
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 ...