org.jgrapht.alg.interfaces.MaximumFlowAlgorithm Maven / Gradle / Ivy
The newest version!
/*
* (C) Copyright 2015-2023, by Alexey Kudinkin and Contributors.
*
* JGraphT : a free Java graph-theory library
*
* See the CONTRIBUTORS.md file distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the
* GNU Lesser General Public License v2.1 or later
* which is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1-standalone.html.
*
* SPDX-License-Identifier: EPL-2.0 OR LGPL-2.1-or-later
*/
package org.jgrapht.alg.interfaces;
import java.util.*;
/**
* Allows to derive maximum-flow
* from the supplied flow network
*
* @author Alexey Kudinkin
* @author Joris Kinable
*
* @param the graph vertex type
* @param the graph edge type
*
*/
public interface MaximumFlowAlgorithm
extends FlowAlgorithm
{
/**
* Sets current source to source
, current sink to sink
, then
* calculates maximum flow from source
to sink
. Returns an object
* containing detailed information about the flow.
*
* @param source source of the flow inside the network
* @param sink sink of the flow inside the network
*
* @return maximum flow
*/
MaximumFlow getMaximumFlow(V source, V sink);
/**
* Sets current source to source
, current sink to sink
, then
* calculates maximum flow from source
to sink
. Note, that
* source
and sink
must be vertices of the
* network
passed to the constructor, and they must be different.
*
* @param source source vertex
* @param sink sink vertex
* @return the value of the maximum flow
*/
default double getMaximumFlowValue(V source, V sink)
{
return getMaximumFlow(source, sink).getValue();
}
/**
* A maximum flow
*
* @param the graph edge type
*/
interface MaximumFlow
extends Flow
{
/**
* Returns value of the maximum-flow for the given network
*
* @return value of the maximum-flow
*/
Double getValue();
}
/**
* Default implementation of the maximum flow
*
* @param the graph edge type
*/
class MaximumFlowImpl
extends FlowImpl
implements MaximumFlow
{
private Double value;
/**
* Create a new maximum flow
*
* @param value the flow value
* @param flow the flow map
*/
public MaximumFlowImpl(Double value, Map flow)
{
super(flow);
this.value = value;
}
@Override
public Double getValue()
{
return value;
}
@Override
public String toString()
{
return "Flow Value: " + value + "\nFlow map:\n" + getFlowMap();
}
}
}