Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::SpannerBerman< TWeight > Class Template Reference

Approximation algorithm for calculating spanners. More...

#include <ogdf/graphalg/SpannerBerman.h>

+ Inheritance diagram for ogdf::SpannerBerman< TWeight >:

Public Member Functions

 SpannerBerman ()
 
virtual ~SpannerBerman ()
 
virtual bool preconditionsOk (const GraphAttributes &GA, double stretch, std::string &error) override
 
- Public Member Functions inherited from ogdf::SpannerModule< TWeight >
 SpannerModule ()
 Initializes a spanner module.
 
virtual ~SpannerModule ()
 
virtual ReturnType call (const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner)
 Executes the algorithm.
 
int64_t getTimeNeeded ()
 
void setTimelimit (int64_t milliseconds)
 Sets the timelimit for the algorithm in milliseconds.
 
- Public Member Functions inherited from ogdf::Module
 Module ()
 Initializes a module.
 
virtual ~Module ()
 

Static Public Attributes

static Logger logger
 

Private Types

enum class  SeparationResult { NewConstraint , Fail , Solution }
 Used to indicate the result of the separation method. More...
 

Private Member Functions

bool _isThickEdge (edge e)
 Actually calculates whether e is thick or not.
 
void addEdgeToSpanner (edge e)
 Add an edge to the spanner.
 
void addUnsettledThickEdges ()
 
void calculateThickEdges ()
 
void createAntispanner (const edge unsettledThinEdge, const EdgeArray< bool > &out, EdgeArray< bool > &antispanner)
 
TWeight distance (const GraphCopySimple &G, const EdgeArray< TWeight > &weights, const node s, const node t, int maxLookupDist)
 
virtual SpannerModule< TWeight >::ReturnType execute () override
 Executes the core algorithm.
 
void firstPart ()
 First part of the algorithm: Settle all thick edges.
 
void inArborescence (const GraphAttributes &GA, node root, NodeArray< edge > &predecessor, NodeArray< TWeight > &distance)
 Calculates an in-arborescense rooted at root.
 
virtual void init (const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner) override
 Initializes members and create an empty spanner.
 
bool isSettledEdge (const edge e)
 Shortcut for calling isSettledEdge with m_spanner and the current spanner weights.
 
bool isSettledEdge (const edge e, const GraphCopySimple &_spanner, const EdgeArray< TWeight > &_spannerWeight)
 
bool isThickEdge (edge e)
 
bool isThinEdge (edge e)
 
void outArborescence (const GraphAttributes &GA, node root, NodeArray< edge > &predecessor, NodeArray< TWeight > &distance)
 Calculates an out-arborescense rooted at root.
 
void printStats (bool assert=false)
 
void randomizedSelection (const double *fractions, EdgeArray< bool > &out)
 
void resetLP ()
 Resets the LP defining variables.
 
bool secondPart ()
 The second part: Settling all thin edges.
 
SeparationResult separation (const double *solution, const EdgeArray< int > &indices)
 
bool setOpt (int opt)
 Set a new value for m_OPT.
 

Private Attributes

double m_beta
 sqrt(n)
 
std::vector< CoinPackedVector * > m_constraints
 Holds all constraints so they can be freed at destruction.
 
EdgeArray< boolm_E1
 Holds the set E1 from the first part of the algorithm.
 
EdgeArray< boolm_E2
 Holds the set E2 from the second part of the algorithm.
 
EpsilonTest m_eps
 
const Graphm_G
 const reference to the original graph
 
NodeArray< NodeArray< TWeight > > m_inDistance
 m_inDistance[v][w]: distance from v in a v-rooted in-arborescense to w
 
EdgeArray< boolm_isThickEdge
 
int m_nSquared
 n^2
 
int m_OPT
 The current guess for our optimal LP value.
 
OsiSolverInterfacem_osi
 the solver.
 
NodeArray< NodeArray< TWeight > > m_outDistance
 m_outDistance[v][w]: distance from v in a v-rooted out-arborescense to w
 
EdgeArray< TWeightm_spannerWeight
 weights for m_spanner Caches, if an edge is thick (or thin).
 
double m_sqrtlog
 sqrt(n) * ln(n)
 
int m_thickEdgeNodeAmountLimit
 n/beta
 
EdgeArray< TWeightm_weight
 weights of each edge from m_G
 

