Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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