Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 
60  MaximumCPlanarSubgraph() : m_heuristicLevel(1),
61  m_heuristicRuns(1),
62  m_heuristicOEdgeBound(0.4),
63  m_heuristicNPermLists(5),
64  m_kuratowskiIterations(10),
65  m_subdivisions(10),
66  m_kSupportGraphs(10),
67  m_kuratowskiHigh(0.8),
68  m_kuratowskiLow(0.8),
69  m_perturbation(false),
70  m_branchingGap(0.4),
71  m_time("00:20:00"),
72  m_pricing(false),
73  m_checkCPlanar(false),
74  m_numAddVariables(15),
75  m_strongConstraintViolation(0.3),
76  m_strongVariableViolation(0.3),
77  m_totalTime(-1.0),
78  m_heurTime(-1.0),
79  m_lpTime(-1.0),
80  m_lpSolverTime(-1.0),
81  m_sepTime(-1.0),
82  m_totalWTime(-1.0),
83  m_numCCons(-1),
84  m_numKCons(-1),
85  m_numLPs(-1),
86  m_numBCs(-1),
87  m_numSubSelected(-1),
88  m_portaOutput(false),
89  m_defaultCutPool(true) {}
90  //destruction
92 
101  /*
102  * @param ClusterGraph the graph that we want to compute a subgraph of
103  * @param pCost the cost of each edge or \c nullptr if edges should have uniform cost
104  * @param delEdges contains all deleted edges after the call
105  * @param addedEdges the set of edges that makes the subgraph connected
106  */
108  const ClusterGraph &G,
109  const EdgeArray<int> *pCost,
110  List<edge> &delEdges,
111  NodePairs &addedEdges) {
112  return doCall(G, pCost, delEdges, addedEdges);
113  }
114  //setter methods for the module parameters
115  void setHeuristicLevel(int i) {m_heuristicLevel = i;}
116  void setHeuristicRuns(int i) {m_heuristicRuns = i;}
117  void setHeuristicBound(double d) {m_heuristicOEdgeBound = d;}
118  void setNumberOfPermutations(int i) {m_heuristicNPermLists = i;}
119  void setNumberOfKuraIterations(int i) {m_kuratowskiIterations = i;}
120  void setNumberOfSubDivisions(int i) {m_subdivisions = i;}
121  void setNumberOfSupportGraphs(int i) {m_kSupportGraphs = i;}
122  void setUpperRounding(double d) {m_kuratowskiHigh = d;}
123  void setLowerRounding(double d) {m_kuratowskiLow = d;}
124  void setPerturbation(bool b) {m_perturbation = b;}
125  void setBranchingGap(double d) {m_branchingGap = d;}
126  void setTimeLimit(string s) {m_time = s.c_str();}
127  void setTimeLimit(std::chrono::milliseconds milliSec) {
128  // format string only supports seconds
129  OGDF_ASSERT( milliSec.count() >= 1000 );
130  // transform to format string
131  std::chrono::milliseconds remaining(milliSec);
132  auto h = std::chrono::duration_cast<std::chrono::hours>(remaining);
133  remaining -= h;
134  auto m = std::chrono::duration_cast<std::chrono::minutes>(remaining);
135  remaining -= m;
136  auto s = std::chrono::duration_cast<std::chrono::seconds>(remaining);
137  std::stringstream ss;
138  ss << h.count() << ":" << m.count() << ":" << s.count();
139  setTimeLimit(ss.str());
140  }
141  void setPortaOutput(bool b) {m_portaOutput = b;}
142  void setPricing(bool b) { m_pricing = b;}
143  void setCheckCPlanar(bool b) {m_checkCPlanar = b;}
144  void setNumAddVariables(int n) { m_numAddVariables = n;}
145  void setStrongConstraintViolation(double d) { m_strongConstraintViolation=d;}
146  void setStrongVariableViolation(double d) { m_strongVariableViolation=d;}
149  bool & useDefaultCutPool() {return m_defaultCutPool;}
150 
151  //getter methods for results
152  double getTotalTime() {return m_totalTime;}
153  double getHeurTime() {return m_heurTime;}
154  double getLPTime() {return m_lpTime;}
155  double getLPSolverTime() {return m_lpSolverTime;}
156  double getSeparationTime() {return m_sepTime;}
157  double getTotalWTime() {return m_totalWTime;}
159  int getNumCCons() {return m_numCCons;}
161  int getNumKCons() {return m_numKCons;}
163  int getNumLPs() {return m_numLPs;}
165  int getNumBCs() {return m_numBCs;}
167  int getNumSubSelected() {return m_numSubSelected;}
169  int getNumVars() {return m_numVars;}
170 
172  void writeFeasible(const char *filename, MaxCPlanarMaster &master,
173  abacus::Master::STATUS &status);
174 #ifdef OGDF_DEBUG
175  bool getSolByHeuristic(){return m_solByHeuristic;}
176 #endif
177 
178 
179 protected:
185  const ClusterGraph &G,
186  const EdgeArray<int> *pCost,
187  List<edge> &delEdges) override
188  {
189  NodePairs addEdges;
190  return doCall(G, pCost, delEdges, addEdges);
191  }
192 
193  //as above, also returns the set of edges that were
194  //added to construct a completely connected planar
195  //graph that contains the computed c-planar subgraph
196  virtual ReturnType doCall(
197  const ClusterGraph &G,
198  const EdgeArray<int> *pCost,
199  List<edge> &delEdges,
200  NodePairs &addedEdges);
201 
202  double getDoubleTime(const Stopwatch &act)
203  {
204  int64_t tempo = act.centiSeconds()+100*act.seconds()+6000*act.minutes()+360000*act.hours();
205  return ((double) tempo)/ 100.0;
206  }//getdoubletime
207 
209  void getBottomUpClusterList(const cluster c, List< cluster > & theList);
210 
211 private:
212  //Abacus Master class settings in order of appearance
213  int m_heuristicLevel, m_heuristicRuns;
215  int m_heuristicNPermLists, m_kuratowskiIterations;
216  int m_subdivisions, m_kSupportGraphs;
217  double m_kuratowskiHigh, m_kuratowskiLow;
220  string m_time;
221  bool m_pricing;//<! Decides if pricing is used
222  bool m_checkCPlanar;//<! If set to true, only c-planarity is checked
226 
227  const char* getPortaFileName()
228  {
229  return "porta.poi";
230  }
231  const char* getIeqFileName()
232  {
233  return "porta.ieq";
234  }
236  {
237  return 1024;
238  }
239  void outputCons(ofstream &os,
242 
243  //results
244  double m_totalTime; //<! Total computation time, returned from abacus
245  double m_heurTime; //<! Time spent in heuristic, returned from abacus
246  double m_lpTime; //<! Cpu time spent in members of the LP-interface, returned from abacus
247  double m_lpSolverTime; //<! Cpu time required by the LP solver, returned from abacus
248  double m_sepTime; //<! Cpu time spent in the separation of cutting planes, returned from abacus
249  double m_totalWTime; //<! Total wall clock time, returned from abacus
250  int m_numCCons; //<! Number of added connectivity constraints
251  int m_numKCons; //<! Number of added kuratowski constraints
252  int m_numLPs; //<! The number of optimized linear programs (LP-relax.).
253  int m_numBCs; //<! The number of generated subproblems.
254  int m_numSubSelected; //<! The number of subproblems selected by ABACUS.
255  int m_numVars; //<! The number of global variables.
256  bool m_portaOutput; //<! If set to true, output for PORTA in ieq format is generated.
257  bool m_defaultCutPool; //<! Passed through to master
258 #ifdef OGDF_DEBUG
259  bool m_solByHeuristic;
260 #endif
261 
262 };
263 
264 } //end namespace ogdf
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
ReturnType callAndConnect(const ClusterGraph &G, const EdgeArray< int > *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...
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...
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:39
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)
virtual ReturnType doCall(const ClusterGraph &G, const EdgeArray< int > *pCost, List< edge > &delEdges) override
Computes a maximum c-planar subgraph, returns the set of edges that have to be deleted in delEdges if...
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
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.