Skip to content

Commit

Permalink
self loops and direction option for complemtent
Browse files Browse the repository at this point in the history
  • Loading branch information
lypoluz committed Jan 24, 2024
1 parent cb39155 commit c493447
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 5 additions & 6 deletions include/ogdf/basic/graph_generators/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ OGDF_EXPORT void rootedProduct(const Graph& G1, const Graph& G2, Graph& product,
* Computes the complement of G.
*
* @param G is the input graph, the complement will be assigned to G.
* @param keep_directionality, default false. Whether directionality should be considered when computing the complement graph.
* @param directional Whether directionality should be considered when computing the complement graph. (default is false)
* @param allow_self_loops Whether to allow self loops, if false and G contains self loops, these will not be removed. (default is false)
*/
OGDF_EXPORT void complement(Graph& G, bool keep_directionality = false);

OGDF_EXPORT void complement(Graph& G, bool directional = false, bool allow_self_loops = false);
/**
* Computes the intersection of G1 and G2. The output will be assigned to G1.
*
* @param G1 is the first graph, the intersection will be assigned to G1.
* @param G1 is the second graph.
* @param G2 is the second graph.
* @param nodeMap associates a node in G2 with a node in G1. There should be an entry for every node in G1, this entry may be a nullptr.
*/
OGDF_EXPORT void intersection(Graph& G1, const Graph& G2, const NodeArray<node>& nodeMap);
Expand All @@ -210,7 +210,7 @@ OGDF_EXPORT void intersection(Graph& G1, const Graph& G2, const NodeArray<node>&
* \f$ (V = V_1 \cup V_2, E = E_1 \cup E_2 \cup V_1 \cross V_2) \f$
*
* @param G1 is the first graph, the joined graph will be assigned to G1.
* @param G1 is the second graph.
* @param G2 is the second graph.
* @param nodeMap is assigned a mapping from nodes in \p G2 to new nodes in G1. It should be initialized like this: NodeArray<node> nodeMap(G2);
*/
OGDF_EXPORT void join(Graph& G1, const Graph& G2, NodeArray<node>& nodeMap);
Expand All @@ -219,5 +219,4 @@ OGDF_EXPORT void join(Graph& G1, const Graph& G2, NodeArray<node>& nodeMap);
//! @}

/** @} */

}
22 changes: 18 additions & 4 deletions src/ogdf/basic/graph_generators/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,20 +251,34 @@ void rootedProduct(const Graph& G1, const Graph& G2, Graph& product, NodeMap& no
});
}

void complement(Graph& G, bool keep_directionality) {
void complement(Graph& G, bool directional, bool allow_self_loops) {
for (node n1 : G.nodes) {
for (node n2 : G.nodes) {
if (n1->index() >= n2->index()) {
if (n1->index() > n2->index()) {
continue;
}
if (!allow_self_loops && n1->index() == n2->index()) {
continue;
}

edge e = G.searchEdge(n1, n2, true);
edge er = G.searchEdge(n2, n1, true);

if (e) {
G.delEdge(e);
} else if (er) {
}
if (er) {
G.delEdge(er);
} else {
}

if (directional) {
if (!e) {
G.newEdge(n1, n2);
}
if (!er && !allow_self_loops) {
G.newEdge(n2, n1);
}
} else if (!e && !er) {
G.newEdge(n1, n2);
}
}
Expand Down

0 comments on commit c493447

Please sign in to comment.