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
38#include <ogdf/basic/Graph.h>
40#include <ogdf/basic/List.h>
41#include <ogdf/basic/Logger.h>
42#include <ogdf/basic/basic.h>
47
48namespace abacus {
49class Constraint;
50class Sub;
51} // namespace abacus
52
54class ChunkConnection;
55} // namespace ogdf::cluster_planarity
56
57namespace ogdf {
58class ClusterAnalysis;
59
60namespace cluster_planarity {
61
63 friend class CPlanaritySub;
64
65#if 0
67 const ClusterGraph *m_C;
68 const Graph *m_G;
69
70
74
75 List<nodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
76#endif
77
78public:
79 // Construction and default values
80 explicit CPlanarityMaster(const ClusterGraph& C,
81 //Check what we really still need here
82 int heuristicLevel = 0, int heuristicRuns = 2, double heuristicOEdgeBound = 0.3,
83 int heuristicNPermLists = 5, int kuratowskiIterations = 3, int subdivisions = 10,
84 int kSupportGraphs = 3, double kuratowskiHigh = 0.75, double kuratowskiLow = 0.3,
85 bool perturbation = false, double branchingGap = 0.4,
86 const char* time = "00:20:00" /* maximum computation time */);
87
90
91 // Initialization of the first Subproblem
92 virtual abacus::Sub* firstSub() override;
93
94 // Returns the number of variables
95 int nMaxVars() const { return m_nMaxVars; }
96
97 // Returns a pointer to the underlying Graph
98 const Graph* getGraph() const { return m_G; }
99
100 // Returns a pointer to the given Clustergraph.
101 const ClusterGraph* getClusterGraph() const { return m_C; }
102
103 // Returns a pointer on the search space graph, which is
104 // a copy of the input graph with all edges added that
105 // correspond to variables add at initialization.
106 // Be aware that this is not dynamically updated, e.g. for pricing.
107
108 const GraphCopy* searchSpaceGraph() const { return m_ssg; }
109
110 // Updates the "best" Subgraph #m_solutionGraph found so far and fills edge lists with
111 // corresponding edges (nodePairs).
112 void updateBestSubGraph(List<NodePair>& connection) override;
113
114 // Returns the optimal solution induced Clustergraph
115 Graph* solutionInducedGraph() override { return static_cast<Graph*>(m_solutionGraph); }
116
117 // Returns nodePairs of connecting optimal solution edges in list \p edges.
119
120 // Get parameters
122
123 int getNSubdivisions() const { return m_nSubdivisions; }
124
126
127 int getHeuristicLevel() const { return m_heuristicLevel; }
128
129 int getHeuristicRuns() const { return m_nHeuristicRuns; }
130
131 double getKBoundHigh() const { return m_kuratowskiBoundHigh; }
132
133 double getKBoundLow() const { return m_kuratowskiBoundLow; }
134
135 bool perturbation() const { return m_usePerturbation; }
136
137 double branchingOEdgeSelectGap() const { return m_branchingGap; }
138
140
142
143 bool getMPHeuristic() const { return m_mpHeuristic; }
144
145 int getNumAddVariables() const { return m_numAddVariables; }
146
148
150
151#if 0
152 // Read global constraint counter, i.e. the number of added constraints of specific type.
153 int addedKConstraints() const {return m_nKConsAdded;}
154 int addedCConstraints() const {return m_nCConsAdded;}
155#endif
156
157
158 // Set parameters
160
162
164
166
167 void setKBoundHigh(double n) { m_kuratowskiBoundHigh = ((n > 0.0 && n < 1.0) ? n : 0.8); }
168
169 void setKBoundLow(double n) { m_kuratowskiBoundLow = ((n > 0.0 && n < 1.0) ? n : 0.2); }
170
171 void heuristicLevel(int level) { m_heuristicLevel = level; }
172
174
175 void setPertubation(bool b) { m_usePerturbation = b; }
176
178
180
182 void setMPHeuristic(bool b) { m_mpHeuristic = b; }
183
185
187
189
191 void setSearchSpaceShrinking(bool b) { m_shrink = b; }
192
193#if 0
195 void updateAddedCCons(int n) {m_nCConsAdded += n;}
196 void updateAddedKCons(int n) {m_nKConsAdded += n;}
197
199 double getPrimalBound() {return globalPrimalBound;}
200 double getDualBound() {return globalDualBound;}
201
202 // Cut pools for connectivity and planarity
204 StandardPool<Constraint, Variable> *getCutConnPool() {return m_cutConnPool;}
206 StandardPool<Constraint, Variable> *getCutKuraPool() {return m_cutKuraPool;}
207
210 bool &useDefaultCutPool() { return m_useDefaultCutPool;}
211#endif
212
213#ifdef OGDF_DEBUG
216 void printGraph(const Graph& G);
217#endif
218
221 const char* getStdConstraintsFileName() { return "StdConstraints.txt"; }
222
224
226 const List<node>& getClusterNodes(cluster c) const { return m_cNodes[c]; }
227
230 void getClusterNodes(cluster c, List<node>& nodeList) const {
231 ListConstIterator<node> it = m_cNodes[c].begin();
232 while (it.valid()) {
233 nodeList.pushBack(*it);
234 ++it;
235 }
236 }
237
238protected:
239 // Initializes constraints and variables and an initial dual bound.
240 virtual void initializeOptimization() override;
241
242 // Function that is invoked at the end of the optimization
243 virtual void terminateOptimization() override;
244
245 double heuristicInitialLowerBound() override;
246
250
253
257
258 bool isCP() override {
259#if 1
260 return feasibleFound();
261#else
262 return dualBound() != -infinity();
263#endif
264 }
265
267 bool goodVar(node a, node b) override;
268
269private:
274 double heuristicInitialUpperBound() override;
275
277 double clusterConnection(cluster c, GraphCopy& GC) override;
278
281
283 void nodeDistances(node u, NodeArray<NodeArray<int>>& dist) override;
284
285
286 // Parameters
287#if 0
288 int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
289 int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
290 int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
291 int m_nMaxVars; // Max Number of variables
292 int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
293 int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
294
295 bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
296 double m_branchingGap; // Modifies the branching behaviour
298 int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
299 bool m_mpHeuristic;
300
301 double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
302 double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
303
304 int m_numAddVariables; // how many variables should i add maximally per pricing round?
305 double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
306 double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
307
308 AbaString *m_maxCpuTime; // Time threshold for optimization
309
312 double m_largestConnectionCoeff;
313
314 // Counters for the number of added constraints
315 int m_nCConsAdded;
316 int m_nKConsAdded;
317 int m_solvesLP;
318 int m_varsInit;
319 int m_varsAdded;
320 int m_varsPotential;
321 int m_varsMax;
322 int m_varsCut;
323 int m_varsKura;
324 int m_varsPrice;
325 int m_varsBranch;
326 int m_activeRepairs;
328 inline void clearActiveRepairs() {
329 if(m_activeRepairs) {
331 m_activeRepairs = 0;
332 }
333 }
334
335 double globalPrimalBound;
336 double globalDualBound;
337
338 inline double getDoubleTime(const Stopwatch* act) {
339 long tempo = act->centiSeconds()+100*act->seconds()+6000*act->minutes()+360000*act->hours();
340 return ((double) tempo)/ 100.0;
341 }
342
344 const int m_fastHeuristicRuns;
345
347 StandardPool< Constraint, Variable > *m_cutConnPool;
348 StandardPool< Constraint, Variable > *m_cutKuraPool;
349
353
354 double m_delta;
355 double m_deltaCount;
356#endif
357
359 virtual double nextConnectCoeff() override { return 1.0; }
360#if 0
361 double nextConnectCoeff() { return -1 + m_deltaCount--*m_delta; };
362#endif
365 ++m_varsAdded;
366 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
368 m_inactiveVariables.del(it);
369 //we don't need to check symmetry
370 m_varCreated[(*it).source][(*it).target] = true;
371 return v;
372 }
373
375 virtual CPlanarEdgeVar* createVariable(node a, node b, double lbound) {
376 OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
377 ++m_varsAdded;
378 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), lbound, a, b);
380 //we don't need to check symmetry
381 m_varCreated[a][b] = true;
382 return v;
383 }
384
386 virtual CPlanarEdgeVar* createVariable(node a, node b) override {
387 OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
388 ++m_varsAdded;
389 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
391 //we don't need to check symmetry
392 m_varCreated[a][b] = true;
393 return v;
394 }
395
396#if 0
398#endif
399
400 //used in initialization
402 List<CPlanarEdgeVar*>& connectVars);
403
404#if 0
407#endif
408
412 List<double>& coeffs) override;
413
417
423 int m_nSep;
425};
426
427}
428}
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...
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Includes declaration of graph class.
Declaration of graph copy classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Basic declarations, included by all source files.
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:160
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:57
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:294
The subproblem.
Definition sub.h:69
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Definition ArrayBuffer.h:64
void push(E e)
Puts a new element in the buffer.
RegisteredArray for labeling the clusters of a ClusterGraph.
Representation of clusters in a clustered graph.
Representation of clustered graphs.
Copies of graphs supporting edge splitting.
Definition GraphCopy.h:390
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition Logger.h:193
Class for the representation of nodes.
Definition Graph_d.h:241
Realizes a stopwatch for measuring elapsed time.
Definition Stopwatch.h:45
int64_t hours() const
Returns the currently elapsed time in hours.
Definition Stopwatch.h:126
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition Stopwatch.h:105
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition Stopwatch.h:112
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition Stopwatch.h:119
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 printGraph(const Graph &G)
Simple output function to print the given graph to the console. Used for debugging only.
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.
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.