Additional Inherited Members

- Public Types inherited from ogdf::Module
enum class  ReturnType { Feasible , Optimal , NoFeasibleSolution , TimeoutFeasible , TimeoutInfeasible , Error }
 The return type of a module. More...
 
- Static Public Member Functions inherited from ogdf::SpannerModule< TWeight >
static void apspSpanner (const GraphAttributes &GA, const GraphCopySimple &spanner, NodeArray< NodeArray< TWeight > > &shortestPathMatrix)
 Calculates an all-pair shortest-path on spanner with the weights given by GA.
 
static bool isMultiplicativeSpanner (const GraphAttributes &GA, const GraphCopySimple &spanner, double stretch)
 Validates a spanner.
 
- Static Public Member Functions inherited from ogdf::Module
static bool isSolution (ReturnType ret)
 Returns true iff ret indicates that the module returned a feasible solution.
 
- Protected Member Functions inherited from ogdf::SpannerModule< TWeight >
void assertTimeLeft ()
 Assert, that time is left.
 
int64_t getTimeLeft ()
 
int getWeight (const GraphAttributes &GA, edge e)
 
double getWeight (const GraphAttributes &GA, edge e)
 
bool isTimelimitEnabled ()
 
- Static Protected Member Functions inherited from ogdf::SpannerModule< TWeight >
static TWeight getWeight (const GraphAttributes &GA, edge e)
 
- Protected Attributes inherited from ogdf::SpannerModule< TWeight >
const GraphAttributesm_GA
 
EdgeArray< bool > * m_inSpanner
 
GraphCopySimplem_spanner
 
double m_stretch
 

Detailed Description

template<typename TWeight>
class ogdf::SpannerBerman< TWeight >

Approximation algorithm for calculating spanners.

P. Berman, A. Bhattacharyya, K. Makarychev, S. Raskhodnikova und G. Yaroslavtsev. Approximation algorithms for spanner problems and Directed Steiner Forest. Information and Computation 222 (2013). 38th International Colloquium on Automata, Languages and Programming (ICALP 2011), S. 93–107. doi: https://doi.org/10.1016/j.ic. 2012.10.007.

Conditions for the graph:

  • simple
  • weakly connected: The graph must be connected, if acrs are seen as edges. To calculate a spanner on disconnected graphs use SpannerBermanDisconnected.

The stretch \(s\) must satisfy: \(s\geq1\in\mathbb{R}\).

The preconditions can be checked with SpannerBerman::preconditionsOk.

Calculates a k-spanner with an approximation ratio of \(\mathcal{O}(n^{1/2}\log n)\) for the size. The graph can be directed and weighted. Undirected and/or unweighted graphs still preserve the approximation ratio.

To enable logging you have to set the log level of the algorithm's logger to Logger::Level::Default or below:

// or
Approximation algorithm for calculating spanners.

Definition at line 76 of file SpannerBerman.h.

Member Enumeration Documentation

◆ SeparationResult

Used to indicate the result of the separation method.

Enumerator
NewConstraint 
Fail 
Solution 

Definition at line 109 of file SpannerBerman.h.

Constructor & Destructor Documentation

◆ SpannerBerman()

template<typename TWeight >
ogdf::SpannerBerman< TWeight >::SpannerBerman ( )
inline

Definition at line 80 of file SpannerBerman.h.

◆ ~SpannerBerman()

template<typename TWeight >
virtual ogdf::SpannerBerman< TWeight >::~SpannerBerman ( )
inlinevirtual

Definition at line 85 of file SpannerBerman.h.

Member Function Documentation

◆ _isThickEdge()

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::_isThickEdge ( edge  e)
inlineprivate

Actually calculates whether e is thick or not.

Definition at line 338 of file SpannerBerman.h.

◆ addEdgeToSpanner()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::addEdgeToSpanner ( edge  e)
inlineprivate

Add an edge to the spanner.

Only used in the first phase!

Definition at line 264 of file SpannerBerman.h.

◆ addUnsettledThickEdges()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::addUnsettledThickEdges ( )
inlineprivate

Definition at line 392 of file SpannerBerman.h.

◆ calculateThickEdges()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::calculateThickEdges ( )
inlineprivate

Definition at line 329 of file SpannerBerman.h.

