Class Graph

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

public class Graph extends Object
A simple Graph class for searching algorithms
See Also:
  • Field Details

  • Constructor Details

    • Graph

      public Graph()
      Creates a new Graph
  • Method Details

    • addVertex

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

      public void addEdge(Vertex source, Vertex destination)
      Adds an unweighted edge to the graph
      Parameters:
      source - The source vertex
      destination - The destination vertex
    • addEdge

      public void addEdge(Vertex source, Vertex destination, int weight)
      Adds an edge to the graph
      Parameters:
      source - The source vertex
      destination - The desitunation vertex
      weight - The weight of going to the destination
    • addUndirectedEdge

      public void addUndirectedEdge(Vertex v1, Vertex v2, int weight)
      Creates an undirected edge in the graph between two vertices
      Parameters:
      v1 - The first vertex
      v2 - The other vertex
      weight - The weight between the two vertices
    • addUndirectedEdge

      public void addUndirectedEdge(Vertex v1, Vertex v2)
      Creates an unweighted, undirected edge in the graph between tow vertices
      Parameters:
      v1 - The one vertex
      v2 - The other vertex
    • getNeightbours

      public List<Edge> getNeightbours(Vertex v)
      Gets the neightbours of a vertex
      Parameters:
      v - The vertex
      Returns:
      The neightbours
    • getVertices

      public Set<Vertex> getVertices()
      Gets the vertices in the graph
      Returns:
      The vertices
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • bfs

      public Map<Vertex,Path> bfs(Vertex start)
      The Breath-first Search algorithm
      Parameters:
      start - The starting vertex
      Returns:
      A Map of all vertices and their distnace from the starting vertex
      See Also: