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 <chrono>
47 #include <cstdint>
48 #include <sstream>
49 #include <string>
50 
51 namespace abacus {
52 template<class BaseType, class CoType>
53 class StandardPool;
54 } // namespace abacus
55 
56 namespace ogdf {
57 
59 
63 public:
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 
223 protected:
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 
247  void getBottomUpClusterList(const cluster c, List<cluster>& theList);
248 
249 private:
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::MaximumCPlanarSubgraph::m_pricing
bool m_pricing
Definition: MaximumCPlanarSubgraph.h:259
ogdf::MaximumCPlanarSubgraph::setHeuristicRuns
void setHeuristicRuns(int i)
Definition: MaximumCPlanarSubgraph.h:131
Graph.h
Includes declaration of graph class.
ogdf::MaximumCPlanarSubgraph::getPortaFileName
const char * getPortaFileName()
Definition: MaximumCPlanarSubgraph.h:265
ogdf::MaximumCPlanarSubgraph::m_totalWTime
double m_totalWTime
Definition: MaximumCPlanarSubgraph.h:281
ogdf::MaximumCPlanarSubgraph::m_solByHeuristic
bool m_solByHeuristic
Definition: MaximumCPlanarSubgraph.h:291
ogdf::MaximumCPlanarSubgraph::useDefaultCutPool
bool & useDefaultCutPool()
Use default abacus master cut pool or dedicated connectivity and kuratowski cut pools.
Definition: MaximumCPlanarSubgraph.h:182
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:107
ogdf::MaximumCPlanarSubgraph::getTotalTime
double getTotalTime()
Definition: MaximumCPlanarSubgraph.h:185
ogdf::MaximumCPlanarSubgraph::m_totalTime
double m_totalTime
Definition: MaximumCPlanarSubgraph.h:276
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:172
ogdf::MaximumCPlanarSubgraph::setNumberOfPermutations
void setNumberOfPermutations(int i)
Definition: MaximumCPlanarSubgraph.h:135
ogdf::MaximumCPlanarSubgraph::m_defaultCutPool
bool m_defaultCutPool
Definition: MaximumCPlanarSubgraph.h:289
ogdf::MaximumCPlanarSubgraph::setTimeLimit
void setTimeLimit(string s)
Definition: MaximumCPlanarSubgraph.h:151
ogdf::MaximumCPlanarSubgraph::setPricing
void setPricing(bool b)
Definition: MaximumCPlanarSubgraph.h:170
ogdf::MaximumCPlanarSubgraph::MaximumCPlanarSubgraph
MaximumCPlanarSubgraph()
Construction.
Definition: MaximumCPlanarSubgraph.h:68
ogdf::MaximumCPlanarSubgraph::setNumberOfKuraIterations
void setNumberOfKuraIterations(int i)
Definition: MaximumCPlanarSubgraph.h:137
ogdf::MaximumCPlanarSubgraph::setUpperRounding
void setUpperRounding(double d)
Definition: MaximumCPlanarSubgraph.h:143
abacus
Definition: ILPClusterPlanarity.h:50
ogdf::MaximumCPlanarSubgraph::setStrongConstraintViolation
void setStrongConstraintViolation(double d)
Definition: MaximumCPlanarSubgraph.h:176
ogdf::MaximumCPlanarSubgraph::getLPTime
double getLPTime()
Definition: MaximumCPlanarSubgraph.h:189
ogdf::MaximumCPlanarSubgraph::m_kuratowskiLow
double m_kuratowskiLow
Definition: MaximumCPlanarSubgraph.h:255
ogdf::MaximumCPlanarSubgraph::getSeparationTime
double getSeparationTime()
Definition: MaximumCPlanarSubgraph.h:193
ogdf::MaximumCPlanarSubgraph::getIeqFileName
const char * getIeqFileName()
Definition: MaximumCPlanarSubgraph.h:267
ogdf::MaximumCPlanarSubgraph::setNumberOfSupportGraphs
void setNumberOfSupportGraphs(int i)
Definition: MaximumCPlanarSubgraph.h:141
ogdf::MaximumCPlanarSubgraph::getNumCCons
int getNumCCons()
Returns number of connectivity constraints added during computation.
Definition: MaximumCPlanarSubgraph.h:198
ogdf::MaximumCPlanarSubgraph::getSolByHeuristic
bool getSolByHeuristic()
Definition: MaximumCPlanarSubgraph.h:219
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:147
ogdf::MaximumCPlanarSubgraph::setNumAddVariables
void setNumAddVariables(int n)
Definition: MaximumCPlanarSubgraph.h:174
ogdf::MaximumCPlanarSubgraph::m_numAddVariables
int m_numAddVariables
Definition: MaximumCPlanarSubgraph.h:261
abacus::StandardPool< abacus::Constraint, abacus::Variable >
ogdf::MaximumCPlanarSubgraph::getNumBCs
int getNumBCs()
Returns number of generated LPs.
Definition: MaximumCPlanarSubgraph.h:207
ogdf::MaximumCPlanarSubgraph::m_heurTime
double m_heurTime
Definition: MaximumCPlanarSubgraph.h:277
ogdf::MaximumCPlanarSubgraph::setHeuristicLevel
void setHeuristicLevel(int i)
Definition: MaximumCPlanarSubgraph.h:129
ogdf::MaximumCPlanarSubgraph::setTimeLimit
void setTimeLimit(std::chrono::milliseconds milliSec)
Definition: MaximumCPlanarSubgraph.h:153
ogdf::MaximumCPlanarSubgraph::setNumberOfSubDivisions
void setNumberOfSubDivisions(int i)
Definition: MaximumCPlanarSubgraph.h:139
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:204
ogdf::MaximumCPlanarSubgraph::maxConLength
int maxConLength()
Definition: MaximumCPlanarSubgraph.h:269
ogdf::MaximumCPlanarSubgraph::m_portaOutput
bool m_portaOutput
Definition: MaximumCPlanarSubgraph.h:288
ogdf::MaximumCPlanarSubgraph::m_strongConstraintViolation
double m_strongConstraintViolation
Definition: MaximumCPlanarSubgraph.h:262
ogdf::MaximumCPlanarSubgraph::getHeurTime
double getHeurTime()
Definition: MaximumCPlanarSubgraph.h:187
ogdf::MaximumCPlanarSubgraph::m_perturbation
bool m_perturbation
Definition: MaximumCPlanarSubgraph.h:256
ogdf::MaximumCPlanarSubgraph::getNumKCons
int getNumKCons()
Returns number of Kuratowski constraints added during computation.
Definition: MaximumCPlanarSubgraph.h:201
ogdf::MaximumCPlanarSubgraph::m_heuristicOEdgeBound
double m_heuristicOEdgeBound
Definition: MaximumCPlanarSubgraph.h:252
ogdf::MaximumCPlanarSubgraph::m_numCCons
int m_numCCons
Definition: MaximumCPlanarSubgraph.h:282
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:123
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:62
ogdf::MaximumCPlanarSubgraph::m_subdivisions
int m_subdivisions
Definition: MaximumCPlanarSubgraph.h:254
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:286
ogdf::MaximumCPlanarSubgraph::setPortaOutput
void setPortaOutput(bool b)
Definition: MaximumCPlanarSubgraph.h:168
ogdf::MaximumCPlanarSubgraph::setHeuristicBound
void setHeuristicBound(double d)
Definition: MaximumCPlanarSubgraph.h:133
ogdf::MaximumCPlanarSubgraph::getTotalWTime
double getTotalWTime()
Definition: MaximumCPlanarSubgraph.h:195
ogdf::MaximumCPlanarSubgraph::m_strongVariableViolation
double m_strongVariableViolation
Definition: MaximumCPlanarSubgraph.h:263
ogdf::MaximumCPlanarSubgraph::getNumVars
int getNumVars()
Returns number of global variables. Todo: Real number from ABACUS.
Definition: MaximumCPlanarSubgraph.h:213
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:285
ogdf::MaximumCPlanarSubgraph::setStrongVariableViolation
void setStrongVariableViolation(double d)
Definition: MaximumCPlanarSubgraph.h:178
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:228
ogdf::MaximumCPlanarSubgraph::m_numVars
int m_numVars
Definition: MaximumCPlanarSubgraph.h:287
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:251
ogdf::MaximumCPlanarSubgraph::m_kuratowskiIterations
int m_kuratowskiIterations
Definition: MaximumCPlanarSubgraph.h:253
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:260
ogdf::AlgorithmFailureCode::StandardPool
@ StandardPool
ogdf::MaximumCPlanarSubgraph::setBranchingGap
void setBranchingGap(double d)
Definition: MaximumCPlanarSubgraph.h:149
ogdf::MaximumCPlanarSubgraph::m_sepTime
double m_sepTime
Definition: MaximumCPlanarSubgraph.h:280
ogdf::MaximumCPlanarSubgraph::getNumSubSelected
int getNumSubSelected()
Returns number of subproblems selected by ABACUS.
Definition: MaximumCPlanarSubgraph.h:210
ogdf::MaximumCPlanarSubgraph::setLowerRounding
void setLowerRounding(double d)
Definition: MaximumCPlanarSubgraph.h:145
ogdf::MaximumCPlanarSubgraph::m_numKCons
int m_numKCons
Definition: MaximumCPlanarSubgraph.h:283
ogdf::MaximumCPlanarSubgraph::m_branchingGap
double m_branchingGap
Definition: MaximumCPlanarSubgraph.h:257
ogdf::MaximumCPlanarSubgraph::m_time
string m_time
Definition: MaximumCPlanarSubgraph.h:258
ogdf::Module::ReturnType
ReturnType
The return type of a module.
Definition: Module.h:52
ogdf::MaximumCPlanarSubgraph::m_lpTime
double m_lpTime
Definition: MaximumCPlanarSubgraph.h:278
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::MaximumCPlanarSubgraph::getDoubleTime
double getDoubleTime(const Stopwatch &act)
Definition: MaximumCPlanarSubgraph.h:240
ogdf::MaximumCPlanarSubgraph::m_numLPs
int m_numLPs
Definition: MaximumCPlanarSubgraph.h:284
ogdf::MaximumCPlanarSubgraph::m_lpSolverTime
double m_lpSolverTime
Definition: MaximumCPlanarSubgraph.h:279
ogdf::MaximumCPlanarSubgraph::getLPSolverTime
double getLPSolverTime()
Definition: MaximumCPlanarSubgraph.h:191
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716