Class Graph

java.lang.Object
com.thomas.graphs.Weighted.Graph

public class Graph extends Object
An implenation of a graph that has weighted edges
  • Field Details

    • INFINITY

      public static final int INFINITY
      A quick reference for "Infinity"
      See Also:
    • vertices

      public List<Vertex> vertices
      The vertices in the graph
  • Constructor Details

    • Graph

      public Graph()
      Creates an empty graph
  • Method Details

    • addVertex

      public void addVertex(Vertex vertex)
      Adds a vertex to the graph
      Parameters:
      vertex - The vertex
    • addEdge

      public void addEdge(Vertex source, Vertex destination, int weight)
      Creates a new directional edge between a source vertex and a destination
      Parameters:
      source - The source Vertex
      destination - The destination vertex
      weight - The weight of the edge
    • dijkstra

      public void dijkstra(Vertex source) throws IllegalArgumentException
      An implemntation of Dijsktra's Algorithm
      Parameters:
      source - The source vertex
      Throws:
      IllegalArgumentException - If any of the weights are negative
    • bellmanFord

      public void bellmanFord(Vertex source) throws NegativeCycleException
      An implemntation of Bellman Ford's algorithm
      Parameters:
      source - The source vertex
      Throws:
      NegativeCycleException - if a negative Cycle is detected