Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

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