◆ createAntispanner()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::createAntispanner ( const edge  unsettledThinEdge,
const EdgeArray< bool > &  out,
EdgeArray< bool > &  antispanner 
)
inlineprivate

Definition at line 583 of file SpannerBerman.h.

◆ distance()

template<typename TWeight >
TWeight ogdf::SpannerBerman< TWeight >::distance ( const GraphCopySimple G,
const EdgeArray< TWeight > &  weights,
const node  s,
const node  t,
int  maxLookupDist 
)
inlineprivate

Definition at line 381 of file SpannerBerman.h.

◆ execute()

template<typename TWeight >
virtual SpannerModule< TWeight >::ReturnType ogdf::SpannerBerman< TWeight >::execute ( )
inlineoverrideprivatevirtual

Executes the core algorithm.

Called after initialization. This method is used for the timelimit, so do not forget to call assertTimeLeft from time to time.

Implements ogdf::SpannerModule< TWeight >.

Definition at line 183 of file SpannerBerman.h.

◆ firstPart()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::firstPart ( )
inlineprivate

First part of the algorithm: Settle all thick edges.

Definition at line 209 of file SpannerBerman.h.

◆ inArborescence()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::inArborescence ( const GraphAttributes GA,
node  root,
NodeArray< edge > &  predecessor,
NodeArray< TWeight > &  distance 
)
inlineprivate

Calculates an in-arborescense rooted at root.

Definition at line 246 of file SpannerBerman.h.

◆ init()

template<typename TWeight >
virtual void ogdf::SpannerBerman< TWeight >::init ( const GraphAttributes GA,
double  stretch,
GraphCopySimple spanner,
EdgeArray< bool > &  inSpanner 
)
inlineoverrideprivatevirtual

Initializes members and create an empty spanner.

Reimplemented from ogdf::SpannerModule< TWeight >.

Definition at line 157 of file SpannerBerman.h.

◆ isSettledEdge() [1/2]

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::isSettledEdge ( const edge  e)
inlineprivate

Shortcut for calling isSettledEdge with m_spanner and the current spanner weights.

Definition at line 367 of file SpannerBerman.h.

◆ isSettledEdge() [2/2]

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::isSettledEdge ( const edge  e,
const GraphCopySimple _spanner,
const EdgeArray< TWeight > &  _spannerWeight 
)
inlineprivate
Returns
true, if the edge is settles in the given spanner.

Definition at line 372 of file SpannerBerman.h.

◆ isThickEdge()

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::isThickEdge ( edge  e)
inlineprivate

Definition at line 139 of file SpannerBerman.h.

◆ isThinEdge()

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::isThinEdge ( edge  e)
inlineprivate

Definition at line 137 of file SpannerBerman.h.

◆ outArborescence()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::outArborescence ( const GraphAttributes GA,
node  root,
NodeArray< edge > &  predecessor,
NodeArray< TWeight > &  distance 
)
inlineprivate

Calculates an out-arborescense rooted at root.

Definition at line 255 of file SpannerBerman.h.

◆ preconditionsOk()

template<typename TWeight >
virtual bool ogdf::SpannerBerman< TWeight >::preconditionsOk ( const GraphAttributes GA,
double  stretch,
std::string &  error 
)
inlineoverridevirtual

Returns
true, if the given GA and stretch are valid for a specific algorithm. If not, an error message is provided via error

Implements ogdf::SpannerModule< TWeight >.

Definition at line 88 of file SpannerBerman.h.

◆ printStats()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::printStats ( bool  assert = false)
inlineprivate

Definition at line 272 of file SpannerBerman.h.

◆ randomizedSelection()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::randomizedSelection ( const double fractions,
EdgeArray< bool > &  out 
)
inlineprivate

Definition at line 574 of file SpannerBerman.h.

◆ resetLP()

template<typename TWeight >
void ogdf::SpannerBerman< TWeight >::resetLP ( )
inlineprivate

Resets the LP defining variables.

Deletes m_osi as well as every entry in m_constraints. Sets both variables to nullptr/empty list.

Definition at line 146 of file SpannerBerman.h.

◆ secondPart()

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::secondPart ( )
inlineprivate

The second part: Settling all thin edges.

Definition at line 410 of file SpannerBerman.h.

◆ separation()

template<typename TWeight >
SeparationResult ogdf::SpannerBerman< TWeight >::separation ( const double solution,
const EdgeArray< int > &  indices 
)
inlineprivate

