Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
CP_MasterBase.h
Go to the documentation of this file.
1
34#pragma once
35
38#include <ogdf/basic/Logger.h>
41
43
44namespace ogdf {
45namespace cluster_planarity {
46
48public:
50
52 explicit CP_MasterBase(const ClusterGraph& C,
53 //Check what we really still need here
54 int heuristicLevel = 1, int heuristicRuns = 2, double heuristicOEdgeBound = 0.3,
55 int heuristicNPermLists = 5, int kuratowskiIterations = 3, int subdivisions = 10,
56 int kSupportGraphs = 3, double kuratowskiHigh = 0.7, double kuratowskiLow = 0.3,
57 bool perturbation = false, double branchingGap = 0.4,
58 const char* time = "00:05:00" /* maximum computation time */);
59
61 virtual ~CP_MasterBase();
62
63#if 0
64 // Initialization of the first Subproblem
65 virtual Sub *firstSub();
66#endif
67
69 double epsilon() const { return m_epsilon; }
70
72 int nMaxVars() const { return m_nMaxVars; }
73
75 const Graph* getGraph() const { return m_G; }
76
78 const ClusterGraph* getClusterGraph() const { return m_C; }
79
81 // corresponding edges (::nodePair).
83
85 virtual Graph* solutionInducedGraph() { return static_cast<Graph*>(m_solutionGraph); }
86
89
90 void setTimeLimit(const char* s) {
91 delete m_maxCpuTime;
92 m_maxCpuTime = new string(s);
93 }
94
95 // Get parameters
97
98 int getNSubdivisions() const { return m_nSubdivisions; }
99
101
102 int getHeuristicLevel() const { return m_heuristicLevel; }
103
104 int getHeuristicRuns() const { return m_nHeuristicRuns; }
105
106 double getKBoundHigh() const { return m_kuratowskiBoundHigh; }
107
108 double getKBoundLow() const { return m_kuratowskiBoundLow; }
109
110 bool perturbation() const { return m_usePerturbation; }
111#if 0
112 double branchingOEdgeSelectGap() const {return m_branchingGap;}
113#endif
115
117
118 bool getMPHeuristic() const { return m_mpHeuristic; }
119
120 int getNumAddVariables() const { return m_numAddVariables; }
121
123
125
126 // Read global constraint counter, i.e. the number of added constraints of specific type.
127 int addedKConstraints() const { return m_nKConsAdded; }
128
129 int addedCConstraints() const { return m_nCConsAdded; }
130
131 // Set parameters
133
135
137
139
140 void setKBoundHigh(double n) { m_kuratowskiBoundHigh = ((n > 0.0 && n < 1.0) ? n : 0.8); }
141
142 void setKBoundLow(double n) { m_kuratowskiBoundLow = ((n > 0.0 && n < 1.0) ? n : 0.2); }
143
144 void heuristicLevel(int level) { m_heuristicLevel = level; }
145
147
148 void setPertubation(bool b) { m_usePerturbation = b; }
149
151
153
155 void setMPHeuristic(bool b) { m_mpHeuristic = b; }
156
158
160
162
164 void setPortaFile(bool b) { m_porta = b; }
165
166 // Updating global constraint counter
167 void updateAddedCCons(int n) { m_nCConsAdded += n; }
168
169 void updateAddedKCons(int n) { m_nKConsAdded += n; }
170
171 // Returns global primal and dual bounds.
173
174 double getDualBound() { return globalDualBound; }
175
176 // Cut pools for connectivity and planarity
181
186
190
193 double intGap() { return 0.79; }
194
195#ifdef OGDF_DEBUG
196 bool m_solByHeuristic; //solution computed by heuristic or ILP
197 // Simple output function to print the given graph to the console.
198 // Used for debugging only.
199 void printGraph(const Graph& G);
200#endif
201
204 const char* getStdConstraintsFileName() { return "StdConstraints.txt"; }
205
207
209
210protected:
211 List<NodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
212
215 const Graph* m_G;
216
217 // Each time the primal bound is improved, the integer solution induced Graph is built.
218 // #m_solutionGraph is a pointer to the currently best solution induced Graph.
219 // #m_solutionGraph is deleted in the destructor.
221
225
226 string* m_maxCpuTime;
227
228 // Initializes constraints and variables and an initial dual bound.
229 virtual void initializeOptimization() override = 0;
230
233 virtual void terminateOptimization() override;
234
236
240
241 // Computes a dual bound for the optimal solution.
242 // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
243 // If k edge-disjoint groups of subdivisions are found, the upper bound can be
244 // initialized with number of edges in underlying graph minus k.
246
249 virtual bool isCP() = 0;
250
251 // Node pair is potential candidate for new edge variable
252 virtual bool goodVar(node a, node b) { return true; }
253
255#if 0
256 //used in initialization
257 void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
258#endif
260
261
262 // Parameters
263 int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
264 int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
265 int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
266 int m_nMaxVars; // Max Number of variables
267 int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
268 int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
269
270 bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
271 double m_branchingGap; // Modifies the branching behaviour
273 int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
275
276 double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
277 double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
278
279 int m_numAddVariables; // how many variables should i add maximally per pricing round?
280 double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
281 double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
282
283 // Counters for the number of added constraints
297
298 inline void clearActiveRepairs() {
299 if (m_activeRepairs) {
301 m_activeRepairs = 0;
302 }
303 }
304
307
308 inline double getDoubleTime(const Stopwatch* act) {
309 int64_t tempo = act->centiSeconds() + 100 * act->seconds() + 6000 * act->minutes()
310 + 360000 * act->hours();
311 return ((double)tempo) / 100.0;
312 }
313
314#if 0
315 //number of calls of the fast max planar subgraph heuristic
316 const int m_fastHeuristicRuns;
317#endif
318
319private:
320 // Is invoked by heuristicInitialLowerBound()
322
325
326 // Computes the (here: graphtheoretical) distances of edges incident to node \p u.
328
329 // The basic objective function coefficient for connection edges.
330 double m_epsilon;
331#if 0
332 // If perturbation is used, this variable stores the largest occuring coeff,
333 // i.e. the one closest to 0. Otherwise it corresponds to #m_epsilon
334 double m_largestConnectionCoeff;
335#endif
336
340
342#if 0
343 double m_delta;
344 double m_deltaCount;
345#endif
346 //Switch to minimization of additional edges, no delta necessary
347#if 1
348 virtual double nextConnectCoeff() { return 1.0; }
349#else
350 virtual double nextConnectCoeff() { return -1 + m_deltaCount-- * m_delta; }
351#endif
354 ++m_varsAdded;
355 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
357 m_inactiveVariables.del(it);
358 //we don't need to check symmetry
359 m_varCreated[(*it).source][(*it).target] = true;
360 return v;
361 }
362
365 OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
366 ++m_varsAdded;
367 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
369 // we don't need to check symmetry
370 m_varCreated[a][b] = true;
371 return v;
372 }
373#if 0
375
376 //used in initialization
377 void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
378
381#endif
382
389};
390
391}
392}
Declaration and implementation of ArrayBuffer class.
Declaration of the variable class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph prob...
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...
Forms the virtual base class for all possible constraints given in pool format.
Definition constraint.h:56
The master of the optimization.
Definition master.h:69
friend class Sub
Definition master.h:71
virtual Sub * firstSub()=0
Should return a pointer to the first subproblem of the optimization, i.e., the root node of the enume...
Standard pools.
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.
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
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
virtual void nodeDistances(node u, NodeArray< NodeArray< int > > &dist)
void setMPHeuristic(bool b)
Switches use of lower bound heuristic.
double getDoubleTime(const Stopwatch *act)
virtual void updateBestSubGraph(List< NodePair > &connection)
Updates the "best" Subgraph m_solutionGraph found so far and fills connection with.
const char * getStdConstraintsFileName()
The name of the file that contains the standard, i.e., non-cut, constraints (may be deleted by ABACUS...
string * m_maxCpuTime
Time threshold for optimization.
virtual ~CP_MasterBase()
Destruction.
NodeArray< NodeArray< bool > > m_varCreated
Keeps track of variables that are currently inactive during optimization.
virtual CPlanarEdgeVar * createVariable(ListIterator< NodePair > &it)
Variable creation for nodePair.
List< NodePair > m_connectionOneEdges
stores optimization success state
virtual bool goodVar(node a, node b)
bool m_useDefaultCutPool
Defines if the ABACUS default cut pool or the separate Connectivity and Kuratowski constraint pools a...
CP_MasterBase(const ClusterGraph &C, 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:05:00")
Construction and default values.
virtual bool isCP()=0
Derives and returns c-planarity property either directly or indirectly from computation results.
const ClusterGraph * getClusterGraph() const
Returns a pointer to the given Clustergraph.
virtual CPlanarEdgeVar * createVariable(node a, node b)
Variable creation for pair of nodes which is not stored in m_inactiveVariables.
virtual void createCompConnVars(List< CPlanarEdgeVar * > &initVars)
Creates variables for complete connectivity.
double epsilon() const
Returns the objective function coefficient of C-edges.
void setPortaFile(bool b)
If set to true, PORTA output is written in a file.
bool & useDefaultCutPool()
Returns true if default cut pool is used. Otherwise, separate connectivity and Kuratowski pools are g...
bool m_porta
If set to true, PORTA output is written in a file.
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutConnPool
Cut pools for connectivity and Kuratowski constraints.
virtual double clusterConnection(cluster c, GraphCopy &GC)
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
virtual void createInitialVariables(List< CPlanarEdgeVar * > &initVars)=0
All variables that have to be present at start of optimization are created here.
const Graph * getGraph() const
Returns a pointer to the underlying Graph.
virtual void initializeOptimization() override=0
The default implementation of initializeOptimization() does nothing.
int m_nKuratowskiSupportGraphs
Keeps track of created variables.
virtual void getCoefficients(abacus::Constraint *con, const List< CPlanarEdgeVar * > &connect, List< double > &coeffs)
writes coefficients of all orig and connect variables in constraint con into emptied list coeffs
virtual void terminateOptimization() override
Function that is invoked at the end of the optimization. Does nothing but output in CP_MasterBase.
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...
double intGap()
Returns a value that allows to distinguish result values when connection edges (tiny negative cost) a...
virtual void getConnectionOptimalSolutionEdges(List< NodePair > &edges) const
Returns nodePairs of connecting optimal solution edges in list edges.
virtual Graph * solutionInducedGraph()
Returns the optimal solution induced Clustergraph.
int nMaxVars() const
Returns the number of variables.
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
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
the master of the optimization.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.