83template<
typename TWeight>
92 std::string& error)
override {
94 error =
"The graph must be undirected";
98 error =
"The stretch must be 2.0";
102 error =
"The graph is not simple";
106 error =
"The graph must be unweighted";
122 node maxNode =
nullptr;
123 double maxDensity = 0.0;
132 for (
adjEntry adj : v->adjEntries) {
133 neighborGraph.
newNode(adj->twinNode());
136 if (neighborGraph.
copy(e->target()) !=
nullptr
137 && neighborGraph.
copy(e->source()) !=
nullptr) {
144 int64_t timelimit = -1;
146 timelimit = max(
static_cast<int64_t
>(0),
getTimeLeft());
149 neighborGraph, denseSubset,
161 if (denseSubset.
isMember(e->source()) && denseSubset.
isMember(e->target())) {
167 double density = denseSubset.
size() == 0
169 :
static_cast<double>(E_U.
size()) / denseSubset.
size();
171 maxDensity = density;
173 maxDenseSubset = denseSubset;
200 for (
edge e : maxE_U) {
Compare floating point numbers with epsilons and integral numbers with normal compare operators.
Includes declaration of graph class.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration of graph copy classes.
Decralation of GraphElement and GraphList classes.
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
Declaration of doubly linked lists and iterators.
Declares maximum density subgraph algorithms.
Basic module for spanner algorithms.
Basic declarations, included by all source files.
Class for adjacency list elements.
Class for the representation of edges.
std::enable_if< std::is_integral< T >::value, bool >::type less(const T &x, const T &y) const
Compare if x is LESS than y for integral types.
std::enable_if< std::is_integral< T >::value, bool >::type greater(const T &x, const T &y) const
Compare if x is GREATER than y for integral types.
Stores additional attributes of a graph (like layout information).
bool directed() const
Returns if the graph is directed.
const Graph & constGraph() const
Returns a reference to the associated graph.
static const long edgeDoubleWeight
Corresponds to edge attribute doubleWeight(edge).
bool has(long attr) const
Returns true iff all attributes in attr are available.
static const long edgeIntWeight
Corresponds to edge attribute intWeight(edge).
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
void init(const Graph &G)
Re-initializes the copy using G, creating copies for all nodes and edges in G.
const Graph & original() const
Returns a reference to the original graph.
Copies of graphs with mapping between nodes and edges.
edge newEdge(edge eOrig)
Creates a new edge in the graph copy with original edge eOrig.
void setOriginalGraph(const Graph *G) override
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
void delEdge(edge e) override
Removes edge e.
void clear() override
Removes all nodes and edges from this copy but does not break the link with the original graph.
edge copy(edge e) const override
Returns the edge in the graph copy corresponding to e.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
edge searchEdge(node v, node w, bool directed=false) const
Searches and returns an edge connecting nodes v and w in time O( min(deg(v ), deg(w ))).
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Doubly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
ReturnType
The return type of a module.
Class for the representation of nodes.
const list_type & nodes()
Returns a reference to the list of nodes contained in this set.
int size() const
Returns the number of elements in this set.
bool isMember(element_type v) const
Returns true iff element v is contained in this set.
Approximation multiplicative 2-spanner calculation.
virtual bool preconditionsOk(const GraphAttributes &GA, double stretch, std::string &error) override
void addToSpanner(edge e)
Adds e from m_G to the spanner and sets inSpanner.
virtual void init(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner) override
Initializes members and create an empty spanner.
GraphCopySimple m_G
The copy of GA.constGraph() to work on. Edges will be removed in each iteration.
virtual SpannerModule< TWeight >::ReturnType execute() override
Executes the core algorithm.
Interface for spanner algorithms.
void assertTimeLeft()
Assert, that time is left.
bool isTimelimitEnabled()
virtual void init(const GraphAttributes &GA, double stretch, GraphCopySimple &spanner, EdgeArray< bool > &inSpanner)
Initializes members and create an empty spanner.
const GraphAttributes * m_GA
EdgeArray< bool > * m_inSpanner
GraphCopySimple * m_spanner
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
bool maximumDensitySubgraph(Graph &G, NodeSet &subgraphNodes, std::function< node(node)> resultNodeMap=[](node v) { return v;}, int64_t timelimit=-1)
Calculates the maximum density subgraph of G.
bool isSimple(const Graph &G)
Returns true iff G contains neither self-loops nor parallel edges.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
The namespace for all OGDF objects.
Declaration of simple graph algorithms.
A simple exception used to exit from the execution, if the timelimit is reached.