Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MaxCPlanarMaster.h
Go to the documentation of this file.
1
37#pragma once
38
40#include <ogdf/basic/Graph.h>
42#include <ogdf/basic/List.h>
43#include <ogdf/basic/Logger.h>
45#include <ogdf/basic/basic.h>
49
51
52#include <cstdint>
53#include <string>
54
55namespace abacus {
56template<class BaseType, class CoType>
57class StandardPool;
58} // namespace abacus
59
61class ChunkConnection;
62} // namespace ogdf::cluster_planarity
63
64namespace ogdf {
65namespace cluster_planarity {
66
68 friend class MaxCPlanarSub;
69
70 // Pointers to the given Clustergraph and underlying Graph are stored.
72 const Graph* m_G;
74
75
76 // Each time the primal bound is improved, the integer solution induced Graph is built.
77 // \#m_solutionGraph is a pointer to the currently best solution induced Graph.
79
80 List<NodePair> m_allOneEdges; //<! Contains all nodePairs whose variable is set to 1.0
81 List<NodePair> m_originalOneEdges; //<! Contains original nodePairs whose variable is set to 1.0
82 List<NodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
83 List<edge> m_deletedOriginalEdges; //<! Contains original edges whose variable is set to 0.0
84
85public:
86 // Construction and default values
88 int heuristicRuns = 2, double heuristicOEdgeBound = 0.3, int heuristicNPermLists = 5,
89 int kuratowskiIterations = 3, int subdivisions = 10, int kSupportGraphs = 3,
90 double kuratowskiHigh = 0.7, double kuratowskiLow = 0.3, bool perturbation = false,
91 double branchingGap = 0.4,
92 const char* time = "00:20:00", //maximum computation time
93 bool dopricing = true,
94 bool checkCPlanar = false, //just check c-planarity
95 int numAddVariables = 15, double strongConstraintViolation = 0.3,
96 double strongVariableViolation = 0.3);
97
100
101 // Initialisation of the first Subproblem
102 virtual abacus::Sub* firstSub() override;
103
104 // Returns the objective function coefficient of C-edges
105 double epsilon() const { return m_epsilon; }
106
107 // Returns the number of variables
108 int nMaxVars() const { return m_nMaxVars; }
109
110 // Returns a pointer to the underlying Graph
111 const Graph* getGraph() const { return m_G; }
112
113 // Returns a pointer to the given Clustergraph.
114 const ClusterGraph* getClusterGraph() const { return m_C; }
115
116 // Updates the "best" Subgraph #m_solutionGraph found so far and fills edge lists with
117 // corresponding edges (nodePairs).
119 List<edge>& deleted);
120
121 // Returns the optimal solution induced Clustergraph
122 Graph* solutionInducedGraph() { return static_cast<Graph*>(m_solutionGraph); }
123
124 // Returns nodePairs of original, connection, deleted or all optimal solution edges in list \p edges.
128 void getDeletedEdges(List<edge>& edges) const;
129
130 // Get parameters
132
133 int getNSubdivisions() const { return m_nSubdivisions; }
134
136
137 int getHeuristicLevel() const { return m_heuristicLevel; }
138
139 int getHeuristicRuns() const { return m_nHeuristicRuns; }
140
141 double getKBoundHigh() const { return m_kuratowskiBoundHigh; }
142
143 double getKBoundLow() const { return m_kuratowskiBoundLow; }
144
145 bool perturbation() const { return m_usePerturbation; }
146
147 double branchingOEdgeSelectGap() const { return m_branchingGap; }
148
150
152
153 bool getMPHeuristic() const { return m_mpHeuristic; }
154
155 bool getCheckCPlanar() const { return m_checkCPlanar; }
156
157 int getNumAddVariables() const { return m_numAddVariables; }
158
160
162
163 // Read global constraint counter, i.e. the number of added constraints of specific type.
164 int addedKConstraints() const { return m_nKConsAdded; }
165
166 int addedCConstraints() const { return m_nCConsAdded; }
167
168 // Set parameters
170
172
174
176
177 void setKBoundHigh(double n) { m_kuratowskiBoundHigh = ((n > 0.0 && n < 1.0) ? n : 0.8); }
178
179 void setKBoundLow(double n) { m_kuratowskiBoundLow = ((n > 0.0 && n < 1.0) ? n : 0.2); }
180
181 void heuristicLevel(int level) { m_heuristicLevel = level; }
182
184
185 void setPertubation(bool b) { m_usePerturbation = b; }
186
188
190
192 void setMPHeuristic(bool b) { m_mpHeuristic = b; }
193
195
197
199
201 void setPortaFile(bool b) { m_porta = b; }
202
203 // Updating global constraint counter
204 void updateAddedCCons(int n) { m_nCConsAdded += n; }
205
206 void updateAddedKCons(int n) { m_nKConsAdded += n; }
207
208 // Returns global primal and dual bounds.
210
211 double getDualBound() { return globalDualBound; }
212
213 // Cut pools for connectivity and planarity
218
223
227
228#ifdef OGDF_DEBUG
229 bool m_solByHeuristic; //solution computed by heuristic or ILP
230 // Simple output function to print the given graph to the console.
231 // Used for debugging only.
232 void printGraph(const Graph& G);
233#endif
234
237 const char* getStdConstraintsFileName() { return "StdConstraints.txt"; }
238
240
241protected:
242 // Initializes constraints and variables and an initial dual bound.
243 virtual void initializeOptimization() override;
244
245 // Function that is invoked at the end of the optimization
246 virtual void terminateOptimization() override;
247
249
250private:
251 // Computes a dual bound for the optimal solution.
252 // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
253 // If k edge-disjoint groups of subdivisions are found, the upper bound can be
254 // initialized with number of edges in underlying graph minus k.
256
257 // Is invoked by heuristicInitialUpperBound()
259
260 // Computes the graphtheoretical distances of edges incident to node \p u.
262
263
264 // Parameters
265 int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
266 int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
267 int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
268 int m_nMaxVars; // Max Number of variables
269 int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
270 int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
271
272 bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
273 double m_branchingGap; // Modifies the branching behaviour
275 int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
277
278 double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
279 double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
280
281 int m_numAddVariables; // how many variables should i add maximally per pricing round?
282 double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
283 double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
284
285 string* m_maxCpuTime; // Time threshold for optimization
286
287
288 // The basic objective function coefficient for connection edges.
289 double m_epsilon;
290 // If pertubation is used, this variable stores the largest occuring coeff,
291 // i.e. the one closest to 0. Otherwise it corresponds to #m_epsilon
293
294 // Counters for the number of added constraints
308
309 inline void clearActiveRepairs() {
310 if (m_activeRepairs) {
312 m_activeRepairs = 0;
313 }
314 }
315
318
319 inline double getDoubleTime(const Stopwatch* act) {
320 int64_t tempo = act->centiSeconds() + 100 * act->seconds() + 6000 * act->minutes()
321 + 360000 * act->hours();
322 return ((double)tempo) / 100.0;
323 }
324
325 //number of calls of the fast max planar subgraph heuristic
327
331
335
340
341 double m_delta;
343
345 // TODO: Test whether this implementation is working.
346 return (m_checkCPlanar ? -1 : -m_epsilon) + m_deltaCount-- * m_delta;
347 }
348
350 ++m_varsAdded;
351 EdgeVar* v = new EdgeVar(this, nextConnectCoeff(), EdgeVar::EdgeType::Connect, (*it).source,
352 (*it).target);
354 m_inactiveVariables.del(it);
355 return v;
356 }
357
360 List<EdgeVar*>& connectVars);
361
362 bool goodVar(node a, node b);
363
369 const List<EdgeVar*>& connect, List<double>& coeffs);
370};
371
372}
373}
Declaration and implementation of ArrayBuffer class.
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Declaration of the variable class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph prob...
Includes declaration of graph class.
Declaration of graph copy classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Declaration of stopwatch classes.
Includes Abacus.
Basic declarations, included by all source files.
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:57
The master of the optimization.
Definition master.h:70
double upperBound() const
Returns the value of the global upper bound.
Definition master.h:1531
Standard pools.
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.
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
Encapsulates a pointer to a list element.
Definition List.h:113
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
virtual void printMe(std::ostream &out)
Definition EdgeVar.h:70
void setPortaFile(bool b)
If set to true, PORTA output is written in a file.
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
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutConnPool()
Returns cut pool for connectivity.
void generateVariablesForFeasibility(const List< ChunkConnection * > &ccons, List< EdgeVar * > &connectVars)
void updateBestSubGraph(List< NodePair > &original, List< NodePair > &connection, List< edge > &deleted)
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
bool m_mpHeuristic
Indicates if simple max planar subgraph heuristic should be used to derive lower bound if only root c...
virtual abacus::Sub * firstSub() override
Should return a pointer to the first subproblem of the optimization, i.e., the root node of the enume...
bool m_useDefaultCutPool
Defines if the ABACUS default cut pool or the separate Connectivity and Kuratowski constraint pools a...
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutConnPool
Cut pools for connectivity and Kuratowski constraints.
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)
void getDeletedEdges(List< edge > &edges) const
const char * getStdConstraintsFileName()
The name of the file that contains the standard, i.e., non-cut, constraints (may be deleted by ABACUS...
EdgeVar * createVariable(ListIterator< NodePair > &it)
void getConnectionOptimalSolutionEdges(List< NodePair > &egdes) const
bool m_porta
If set to true, PORTA output is written in a file.
virtual void terminateOptimization() override
The default implementation of terminateOptimization() does nothing.
void getOriginalOptimalSolutionEdges(List< NodePair > &edges) const
void getAllOptimalSolutionEdges(List< NodePair > &edges) const
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutKuraPool
Kuratowski Cuts.
bool m_checkCPlanar
Defines if only clustered planarity is checked, i.e., all edges of the original graph need to be fixe...
double getDoubleTime(const Stopwatch *act)
virtual void initializeOptimization() override
The default implementation of initializeOptimization() does nothing.
void setMPHeuristic(bool b)
Switches use of lower bound heuristic.
bool & useDefaultCutPool()
Returns true if default cut pool is used. Otherwise, separate connectivity and Kuratowski pools are g...
void clusterConnection(cluster c, GraphCopy &GC, double &upperBound)
const ClusterGraph * getClusterGraph() const
void nodeDistances(node u, NodeArray< NodeArray< int > > &dist)
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
The namespace for all OGDF objects.