/*
 * (C) Copyright 2013-2017, by Alexey Kudinkin and Contributors.
 *
 * JGraphT : a free Java graph-theory library
 *
 * This program and the accompanying materials are dual-licensed under
 * either
 *
 * (a) the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation, or (at your option) any
 * later version.
 *
 * or (per the licensee's choosing)
 *
 * (b) the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation.
 */
package org.jgrapht.alg.interfaces;

import java.io.*;
import java.util.*;

/**
 * An algorithm which computes a  spanning
 * tree of a given connected graph. In the case of disconnected graphs it would rather derive a
 * spanning forest.
 *
 * @param  the graph edge type
 */
public interface SpanningTreeAlgorithm
{
    /**
     * Computes a spanning tree.
     *
     * @return a spanning tree
     */
    SpanningTree getSpanningTree();

    /**
     * A spanning tree.
     *
     * @param  the graph edge type
     */
    interface SpanningTree
    {
        /**
         * Returns the weight of the spanning tree.
         * 
         * @return weight of the spanning tree
         */
        double getWeight();

        /**
         * Set of edges of the spanning tree.
         * 
         * @return edge set of the spanning tree
         */
        Set getEdges();
    }

    /**
     * Default implementation of the spanning tree interface.
     *
     * @param  the graph edge type
     */
    class SpanningTreeImpl
        implements SpanningTree, Serializable
    {
        private static final long serialVersionUID = 402707108331703333L;

        private final double weight;
        private final Set edges;

        /**
         * Construct a new spanning tree.
         *
         * @param edges the edges
         * @param weight the weight
         */
        public SpanningTreeImpl(Set edges, double weight)
        {
            this.edges = edges;
            this.weight = weight;
        }

        @Override
        public double getWeight()
        {
            return weight;
        }

        @Override
        public Set getEdges()
        {
            return edges;
        }

        @Override
        public String toString()
        {
            return "Spanning-Tree [weight=" + weight + ", edges=" + edges + "]";
        }
    }

}

 

Ads help maintain this website.