All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgrapht.alg.interfaces.FlowAlgorithm Maven / Gradle / Ivy

The newest version!
/*
 * (C) Copyright 2018-2023, by Joris Kinable 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.*;

/**
 * Interface for flow algorithms
 *
 * @author Joris Kinable
 *
 * @param  the graph vertex type
 * @param  the graph edge type
 */
public interface FlowAlgorithm
{

    /**
     * Result object of a flow algorithm
     *
     * @return flow
     */
    default Flow getFlow()
    {
        return new FlowImpl<>(this.getFlowMap());
    }

    /**
     * Returns a read-only mapping from edges to the corresponding flow values.
     *
     * @return a read-only mapping from edges to the corresponding flow values.
     */
    Map getFlowMap();

    /**
     * For the specified {@code edge} $(u, v)$ returns vertex $v$ if the flow goes from $u$ to $v$,
     * or returns vertex $u$ otherwise. For directed flow networks the result is always the head of
     * the specified arc.
     * 

* Note: not all flow algorithms may support undirected graphs. * * @param edge an edge from the specified flow network * @return the direction of the flow on the {@code edge} */ V getFlowDirection(E edge); /** * Represents a flow. * * @param graph edge type */ interface Flow { /** * Returns the flow on the {@code edge} * * @param edge an edge from the flow network * @return the flow on the {@code edge} */ default double getFlow(E edge) { return getFlowMap().get(edge); } /** * Returns a mapping from the network flow edges to the corresponding flow values. The * mapping contains all edges of the flow network regardless of whether there is a non-zero * flow on an edge or not. * * @return a read-only map that defines a feasible flow. */ Map getFlowMap(); } /** * Default implementation of {@link Flow} * * @param graph edge type */ class FlowImpl implements Flow { /** * A mapping defining the flow on the network */ private Map flowMap; /** * Constructs a new flow * * @param flowMap the mapping defining the flow on the network */ public FlowImpl(Map flowMap) { this.flowMap = Collections.unmodifiableMap(flowMap); } /** * {@inheritDoc} */ @Override public Map getFlowMap() { return flowMap; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy