001/*
002MIT License
003
004Copyright (c) 2020 earlygrey
005
006Permission is hereby granted, free of charge, to any person obtaining a copy
007of this software and associated documentation files (the "Software"), to deal
008in the Software without restriction, including without limitation the rights
009to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010copies of the Software, and to permit persons to whom the Software is
011furnished to do so, subject to the following conditions:
012
013The above copyright notice and this permission notice shall be included in all
014copies or substantial portions of the Software.
015
016THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
022SOFTWARE.
023 */
024package squidpony.squidai.graph;
025
026import java.io.Serializable;
027import java.util.Collection;
028/**
029 * A kind of {@link Graph} where all connections between vertices are one-way (but a connection may exist that goes from
030 * A to B and another connection may go from B to A), and each connection can have a different cost.
031 * @see CostlyGraph The CostlyGraph class supports the common case where V is Coord and all costs are based on the cell being entered.
032 * @param <V> the vertex type; often {@link squidpony.squidmath.Coord}
033 * @author earlygrey
034 */
035public class DirectedGraph<V> extends Graph<V> implements Serializable {
036    private static final long serialVersionUID = 1L;
037
038    final DirectedGraphAlgorithms<V> algorithms;
039
040    //================================================================================
041    // Constructors
042    //================================================================================
043
044    public DirectedGraph () {
045        super();
046        algorithms = new DirectedGraphAlgorithms<>(this);
047    }
048
049    public DirectedGraph (Collection<V> vertices) {
050        super(vertices);
051        algorithms = new DirectedGraphAlgorithms<>(this);
052    }
053
054
055    //================================================================================
056    // Superclass implementations
057    //================================================================================
058
059    @Override
060    protected Connection<V> obtainEdge() {
061        return new Connection.DirectedConnection<>();
062    }
063
064    @Override
065    protected Graph<V> createNew() {
066        return new DirectedGraph<>();
067    }
068
069    @Override
070    public DirectedGraphAlgorithms<V> algorithms() {
071        return algorithms;
072    }
073
074}