Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
MaximumCPlanarSubgraph.h
Go to the documentation of this file.
1
33#pragma once
34
35
36#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
39#include <ogdf/basic/basic.h>
43
45
46#include <chrono>
47#include <cstdint>
48#include <sstream>
49#include <string>
50
51namespace abacus {
52template<class BaseType, class CoType>
53class StandardPool;
54} // namespace abacus
55
56namespace ogdf {
57
59
63public:
66
69 : m_heuristicLevel(1)
70 , m_heuristicRuns(1)
71 , m_heuristicOEdgeBound(0.4)
72 , m_heuristicNPermLists(5)
73 , m_kuratowskiIterations(10)
74 , m_subdivisions(10)
75 , m_kSupportGraphs(10)
76 , m_kuratowskiHigh(0.8)
77 , m_kuratowskiLow(0.8)
78 , m_perturbation(false)
79 , m_branchingGap(0.4)
80 , m_time("00:20:00")
81 , m_pricing(false)
82 , m_checkCPlanar(false)
83 , m_numAddVariables(15)
84 , m_strongConstraintViolation(0.3)
85 , m_strongVariableViolation(0.3)
86 , m_totalTime(-1.0)
87 , m_heurTime(-1.0)
88 , m_lpTime(-1.0)
89 , m_lpSolverTime(-1.0)
90 , m_sepTime(-1.0)
91 , m_totalWTime(-1.0)
92 , m_numCCons(-1)
93 , m_numKCons(-1)
94 , m_numLPs(-1)
95 , m_numBCs(-1)
96 , m_numSubSelected(-1)
97 , m_numVars(-1)
98 , m_portaOutput(false)
99 , m_defaultCutPool(true)
100#ifdef OGDF_DEBUG
101 , m_solByHeuristic(false)
102#endif
103 {
104 }
105
106 //destruction
108
117 /*
118 * @param ClusterGraph the graph that we want to compute a subgraph of
119 * @param pCost the cost of each edge or \c nullptr if edges should have uniform cost
120 * @param delEdges contains all deleted edges after the call
121 * @param addedEdges the set of edges that makes the subgraph connected
122 */
124 List<edge>& delEdges, NodePairs& addedEdges) {
125 return doCall(G, pCost, delEdges, addedEdges);
126 }
127
128 //setter methods for the module parameters
129 void setHeuristicLevel(int i) { m_heuristicLevel = i; }
130
131 void setHeuristicRuns(int i) { m_heuristicRuns = i; }
132
133 void setHeuristicBound(double d) { m_heuristicOEdgeBound = d; }
134
135 void setNumberOfPermutations(int i) { m_heuristicNPermLists = i; }
136
137 void setNumberOfKuraIterations(int i) { m_kuratowskiIterations = i; }
138
139 void setNumberOfSubDivisions(int i) { m_subdivisions = i; }
140
141 void setNumberOfSupportGraphs(int i) { m_kSupportGraphs = i; }
142
143 void setUpperRounding(double d) { m_kuratowskiHigh = d; }
144
145 void setLowerRounding(double d) { m_kuratowskiLow = d; }
146
147 void setPerturbation(bool b) { m_perturbation = b; }
148
149 void setBranchingGap(double d) { m_branchingGap = d; }
150
151 void setTimeLimit(string s) { m_time = s.c_str(); }
152
153 void setTimeLimit(std::chrono::milliseconds milliSec) {
154 // format string only supports seconds
155 OGDF_ASSERT(milliSec.count() >= 1000);
156 // transform to format string
157 std::chrono::milliseconds remaining(milliSec);
158 auto h = std::chrono::duration_cast<std::chrono::hours>(remaining);
159 remaining -= h;
160 auto m = std::chrono::duration_cast<std::chrono::minutes>(remaining);
161 remaining -= m;
162 auto s = std::chrono::duration_cast<std::chrono::seconds>(remaining);
163 std::stringstream ss;
164 ss << h.count() << ":" << m.count() << ":" << s.count();
165 setTimeLimit(ss.str());
166 }
167
168 void setPortaOutput(bool b) { m_portaOutput = b; }
169
170 void setPricing(bool b) { m_pricing = b; }
171
172 void setCheckCPlanar(bool b) { m_checkCPlanar = b; }
173
174 void setNumAddVariables(int n) { m_numAddVariables = n; }
175
176 void setStrongConstraintViolation(double d) { m_strongConstraintViolation = d; }
177
178 void setStrongVariableViolation(double d) { m_strongVariableViolation = d; }
179
182 bool& useDefaultCutPool() { return m_defaultCutPool; }
183
184 //getter methods for results
185 double getTotalTime() { return m_totalTime; }
186
187 double getHeurTime() { return m_heurTime; }
188
189 double getLPTime() { return m_lpTime; }
190
191 double getLPSolverTime() { return m_lpSolverTime; }
192
193 double getSeparationTime() { return m_sepTime; }
194
195 double getTotalWTime() { return m_totalWTime; }
196
198 int getNumCCons() { return m_numCCons; }
199
201 int getNumKCons() { return m_numKCons; }
202
204 int getNumLPs() { return m_numLPs; }
205
207 int getNumBCs() { return m_numBCs; }
208
210 int getNumSubSelected() { return m_numSubSelected; }
211
213 int getNumVars() { return m_numVars; }
214
216 void writeFeasible(const char* filename, MaxCPlanarMaster& master,
217 abacus::Master::STATUS& status);
218#ifdef OGDF_DEBUG
219 bool getSolByHeuristic() { return m_solByHeuristic; }
220#endif
221
222
223protected:
228 virtual ReturnType doCall(const ClusterGraph& G, const EdgeArray<double>* pCost,
229 List<edge>& delEdges) override {
230 NodePairs addEdges;
231 return doCall(G, pCost, delEdges, addEdges);
232 }
233
234 //as above, also returns the set of edges that were
235 //added to construct a completely connected planar
236 //graph that contains the computed c-planar subgraph
237 virtual ReturnType doCall(const ClusterGraph& G, const EdgeArray<double>* pCost,
238 List<edge>& delEdges, NodePairs& addedEdges);
239
240 double getDoubleTime(const Stopwatch& act) {
241 int64_t tempo = act.centiSeconds() + 100 * act.seconds() + 6000 * act.minutes()
242 + 360000 * act.hours();
243 return ((double)tempo) / 100.0;
244 }
245
248
249private:
250 //Abacus Master class settings in order of appearance
251 int m_heuristicLevel, m_heuristicRuns;
253 int m_heuristicNPermLists, m_kuratowskiIterations;
254 int m_subdivisions, m_kSupportGraphs;
255 double m_kuratowskiHigh, m_kuratowskiLow;
258 string m_time;
259 bool m_pricing; //<! Decides if pricing is used
260 bool m_checkCPlanar; //<! If set to true, only c-planarity is checked
264
265 const char* getPortaFileName() { return "porta.poi"; }
266
267 const char* getIeqFileName() { return "porta.ieq"; }
268
269 int maxConLength() { return 1024; }
270
271 void outputCons(std::ofstream& os,
274
275 //results
276 double m_totalTime; //<! Total computation time, returned from abacus
277 double m_heurTime; //<! Time spent in heuristic, returned from abacus
278 double m_lpTime; //<! Cpu time spent in members of the LP-interface, returned from abacus
279 double m_lpSolverTime; //<! Cpu time required by the LP solver, returned from abacus
280 double m_sepTime; //<! Cpu time spent in the separation of cutting planes, returned from abacus
281 double m_totalWTime; //<! Total wall clock time, returned from abacus
282 int m_numCCons; //<! Number of added connectivity constraints
283 int m_numKCons; //<! Number of added kuratowski constraints
284 int m_numLPs; //<! The number of optimized linear programs (LP-relax.).
285 int m_numBCs; //<! The number of generated subproblems.
286 int m_numSubSelected; //<! The number of subproblems selected by ABACUS.
287 int m_numVars; //<! The number of global variables.
288 bool m_portaOutput; //<! If set to true, output for PORTA in ieq format is generated.
289 bool m_defaultCutPool; //<! Passed through to master
290#ifdef OGDF_DEBUG
292#endif
293};
294
295}
Declaration of an interface for c-planar subgraph algorithms.
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
Declaration of stopwatch classes.
Includes Abacus.
Basic declarations, included by all source files.
STATUS
The various statuses of the optimization process.
Definition master.h:78
Standard pools.
Interface of algorithms for the computation of c-planar subgraphs.
Representation of clusters in a clustered graph.
Representation of clustered graphs.
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Exact computation of a maximum c-planar subgraph.
int getNumSubSelected()
Returns number of subproblems selected by ABACUS.
bool & useDefaultCutPool()
Use default abacus master cut pool or dedicated connectivity and kuratowski cut pools.
int getNumBCs()
Returns number of generated LPs.
virtual ReturnType doCall(const ClusterGraph &G, const EdgeArray< double > *pCost, List< edge > &delEdges, NodePairs &addedEdges)
ReturnType callAndConnect(const ClusterGraph &G, const EdgeArray< double > *pCost, List< edge > &delEdges, NodePairs &addedEdges)
Computes set of edges delEdges, which have to be deleted in order to get a c-planar subgraph and also...
int getNumLPs()
Returns number of optimized LPs (only LP-relaxations)
void getBottomUpClusterList(const cluster c, List< cluster > &theList)
Stores clusters in subtree at c in bottom up order in theList.
int getNumVars()
Returns number of global variables. Todo: Real number from ABACUS.
void outputCons(std::ofstream &os, abacus::StandardPool< abacus::Constraint, abacus::Variable > *connCon, abacus::StandardPool< abacus::Variable, abacus::Constraint > *stdVar)
int getNumKCons()
Returns number of Kuratowski constraints added during computation.
void writeFeasible(const char *filename, MaxCPlanarMaster &master, abacus::Master::STATUS &status)
Writes feasible solutions as a file in PORTA format.
void setTimeLimit(std::chrono::milliseconds milliSec)
double getDoubleTime(const Stopwatch &act)
int getNumCCons()
Returns number of connectivity constraints added during computation.
virtual ReturnType doCall(const ClusterGraph &G, const EdgeArray< double > *pCost, List< edge > &delEdges) override
Computes a maximum c-planar subgraph, returns the set of edges that have to be deleted in delEdges if...
ReturnType
The return type of a module.
Definition Module.h:52
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
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.