Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

CP_MasterBase.h
Go to the documentation of this file.
1 
34 #pragma once
35 
37 #include <ogdf/basic/GraphCopy.h>
39 #include <ogdf/basic/Logger.h>
40 #include <ogdf/basic/ArrayBuffer.h>
41 #include <ogdf/lib/abacus/master.h>
42 
43 namespace ogdf {
44 namespace cluster_planarity {
45 
46 class CP_MasterBase : public abacus::Master {
47 public:
48 
50 
52  explicit CP_MasterBase(const ClusterGraph &C,
53  //Check what we really still need here
54  int heuristicLevel=1,
55  int heuristicRuns=2,
56  double heuristicOEdgeBound=0.3,
57  int heuristicNPermLists=5,
58  int kuratowskiIterations=3,
59  int subdivisions=10,
60  int kSupportGraphs=3,
61  double kuratowskiHigh=0.7,
62  double kuratowskiLow=0.3,
63  bool perturbation=false,
64  double branchingGap=0.4,
65  const char *time="00:05:00" /* maximum computation time */);
66 
68  virtual ~CP_MasterBase();
69 
70 #if 0
71  // Initialization of the first Subproblem
72  virtual Sub *firstSub();
73 #endif
74 
76  double epsilon() const {return m_epsilon;}
77 
79  int nMaxVars() const {return m_nMaxVars;}
80 
82  const Graph *getGraph() const {return m_G;}
83 
85  const ClusterGraph *getClusterGraph() const {return m_C;}
86 
88  // corresponding edges (::nodePair).
89  virtual void updateBestSubGraph(List<NodePair> &connection);
90 
92  virtual Graph *solutionInducedGraph() {return static_cast<Graph*>(m_solutionGraph);}
93 
95  virtual void getConnectionOptimalSolutionEdges(List<NodePair> &edges) const;
96 
97  void setTimeLimit(const char* s) {delete m_maxCpuTime; m_maxCpuTime = new string(s);}
98 
99  // Get parameters
101  int getNSubdivisions() const {return m_nSubdivisions;}
103  int getHeuristicLevel() const {return m_heuristicLevel;}
104  int getHeuristicRuns() const {return m_nHeuristicRuns;}
105  double getKBoundHigh() const {return m_kuratowskiBoundHigh;}
106  double getKBoundLow() const {return m_kuratowskiBoundLow;}
107  bool perturbation() const {return m_usePerturbation;}
108 #if 0
109  double branchingOEdgeSelectGap() const {return m_branchingGap;}
110 #endif
113  bool getMPHeuristic() const {return m_mpHeuristic;}
114  int getNumAddVariables() const {return m_numAddVariables;}
117 
118  // Read global constraint counter, i.e. the number of added constraints of specific type.
119  int addedKConstraints() const {return m_nKConsAdded;}
120  int addedCConstraints() const {return m_nCConsAdded;}
121 
122 
123  // Set parameters
128  void setKBoundHigh(double n) {m_kuratowskiBoundHigh = ((n>0.0 && n<1.0) ? n : 0.8);}
129  void setKBoundLow(double n) {m_kuratowskiBoundLow = ((n>0.0 && n<1.0) ? n : 0.2);}
130  void heuristicLevel(int level) {m_heuristicLevel = level;}
132  void setPertubation(bool b) {m_usePerturbation = b;}
135  void setMPHeuristic(bool b) {m_mpHeuristic = b;}
139 
141  void setPortaFile(bool b) {m_porta = b;}
142 
143  // Updating global constraint counter
144  void updateAddedCCons(int n) {m_nCConsAdded += n;}
145  void updateAddedKCons(int n) {m_nKConsAdded += n;}
146 
147  // Returns global primal and dual bounds.
149  double getDualBound() {return globalDualBound;}
150 
151  // Cut pools for connectivity and planarity
156 
160 
163  double intGap() {return 0.79;}
164 
165 #ifdef OGDF_DEBUG
166  bool m_solByHeuristic; //solution computed by heuristic or ILP
167  // Simple output function to print the given graph to the console.
168  // Used for debugging only.
169  void printGraph(const Graph &G);
170 #endif
171 
175  {
176  return "StdConstraints.txt";
177  }
178 
179  int getNumInactiveVars() { return m_inactiveVariables.size();}
180 
182 
183 protected:
184 
185  List<NodePair> m_connectionOneEdges; //<! Contains connection nodePairs whose variable is set to 1.0
186 
189  const Graph *m_G;
190 
191  // Each time the primal bound is improved, the integer solution induced Graph is built.
192  // #m_solutionGraph is a pointer to the currently best solution induced Graph.
193  // #m_solutionGraph is deleted in the destructor.
195 
199 
200  string *m_maxCpuTime;
201 
202  // Initializes constraints and variables and an initial dual bound.
203  virtual void initializeOptimization() override = 0;
204 
207  virtual void terminateOptimization() override;
208 
209  virtual double heuristicInitialLowerBound();
210 
213  virtual void createInitialVariables(List<CPlanarEdgeVar*>& initVars) = 0;
214 
215  // Computes a dual bound for the optimal solution.
216  // Tries to find as many edge-disjoint Kuratowski subdivisions as possible.
217  // If k edge-disjoint groups of subdivisions are found, the upper bound can be
218  // initialized with number of edges in underlying graph minus k.
219  virtual double heuristicInitialUpperBound();
220 
223  virtual bool isCP() = 0;
224 
225  // Node pair is potential candidate for new edge variable
226  virtual bool goodVar(node a, node b) { return true;}
227 
229 #if 0
230  //used in initialization
231  void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
232 #endif
234 
235 
236  // Parameters
237  int m_nKuratowskiSupportGraphs; // Maximal number of times the Kuratowski support graph is computed
238  int m_nKuratowskiIterations; // Maximal number of times BoyerMyrvold is invoked
239  int m_nSubdivisions; // Maximal number of extracted Kuratowski subdivisions
240  int m_nMaxVars; // Max Number of variables
241  int m_heuristicLevel; // Indicates if primal heuristic shall be used or not
242  int m_nHeuristicRuns; // Counts how often the primal heuristic has been called
243 
244  bool m_usePerturbation; // Indicates whether C-variables should be perturbated or not
245  double m_branchingGap; // Modifies the branching behaviour
247  int m_nHeuristicPermutationLists; // The number of permutation lists used in the primal heuristic
249  // should be used to derive lower bound if only root cluster exists
250 
251  double m_kuratowskiBoundHigh; // Upper bound for deterministic edge addition in computation of the Supportgraph
252  double m_kuratowskiBoundLow; // Lower bound for deterministic edge deletion in computation of the Supportgraph
253 
254  int m_numAddVariables; // how many variables should i add maximally per pricing round?
255  double m_strongConstraintViolation; // when do i consider a constraint strongly violated -> separate in first stage
256  double m_strongVariableViolation; // when do i consider a variable strongly violated (red.cost) -> separate in first stage
257 
258  // Counters for the number of added constraints
272  inline void clearActiveRepairs() {
273  if(m_activeRepairs) {
274  m_repairStat.push(m_activeRepairs);
275  m_activeRepairs = 0;
276  }
277  }
278 
281 
282  inline double getDoubleTime(const Stopwatch* act) {
283  int64_t tempo = act->centiSeconds()+100*act->seconds()+6000*act->minutes()+360000*act->hours();
284  return ((double) tempo)/ 100.0;
285  }
286 
287 #if 0
288  //number of calls of the fast max planar subgraph heuristic
289  const int m_fastHeuristicRuns;
290 #endif
291 
292 private:
293  // Is invoked by heuristicInitialLowerBound()
294  virtual double clusterConnection(cluster c, GraphCopy &GC);
295 
297  virtual void createCompConnVars(List<CPlanarEdgeVar*>& initVars);
298 
299  // Computes the (here: graphtheoretical) distances of edges incident to node \p u.
300  virtual void nodeDistances(node u, NodeArray<NodeArray<int> > &dist);
301 
302  // The basic objective function coefficient for connection edges.
303  double m_epsilon;
304 #if 0
305  // If perturbation is used, this variable stores the largest occuring coeff,
306  // i.e. the one closest to 0. Otherwise it corresponds to #m_epsilon
307  double m_largestConnectionCoeff;
308 #endif
309 
313 
315 #if 0
316  double m_delta;
317  double m_deltaCount;
318 #endif
319  //Switch to minimization of additional edges, no delta necessary
320 #if 1
321  virtual double nextConnectCoeff() {return 1.0;}
322 #else
323  virtual double nextConnectCoeff() { return -1 + m_deltaCount--*m_delta; }
324 #endif
327  ++m_varsAdded;
328  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), (*it).source, (*it).target);
329  v->printMe(Logger::slout());
330  m_inactiveVariables.del(it);
331  //we don't need to check symmetry
332  m_varCreated[(*it).source][(*it).target] = true;
333  return v;
334  }
337  OGDF_ASSERT(!(m_varCreated[a][b] || m_varCreated[b][a]));
338  ++m_varsAdded;
339  CPlanarEdgeVar* v = new CPlanarEdgeVar(this, nextConnectCoeff(), a, b);
340  v->printMe(Logger::slout());
341  // we don't need to check symmetry
342  m_varCreated[a][b] = true;
343  return v;
344  }
345 #if 0
347 
348  //used in initialization
349  void generateVariablesForFeasibility(const List<ChunkConnection*>& ccons, List<CPlanarEdgeVar*>& connectVars);
350 
353 #endif
354 
356  bool m_porta;
359  virtual void getCoefficients(abacus::Constraint* con, const List<CPlanarEdgeVar* > & connect,
360  List<double> & coeffs);
361 };
362 
363 }
364 }
virtual bool isCP()=0
Derives and returns c-planarity property either directly or indirectly from computation results...
const Graph * getGraph() const
Returns a pointer to the underlying Graph.
Definition: CP_MasterBase.h:82
void printMe(ostream &out) override
The master of the optimization.
Definition: master.h:69
const ClusterGraph * m_C
Pointers to the given Clustergraph and underlying Graph are stored.
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
Declaration and implementation of ArrayBuffer class.
bool m_mpHeuristic
Indicates if simple max planar subgraph heuristic.
virtual void getCoefficients(abacus::Constraint *con, const List< CPlanarEdgeVar * > &connect, List< double > &coeffs)
writes coefficients of all orig and connect variables in constraint con into emptied list coeffs ...
virtual void nodeDistances(node u, NodeArray< NodeArray< int > > &dist)
virtual void initializeOptimization() override=0
The default implementation of initializeOptimization() does nothing.
int64_t minutes() const
Returns the currently elapsed time in minutes.
Definition: Stopwatch.h:121
double getDoubleTime(const Stopwatch *act)
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:95
int64_t centiSeconds() const
Returns the currently elapsed time in 1/100-seconds.
Definition: Stopwatch.h:107
virtual Graph * solutionInducedGraph()
Returns the optimal solution induced Clustergraph.
Definition: CP_MasterBase.h:92
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutConnPool()
Returns cut pool for connectivity.
virtual Sub * firstSub()=0
Should return a pointer to the first subproblem of the optimization, i.e., the root node of the enume...
the master of the optimization.
void del(iterator it)
Removes it from the list.
Definition: List.h:1380
abacus::StandardPool< abacus::Constraint, abacus::Variable > * getCutKuraPool()
Returns cut pool for planarity.
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
friend class Sub
Definition: master.h:71
bool m_useDefaultCutPool
Defines if the ABACUS default cut pool or the separate Connectivity and Kuratowski constraint pools a...
Representation of clustered graphs.
Definition: ClusterGraph.h:291
int nMaxVars() const
Returns the number of variables.
Definition: CP_MasterBase.h:79
bool m_porta
If set to true, PORTA output is written in a file.
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
virtual bool goodVar(node a, node b)
double epsilon() const
Returns the objective function coefficient of C-edges.
Definition: CP_MasterBase.h:76
CP_MasterBase(const ClusterGraph &C, int heuristicLevel=1, int heuristicRuns=2, double heuristicOEdgeBound=0.3, int heuristicNPermLists=5, int kuratowskiIterations=3, int subdivisions=10, int kSupportGraphs=3, double kuratowskiHigh=0.7, double kuratowskiLow=0.3, bool perturbation=false, double branchingGap=0.4, const char *time="00:05:00")
Construction and default values.
Contains logging functionality.
virtual void getConnectionOptimalSolutionEdges(List< NodePair > &edges) const
Returns nodePairs of connecting optimal solution edges in list edges.
virtual CPlanarEdgeVar * createVariable(ListIterator< NodePair > &it)
Variable creation for nodePair.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
Declaration of graph copy classes.
void setPortaFile(bool b)
If set to true, PORTA output is written in a file.
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutConnPool
Cut pools for connectivity and Kuratowski constraints.
const char * getStdConstraintsFileName()
The name of the file that contains the standard, i.e., non-cut, constraints (may be deleted by ABACUS...
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:250
Declaration of the variable class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph prob...
List< NodePair > m_connectionOneEdges
stores optimization success state
Class for the representation of nodes.
Definition: Graph_d.h:167
Encapsulates a pointer to a list element.
Definition: List.h:41
virtual ~CP_MasterBase()
Destruction.
double intGap()
Returns a value that allows to distinguish result values when connection edges (tiny negative cost) a...
static std::ostream & slout(Level l=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
void setMPHeuristic(bool b)
Switches use of lower bound heuristic.
virtual void createInitialVariables(List< CPlanarEdgeVar *> &initVars)=0
All variables that have to be present at start of optimization are created here.
const ClusterGraph * getClusterGraph() const
Returns a pointer to the given Clustergraph.
Definition: CP_MasterBase.h:85
virtual double clusterConnection(cluster c, GraphCopy &GC)
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:53
NodeArray< NodeArray< bool > > m_varCreated
Keeps track of variables that are currently inactive during optimization.
virtual void terminateOptimization() override
Function that is invoked at the end of the optimization. Does nothing but output in CP_MasterBase...
int64_t seconds() const
Returns the currently elapsed time in seconds.
Definition: Stopwatch.h:114
abacus::StandardPool< abacus::Constraint, abacus::Variable > * m_cutKuraPool
Kuratowski Cuts.
virtual void createCompConnVars(List< CPlanarEdgeVar *> &initVars)
Creates variables for complete connectivity.
int m_nKuratowskiSupportGraphs
Keeps track of created variables.
int64_t hours() const
Returns the currently elapsed time in hours.
Definition: Stopwatch.h:128
bool & useDefaultCutPool()
Returns true if default cut pool is used. Otherwise, separate connectivity and Kuratowski pools are g...
The namespace for all OGDF objects.
virtual CPlanarEdgeVar * createVariable(node a, node b)
Variable creation for pair of nodes which is not stored in m_inactiveVariables.
Declaration of the master class for the Branch&Cut algorithm for the Maximum C-Planar SubGraph proble...
string * m_maxCpuTime
Time threshold for optimization.
virtual void updateBestSubGraph(List< NodePair > &connection)
Updates the "best" Subgraph m_solutionGraph found so far and fills connection with.
Realizes a stopwatch for measuring elapsed time.
Definition: Stopwatch.h:43
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41