Definition at line 509 of file SpannerBerman.h.

◆ setOpt()

template<typename TWeight >
bool ogdf::SpannerBerman< TWeight >::setOpt ( int  opt)
inlineprivate

Set a new value for m_OPT.

Logs about the new value and modifies the LP.

Returns
false, if the new value is too large. If so, the calculation can be aborted.

Definition at line 494 of file SpannerBerman.h.

Member Data Documentation

◆ logger

template<typename TWeight >
Logger ogdf::SpannerBerman< TWeight >::logger
static

Definition at line 78 of file SpannerBerman.h.

◆ m_beta

template<typename TWeight >
double ogdf::SpannerBerman< TWeight >::m_beta
private

sqrt(n)

Definition at line 120 of file SpannerBerman.h.

◆ m_constraints

template<typename TWeight >
std::vector<CoinPackedVector*> ogdf::SpannerBerman< TWeight >::m_constraints
private

Holds all constraints so they can be freed at destruction.

Definition at line 132 of file SpannerBerman.h.

◆ m_E1

template<typename TWeight >
EdgeArray<bool> ogdf::SpannerBerman< TWeight >::m_E1
private

Holds the set E1 from the first part of the algorithm.

Definition at line 124 of file SpannerBerman.h.

◆ m_E2

template<typename TWeight >
EdgeArray<bool> ogdf::SpannerBerman< TWeight >::m_E2
private

Holds the set E2 from the second part of the algorithm.

Definition at line 125 of file SpannerBerman.h.

◆ m_eps

template<typename TWeight >
EpsilonTest ogdf::SpannerBerman< TWeight >::m_eps
private

Definition at line 135 of file SpannerBerman.h.

◆ m_G

template<typename TWeight >
const Graph* ogdf::SpannerBerman< TWeight >::m_G
private

const reference to the original graph

Definition at line 111 of file SpannerBerman.h.

◆ m_inDistance

template<typename TWeight >
NodeArray<NodeArray<TWeight> > ogdf::SpannerBerman< TWeight >::m_inDistance
private

m_inDistance[v][w]: distance from v in a v-rooted in-arborescense to w

Definition at line 127 of file SpannerBerman.h.

◆ m_isThickEdge

template<typename TWeight >
EdgeArray<bool> ogdf::SpannerBerman< TWeight >::m_isThickEdge
private

Definition at line 116 of file SpannerBerman.h.

◆ m_nSquared

template<typename TWeight >
int ogdf::SpannerBerman< TWeight >::m_nSquared
private

n^2

Definition at line 119 of file SpannerBerman.h.

◆ m_OPT

template<typename TWeight >
int ogdf::SpannerBerman< TWeight >::m_OPT
private

The current guess for our optimal LP value.

Definition at line 133 of file SpannerBerman.h.

◆ m_osi

the solver.

Initial nullptr since it is initialized in the second phase.

Definition at line 131 of file SpannerBerman.h.

◆ m_outDistance

template<typename TWeight >
NodeArray<NodeArray<TWeight> > ogdf::SpannerBerman< TWeight >::m_outDistance
private

m_outDistance[v][w]: distance from v in a v-rooted out-arborescense to w

Definition at line 128 of file SpannerBerman.h.

◆ m_spannerWeight

template<typename TWeight >
EdgeArray<TWeight> ogdf::SpannerBerman< TWeight >::m_spannerWeight
private

weights for m_spanner Caches, if an edge is thick (or thin).

Use isThinEdge and isThickEdge for access. It is fully cached after calling calculateThickEdges

Definition at line 113 of file SpannerBerman.h.

◆ m_sqrtlog

template<typename TWeight >
double ogdf::SpannerBerman< TWeight >::m_sqrtlog
private

sqrt(n) * ln(n)

Definition at line 121 of file SpannerBerman.h.

◆ m_thickEdgeNodeAmountLimit

template<typename TWeight >
int ogdf::SpannerBerman< TWeight >::m_thickEdgeNodeAmountLimit
private

n/beta

Definition at line 122 of file SpannerBerman.h.

◆ m_weight

template<typename TWeight >
EdgeArray<TWeight> ogdf::SpannerBerman< TWeight >::m_weight
private

weights of each edge from m_G

Definition at line 112 of file SpannerBerman.h.


The documentation for this class was generated from the following file: