Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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<double> *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;}
157  void setMPHeuristic(bool b) {m_mpHeuristic = b;}
161 
163  void setPortaFile(bool b) {m_porta = b;}
164 
165  // Updating global constraint counter
166  void updateAddedCCons(int n) {m_nCConsAdded += n;}
167  void updateAddedKCons(int n) {m_nKConsAdded += n;}
168 
169  // Returns global primal and dual bounds.
171  double getDualBound() {return globalDualBound;}
172 
173  // Cut pools for connectivity and planarity
178 
182 
183 #ifdef OGDF_DEBUG
184  bool m_solByHeuristic; //solution computed by heuristic or ILP
185  // Simple output function to print the given graph to the console.
186  // Used for debugging only.
187  void printGraph(const Graph &G);
188 #endif
189 
193  {
194  return "StdConstraints.txt";
195  }
196 
197  int getNumInactiveVars() { return m_inactiveVariables.size();}
198 
199 protected:
200 
201  // Initializes constraints and variables and an initial dual bound.
202  virtual void initializeOptimization() override;
203 
204  // Function that is invoked at the end of the optimization
205  virtual void terminateOptimization() override;
206 
208 
209 private:
210 
211  // Computes a dual bound for the optimal solution.
212  // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
213  // If k edge-disjoint groups of subdivisions are found, the upper bound can be
214  // initialized with number of edges in underlying graph minus k.
216 
217  // Is invoked by heuristicInitialUpperBound()
218  void clusterConnection(cluster c, GraphCopy &GC, double &upperBound);
219 
220  // Computes the graphtheoretical distances of edges incident to node \p u.
221  void nodeDistances(node u, NodeArray<NodeArray<int> > &dist);
222 
223 
224  // Parameters
225  int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
226  int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
227  int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
228  int m_nMaxVars; // Max Number of variables
229  int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
230  int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
231 
232  bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
233  double m_branchingGap; // Modifies the branching behaviour
235  int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
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 
299  double m_delta;
300  double m_deltaCount;
301  double nextConnectCoeff() {
302  // TODO: Test whether this implementation is working.
303  return (m_checkCPlanar ? -1 : -m_epsilon) + m_deltaCount--*m_delta;
304  }
306  ++m_varsAdded;
307  EdgeVar* v = new EdgeVar(this, nextConnectCoeff(), EdgeVar::EdgeType::Connect, (*it).source, (*it).target);
308  v->printMe(Logger::slout());
309  m_inactiveVariables.del(it);
310  return v;
311  }
314 
315  bool goodVar(node a, node b);
316 
318  bool m_porta;
321  void getCoefficients(abacus::Constraint* con, const List<EdgeVar *> & orig,
322  const List<EdgeVar* > & connect, List<double> & coeffs);
323 };
324 
325 }
326 }
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:492
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:102
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
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
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:438
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.
virtual void printMe(std::ostream &out)
Definition: EdgeVar.h:64
Doubly linked lists (maintaining the length of the list).
Definition: List.h:40
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.
MaxCPlanarMaster(const ClusterGraph &C, const EdgeArray< double > *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)
EdgeVar * createVariable(ListIterator< NodePair > &it)
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:249
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
void getAllOptimalSolutionEdges(List< NodePair > &edges) const
bool m_porta
If set to true, PORTA output is written in a file.
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 should be used to derive lower bound if only root c...
The namespace for all OGDF objects.
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
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