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
37#include <ogdf/basic/Graph.h>
39#include <ogdf/basic/List.h>
40#include <ogdf/basic/Logger.h>
42#include <ogdf/basic/basic.h>
46
48
49#include <cstdint>
50#include <string>
51
52namespace abacus {
53template<class BaseType, class CoType>
54class StandardPool;
55} // namespace abacus
56
57namespace ogdf {
58namespace cluster_planarity {
59
61public:
63
65 explicit CP_MasterBase(const ClusterGraph& C,
66 //Check what we really still need here
67 int heuristicLevel = 1, int heuristicRuns = 2, double heuristicOEdgeBound = 0.3,
68 int heuristicNPermLists = 5, int kuratowskiIterations = 3, int subdivisions = 10,
69 int kSupportGraphs = 3, double kuratowskiHigh = 0.7, double kuratowskiLow = 0.3,
70 bool perturbation = false, double branchingGap = 0.4,
71 const char* time = "00:05:00" /* maximum computation time */);
72
74 virtual ~CP_MasterBase();
75
76#if 0
77 // Initialization of the first Subproblem
78 virtual Sub *firstSub();
79#endif
80
82 double epsilon() const { return m_epsilon; }
83
85 int nMaxVars() const { return m_nMaxVars; }
86
88 const Graph* getGraph() const { return m_G; }
89
91 const ClusterGraph* getClusterGraph() const { return m_C; }
92
94 // corresponding edges (::nodePair).
95 virtual void updateBestSubGraph(List<NodePair>& connection);
96
98 virtual Graph* solutionInducedGraph() { return static_cast<Graph*>(m_solutionGraph); }
99
102
103 void setTimeLimit(const char* s) {
104 delete m_maxCpuTime;
105 m_maxCpuTime = new string(s);
106 }
107
108 // Get parameters
110
111 int getNSubdivisions() const { return m_nSubdivisions; }
112
114
115 int getHeuristicLevel() const { return m_heuristicLevel; }
116
117 int getHeuristicRuns() const { return m_nHeuristicRuns; }
118
119 double getKBoundHigh() const { return m_kuratowskiBoundHigh; }
120
121 double getKBoundLow() const { return m_kuratowskiBoundLow; }
122
123 bool perturbation() const { return m_usePerturbation; }
124#if 0
125 double branchingOEdgeSelectGap() const {return m_branchingGap;}
126#endif
128
130
131 bool getMPHeuristic() const { return m_mpHeuristic; }
132
133 int getNumAddVariables() const { return m_numAddVariables; }
134
136
138
139 // Read global constraint counter, i.e. the number of added constraints of specific type.
140 int addedKConstraints() const { return m_nKConsAdded; }
141
142 int addedCConstraints() const { return m_nCConsAdded; }
143
144 // Set parameters
146
148
150
152
153 void setKBoundHigh(double n) { m_kuratowskiBoundHigh = ((n > 0.0 && n < 1.0) ? n : 0.8); }
154
155 void setKBoundLow(double n) { m_kuratowskiBoundLow = ((n > 0.0 && n < 1.0) ? n : 0.2); }
156
157 void heuristicLevel(int level) { m_heuristicLevel = level; }
158
160
161 void setPertubation(bool b) { m_usePerturbation = b; }
162
164
166
168 void setMPHeuristic(bool b) { m_mpHeuristic = b; }
169
171
173
175
177 void setPortaFile(bool b) { m_porta = b; }
178
179 // Updating global constraint counter
180 void updateAddedCCons(int n) { m_nCConsAdded += n; }
181
182 void updateAddedKCons(int n) { m_nKConsAdded += n; }
183
184 // Returns global primal and dual bounds.
186
187 double getDualBound() { return globalDualBound; }
188
189 // Cut pools for connectivity and planarity
194
199
203
206 double intGap() { return 0.79; }
207
208#ifdef OGDF_DEBUG
209 bool m_solByHeuristic; //solution computed by heuristic or ILP
210 // Simple output function to print the given graph to the console.
211 // Used for debugging only.
212 void printGraph(const Graph& G);
213#endif
214
217 const char* getStdConstraintsFileName() { return "StdConstraints.txt"; }
218
220
222
223protected:
224 List<NodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
225
228 const Graph* m_G;
229
230 // Each time the primal bound is improved, the integer solution induced Graph is built.
231 // #m_solutionGraph is a pointer to the currently best solution induced Graph.
232 // #m_solutionGraph is deleted in the destructor.
234
238
239 string* m_maxCpuTime;
240
241 // Initializes constraints and variables and an initial dual bound.
242 virtual void initializeOptimization() override = 0;
243
246 virtual void terminateOptimization() override;
247
249
253
254 // Computes a dual bound for the optimal solution.
255 // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
256 // If k edge-disjoint groups of subdivisions are found, the upper bound can be
257 // initialized with number of edges in underlying graph minus k.
259
262 virtual bool isCP() = 0;
263
264 // Node pair is potential candidate for new edge variable
265 virtual bool goodVar(node a, node b) { return true; }
266
268#if 0
269 //used in initialization
270 void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
271#endif
273
274
275 // Parameters
276 int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
277 int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
278 int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
279 int m_nMaxVars; // Max Number of variables
280 int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
281 int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
282
283 bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
284 double m_branchingGap; // Modifies the branching behaviour
286 int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
288
289 double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
290 double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
291
292 int m_numAddVariables; // how many variables should i add maximally per pricing round?
293 double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
294 double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
295
296 // Counters for the number of added constraints
310
311 inline void clearActiveRepairs() {
312 if (m_activeRepairs) {
314 m_activeRepairs = 0;
315 }
316 }
317
320
321 inline double getDoubleTime(const Stopwatch* act) {
322 int64_t tempo = act->centiSeconds() + 100 * act->seconds() + 6000 * act->minutes()
323 + 360000 * act->hours();
324 return ((double)tempo) / 100.0;
325 }
326
327#if 0
328 //number of calls of the fast max planar subgraph heuristic
329 const int m_fastHeuristicRuns;
330#endif
331
332private:
333 // Is invoked by heuristicInitialLowerBound()
334 virtual double clusterConnection(cluster c, GraphCopy& GC);
335
338
339 // Computes the (here: graphtheoretical) distances of edges incident to node \p u.
341
342 // The basic objective function coefficient for connection edges.
343 double m_epsilon;
344#if 0
345 // If perturbation is used, this variable stores the largest occuring coeff,
346 // i.e. the one closest to 0. Otherwise it corresponds to #m_epsilon
347 double m_largestConnectionCoeff;
348#endif
349
353
355#if 0
356 double m_delta;
357 double m_deltaCount;
358#endif
359 //Switch to minimization of additional edges, no delta necessary
360#if 1
361 virtual double nextConnectCoeff() { return 1.0; }
362#else
363 virtual double nextConnectCoeff() { return -1 + m_deltaCount-- * m_delta; }
364#endif
367 ++m_varsAdded;
368 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
370 m_inactiveVariables.del(it);
371 //we don't need to check symmetry
372 m_varCreated[(*it).source][(*it).target] = true;
373 return v;
374 }
375
378 OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
379 ++m_varsAdded;
380 CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
382 // we don't need to check symmetry
383 m_varCreated[a][b] = true;
384 return v;
385 }
386#if 0
388
389 //used in initialization
390 void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
391
394#endif
395
401 List<double>& coeffs);
402};
403
404}
405}
Declaration and implementation of ArrayBuffer class.
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.
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
friend class Sub
Definition master.h:72
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: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 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
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.