45 template<
typename TCost>
65 bool primaryCut =
true,
bool calculateOtherCut =
true,
79 return call(graph, weight, s, t, edgeList, e_st);
195 std::unique_ptr<EpsilonTest>
m_et;
215 while (!queue.
empty()) {
222 m_et->less(m_flow[e], m_weight[e]))
223 || ((frontCut ? e->target() : e->source()) == v &&
224 m_et->greater(m_flow[e], TCost(0))))) {
227 frontCut ? m_frontCutCount++ : m_backCutCount++;
253 if(m_primaryCut || m_calculateOtherCut) {
255 markCut(source,
true, origNode);
258 if(!m_primaryCut || m_calculateOtherCut) {
260 markCut(target,
false, origNode);
265 node startNode = (m_primaryCut ? source : target);
272 adj = (m_primaryCut ? adj->cyclicSucc() : adj->cyclicPred()))
274 if (adj->theEdge()->adjTarget() != adj) {
275 stack.
push(adj->theEdge());
278 while (!stack.
empty()) {
280 if (visited[origEdge(e)]) {
283 visited[origEdge(e)] =
true;
295 adj = (m_primaryCut ? adj->cyclicSucc() : adj->cyclicPred()))
297 if (adj->theEdge()->adjTarget() != adj) {
298 stack.
push(adj->theEdge());
306 template<
typename TCost>
313 if (e_st !=
nullptr) {
321 for (
edge e : edges) {
322 if (m_treatAsUndirected) {
334 edge origEdge = originalEdge[e];
335 m_weight[e] = weight[origEdge];
339 m_mfModule->init(*
m_gc);
340 m_mfModule->computeFlow(m_weight, s, t, m_flow);
343 [&](
edge e) ->
edge {
return originalEdge[e];},
350 template<
typename TCost>
354 const node source,
const node target) {
363 source, target, edgeList);
node target() const
Returns the target node of the edge.
void move(edge e, adjEntry adjSrc, Direction dirSrc, adjEntry adjTgt, Direction dirTgt)
Moves edge e to a different adjacency list.
void markCut(node startNode, bool frontCut, std::function< node(node)> origNode)
Mark the all nodes which are in the same cut partition as the startNode.
EdgeArray< TCost > m_weight
EdgeElement * edge
The type of edges.
std::unique_ptr< EpsilonTest > m_et
void setEpsilonTest(EpsilonTest *et)
Assigns a new epsilon test.
bool isBackCutEdge(const edge e) const
Returns whether this edge is entering the back cut.
edge theEdge() const
Returns the edge associated with this adjacency entry.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
bool frontCutIsComplementOfBackCut() const
Returns whether the front cut is the complement of the backcut.
void init()
Reinitializes the array. Associates the array with no graph.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Data type for general directed graphs (adjacency list representation).
bool m_calculateOtherCut
iff true, the other (near to s for primaryCut == false, near to t for primaryCut == true) cut should ...
void init()
Reinitializes the array. Associates the array with no graph.
Min-st-cut algorithm, that calculates the cut via maxflow.
cutType
The three types of cuts.
bool m_primaryCut
true if the algorithm should search for the mincut nearest to s, false if it should be near to t...
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
EdgeArray< TCost > m_flow
Declaration and implementation of Goldberg-Tarjan max-flow algorithm with global relabeling and gap r...
edge newEdge(edge eOrig)
Creates a new edge (v,w) with original edge eOrig.
bool isOfType(const node v, cutType type) const
Return whether this node is of the specified type.
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
bool isInFrontCut(const node v) const
Returns whether this node is part of the front cut.
void push(const E &x)
Adds element x as top-most element to the stack.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
NodeArray< cutType > m_nodeSet
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
void allEdges(EDGELIST &edgeList) const
Returns a list with all edges of the graph.
E popFrontRet()
Removes the first element from the list and returns it.
Copies of graphs supporting edge splitting.
NodeElement * node
The type of nodes.
virtual bool call(const Graph &graph, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
Class for the representation of nodes.
bool isFrontCutEdge(const edge e) const
Returns whether this edge is leaving the front cut.
const Graph & original() const
Returns a reference to the original graph.
adjEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
E pop()
Removes the top-most element from the stack and returns it.
bool m_treatAsUndirected
states whether or not edges are considered undirected while calculating the maxflow ...
node is not part of any cut
virtual bool call(const Graph &graph, const EdgeArray< TCost > &weight, node s, node t, List< edge > &edgeList, edge e_st) override
The actual algorithm call.
node source() const
Returns the source node of the edge.
void computeCut(const Graph &graph, std::function< edge(edge)> origEdge, std::function< node(node)> origNode, const node source, const node target, List< edge > &edgeList)
Partitions the nodes to front and back cut.
bool isInBackCut(const node v) const
Returns whether this node is part of the back cut.
The namespace for all OGDF objects.
bool empty() const
Returns true iff the stack is empty.
int numberOfNodes() const
Returns the number of nodes in the graph.
Template of base class of min-st-cut algorithms.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
MinSTCutMaxFlow(bool treatAsUndirected=true, MaxFlowModule< TCost > *mfModule=new MaxFlowGoldbergTarjan< TCost >(), bool primaryCut=true, bool calculateOtherCut=true, EpsilonTest *epsilonTest=new EpsilonTest())
Constructor.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
bool empty() const
Returns true iff the list is empty.
Computes a max flow via Preflow-Push (global relabeling and gap relabeling heuristic).
Class for adjacency list elements.
std::unique_ptr< MaxFlowModule< TCost > > m_mfModule
the module used for calculating the maxflow
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.