Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MaxCPlanarMaster.h
Go to the documentation of this file.
1 
37 #pragma once
38 
39 #include <ogdf/basic/GraphCopy.h>
42 #include <ogdf/basic/Logger.h>
43 #include <ogdf/basic/ArrayBuffer.h>
44 
45 namespace ogdf {
46 namespace cluster_planarity {
47 
49  friend class MaxCPlanarSub;
50 
51  // Pointers to the given Clustergraph and underlying Graph are stored.
52  const ClusterGraph *m_C;
53  const Graph *m_G;
55 
56 
57  // Each time the primal bound is improved, the integer solution induced Graph is built.
58  // \#m_solutionGraph is a pointer to the currently best solution induced Graph.
60 
61  List<NodePair> m_allOneEdges; //<! Contains all nodePairs whose variable is set to 1.0
62  List<NodePair> m_originalOneEdges; //<! Contains original nodePairs whose variable is set to 1.0
63  List<NodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
64  List<edge> m_deletedOriginalEdges; //<! Contains original edges whose variable is set to 0.0
65 
66 public:
67 
68  // Construction and default values
70  const ClusterGraph &C,
71  const EdgeArray<int> *pCost,
72  int heuristicLevel=1,
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.7,
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  bool dopricing = true,
85  bool checkCPlanar = false, //just check c-planarity
86  int numAddVariables = 15,
87  double strongConstraintViolation = 0.3,
88  double strongVariableViolation = 0.3);
89 
91  virtual ~MaxCPlanarMaster();
92 
93  // Initialisation of the first Subproblem
94  virtual abacus::Sub *firstSub() override;
95 
96  // Returns the objective function coefficient of C-edges
97  double epsilon() const {return m_epsilon;}
98 
99  // Returns the number of variables
100  int nMaxVars() const {return m_nMaxVars;}
101 
102  // Returns a pointer to the underlying Graph
103  const Graph *getGraph() const {return m_G;}
104 
105  // Returns a pointer to the given Clustergraph.
106  const ClusterGraph *getClusterGraph() const {return m_C;}
107 
108  // Updates the "best" Subgraph #m_solutionGraph found so far and fills edge lists with
109  // corresponding edges (nodePairs).
110  void updateBestSubGraph(List<NodePair> &original, List<NodePair> &connection, List<edge> &deleted);
111 
112  // Returns the optimal solution induced Clustergraph
113  Graph *solutionInducedGraph() {return static_cast<Graph*>(m_solutionGraph);}
114 
115  // Returns nodePairs of original, connection, deleted or all optimal solution edges in list \p edges.
116  void getAllOptimalSolutionEdges(List<NodePair> &edges) const;
119  void getDeletedEdges(List<edge> &edges) const;
120 
121  // Get parameters
123  int getNSubdivisions() const {return m_nSubdivisions;}
125  int getHeuristicLevel() const {return m_heuristicLevel;}
126  int getHeuristicRuns() const {return m_nHeuristicRuns;}
127  double getKBoundHigh() const {return m_kuratowskiBoundHigh;}
128  double getKBoundLow() const {return m_kuratowskiBoundLow;}
129  bool perturbation() const {return m_usePerturbation;}
130  double branchingOEdgeSelectGap() const {return m_branchingGap;}
133  bool getMPHeuristic() const {return m_mpHeuristic;}
134  bool getCheckCPlanar() const {return m_checkCPlanar;}
135  int getNumAddVariables() const {return m_numAddVariables;}
138 
139  // Read global constraint counter, i.e. the number of added constraints of specific type.
140  int addedKConstraints() const {return m_nKConsAdded;}
141  int addedCConstraints() const {return m_nCConsAdded;}
142 
143 
144  // Set parameters
149  void setKBoundHigh(double n) {m_kuratowskiBoundHigh = ((n>0.0 && n<1.0) ? n : 0.8);}
150  void setKBoundLow(double n) {m_kuratowskiBoundLow = ((n>0.0 && n<1.0) ? n : 0.2);}
151  void heuristicLevel(int level) {m_heuristicLevel = level;}
153  void setPertubation(bool b) {m_usePerturbation = b;}
156  void setMPHeuristic(bool b) {m_mpHeuristic = b;}
160 
162  void setPortaFile(bool b) {m_porta = b;}
163 
164  // Updating global constraint counter
165  void updateAddedCCons(int n) {m_nCConsAdded += n;}
166  void updateAddedKCons(int n) {m_nKConsAdded += n;}
167 
168  // Returns global primal and dual bounds.
170  double getDualBound() {return globalDualBound;}
171 
172  // Cut pools for connectivity and planarity
177 
181 
182 #ifdef OGDF_DEBUG
183  bool m_solByHeuristic; //solution computed by heuristic or ILP
184  // Simple output function to print the given graph to the console.
185  // Used for debugging only.
186  void printGraph(const Graph &G);
187 #endif
188 
192  {
193  return "StdConstraints.txt";
194  }
195 
196  int getNumInactiveVars() { return m_inactiveVariables.size();}
197 
198 protected:
199 
200  // Initializes constraints and variables and an initial dual bound.
201  virtual void initializeOptimization() override;
202 
203  // Function that is invoked at the end of the optimization
204  virtual void terminateOptimization() override;
205 
207 
208 private:
209 
210  // Computes a dual bound for the optimal solution.
211  // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
212  // If k edge-disjoint groups of subdivisions are found, the upper bound can be
213  // initialized with number of edges in underlying graph minus k.
215 
216  // Is invoked by heuristicInitialUpperBound()
217  void clusterConnection(cluster c, GraphCopy &GC, double &upperBound);
218 
219  // Computes the graphtheoretical distances of edges incident to node \p u.
220  void nodeDistances(node u, NodeArray<NodeArray<int> > &dist);
221 
222 
223  // Parameters
224  int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
225  int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
226  int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
227  int m_nMaxVars; // Max Number of variables
228  int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
229  int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
230 
231  bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
232  double m_branchingGap; // Modifies the branching behaviour
234  int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
236  // should be used to derive lower bound if only root cluster exists
237 
238  double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
239  double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
240 
241  int m_numAddVariables; // how many variables should i add maximally per pricing round?
242  double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
243  double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
244 
245  string *m_maxCpuTime; // Time threshold for optimization
246 
247 
248  // The basic objective function coefficient for connection edges.
249  double m_epsilon;
250  // If pertubation is used, this variable stores the largest occuring coeff,
251  // i.e. the one closest to 0. Otherwise it corresponds to #m_epsilon
253 
254  // Counters for the number of added constraints
268  inline void clearActiveRepairs() {
269  if(m_activeRepairs) {
270  m_repairStat.push(m_activeRepairs);
271  m_activeRepairs = 0;
272  }
273  }
274 
277 
278  inline double getDoubleTime(const Stopwatch* act) {
279  int64_t tempo = act->centiSeconds()+100*act->seconds()+6000*act->minutes()+360000*act->hours();
280  return ((double) tempo)/ 100.0;
281  }
282 
283  //number of calls of the fast max planar subgraph heuristic
285 
289 
293 
298 
300  double m_delta;
301  double m_deltaCount;
302  double nextConnectCoeff() { return (m_checkCPlanar ? -1 : -m_epsilon) + m_deltaCount--*m_delta; } // TODO-TESTING
304  ++m_varsAdded;
305  EdgeVar* v = new EdgeVar(this, nextConnectCoeff(), EdgeVar::EdgeType::Connect, (*it).source, (*it).target);
306  v->printMe(Logger::slout());
307  m_inactiveVariables.del(it);
308  return v;
309  }
312 
313  bool goodVar(node a, node b);
314 
316  bool m_porta;
319  void getCoefficients(abacus::Constraint* con, const List<EdgeVar *> & orig,
320  const List<EdgeVar* > & connect, List<double> & coeffs);
321 };
322 
323 }
324 }
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutConnPool()
Returns cut pool for connectivity.
void updateBestSubGraph(List< NodePair > &original, List< NodePair > &connection, List< edge > &deleted)
bool m_useDefaultCutPool
Defines if the ABACUS default cut pool or the separate Connectivity and Kuratowski constraint pools a...
The master of the optimization.
Definition: master.h:69
void getDeletedEdges(List< edge > &edges) const
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
Declaration and implementation of ArrayBuffer class.
virtual ~MaxCPlanarMaster()
Destruction.
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutKuraPool
Kuratowski Cuts.
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition: Stopwatch.h:121
The subproblem.
Definition: sub.h:68
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:95
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutConnPool
Cut pools for connectivity and Kuratowski constraints.
virtual void terminateOptimization() override
The default implementation of terminateOptimization() does nothing.
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:107
void getConnectionOptimalSolutionEdges(List< NodePair > &egdes) const
void clusterConnection(cluster c, GraphCopy &GC, double &upperBound)
Declaration of the variable class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph prob...
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
Representation of clustered graphs.
Definition: ClusterGraph.h:291
void setMPHeuristic(bool b)
Switches use of lower bound heuristic.
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
void generateVariablesForFeasibility(const List< ChunkConnection *> &ccons, List< EdgeVar *> &connectVars)
void getOriginalOptimalSolutionEdges(List< NodePair > &edges) const
virtual abacus::Sub * firstSub() override
Should return a pointer to the first subproblem of the optimization, i.e., the root node of the enume...
Contains logging functionality.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
const char * getStdConstraintsFileName()
The name of the file that contains the standard, i.e., non-cut, constraints (may be deleted by ABACUS...
Declaration of graph copy classes.
EdgeVar * createVariable(ListIterator< NodePair > &it)
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
Class for the representation of nodes.
Definition: Graph_d.h:167
Encapsulates a pointer to a list element.
Definition: List.h:41
void getAllOptimalSolutionEdges(List< NodePair > &edges) const
bool m_porta
If set to true, PORTA output is written in a file.
static std::ostream & slout(Level l=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
double upperBound() const
Returns the value of the global upper bound.
Definition: master.h:1530
void nodeDistances(node u, NodeArray< NodeArray< int > > &dist)
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
bool m_checkCPlanar
Defines if only clustered planarity is checked, i.e., all edges of the original graph need to be fixe...
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition: Stopwatch.h:114
virtual void initializeOptimization() override
The default implementation of initializeOptimization() does nothing.
int64_t hours() const
Returns the currently elapsed time in hours.
Definition: Stopwatch.h:128
const ClusterGraph * getClusterGraph() const
bool m_mpHeuristic
Indicates if simple max planar subgraph heuristic.
The namespace for all OGDF objects.
MaxCPlanarMaster(const ClusterGraph &C, const EdgeArray< int > *pCost, int heuristicLevel=1, int heuristicRuns=2, double heuristicOEdgeBound=0.3, int heuristicNPermLists=5, int kuratowskiIterations=3, int subdivisions=10, int kSupportGraphs=3, double kuratowskiHigh=0.7, double kuratowskiLow=0.3, bool perturbation=false, double branchingGap=0.4, const char *time="00:20:00", bool dopricing=true, bool checkCPlanar=false, int numAddVariables=15, double strongConstraintViolation=0.3, double strongVariableViolation=0.3)
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
virtual void printMe(ostream &out)
Definition: EdgeVar.h:64
bool & useDefaultCutPool()
Returns true if default cut pool is used. Otherwise, separate connectivity and Kuratowski pools are g...
void setPortaFile(bool b)
If set to true, PORTA output is written in a file.
double getDoubleTime(const Stopwatch *act)
void getCoefficients(abacus::Constraint *con, const List< EdgeVar *> &orig, const List< EdgeVar * > &connect, List< double > &coeffs)
writes coefficients of all orig and connect variables in constraint con into emptied list coeffs ...
Realizes a stopwatch for measuring elapsed time.
Definition: Stopwatch.h:43