Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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