Class DirectedWeightedGraph<V,W>

java.lang.Object
org.episteme.core.mathematics.discrete.DirectedWeightedGraph<V,W>
All Implemented Interfaces:
Graph<V>, WeightedGraph<V,W>
Direct Known Subclasses:
BayesianBeliefNetwork

public class DirectedWeightedGraph<V,W> extends Object implements WeightedGraph<V,W>
Adjacency list implementation of a directed weighted graph.

Stores edges with weights using an adjacency list structure. Default weight is Real.ONE for backward compatibility.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Constructor Details

    • DirectedWeightedGraph

      public DirectedWeightedGraph()
      Creates a new directed weighted graph with Real.ONE as default weight.
    • DirectedWeightedGraph

      public DirectedWeightedGraph(W defaultWeight)
      Creates a new directed weighted graph with specified default weight.
      Parameters:
      defaultWeight - the default weight for unweighted edges
  • Method Details

    • vertices

      public Set<V> vertices()
      Description copied from interface: Graph
      Returns all vertices in this graph.
      Specified by:
      vertices in interface Graph<V>
      Returns:
      unmodifiable set of vertices
    • vertexCount

      public int vertexCount()
      Description copied from interface: Graph
      Returns the number of vertices in the graph.
      Specified by:
      vertexCount in interface Graph<V>
      Returns:
      the number of vertices
    • edges

      public Set<Graph.Edge<V>> edges()
      Description copied from interface: Graph
      Returns all edges in this graph.
      Specified by:
      edges in interface Graph<V>
      Returns:
      unmodifiable set of edges
    • addVertex

      public boolean addVertex(V vertex)
      Description copied from interface: Graph
      Adds a vertex to the graph.
      Specified by:
      addVertex in interface Graph<V>
      Parameters:
      vertex - the vertex to add
      Returns:
      true if vertex was added, false if already present
    • addEdge

      public boolean addEdge(V source, V target, W weight)
      Description copied from interface: WeightedGraph
      Adds a weighted edge to the graph.

      Vertices are automatically added if not already present.

      Specified by:
      addEdge in interface WeightedGraph<V,W>
      Parameters:
      source - the source vertex
      target - the target vertex
      weight - the edge weight
      Returns:
      true if the edge was added
    • getWeight

      public W getWeight(V source, V target)
      Description copied from interface: WeightedGraph
      Returns the weight of an edge.
      Specified by:
      getWeight in interface WeightedGraph<V,W>
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      the edge weight, or null if no such edge exists
    • getWeightedEdges

      public Set<WeightedEdge<V,W>> getWeightedEdges()
      Description copied from interface: WeightedGraph
      Returns all weighted edges in the graph.
      Specified by:
      getWeightedEdges in interface WeightedGraph<V,W>
      Returns:
      unmodifiable set of weighted edges
    • getWeightedEdgesFrom

      public Set<WeightedEdge<V,W>> getWeightedEdgesFrom(V vertex)
      Description copied from interface: WeightedGraph
      Returns weighted edges originating from a vertex.
      Specified by:
      getWeightedEdgesFrom in interface WeightedGraph<V,W>
      Parameters:
      vertex - the source vertex
      Returns:
      set of weighted edges from vertex
    • neighbors

      public Set<V> neighbors(V vertex)
      Description copied from interface: Graph
      Returns neighbors of a vertex.
      Specified by:
      neighbors in interface Graph<V>
      Parameters:
      vertex - the vertex
      Returns:
      set of adjacent vertices
    • degree

      public int degree(V vertex)
      Description copied from interface: Graph
      Returns the degree (number of edges) of a vertex.
      Specified by:
      degree in interface Graph<V>
      Parameters:
      vertex - the vertex
      Returns:
      degree of vertex
    • isDirected

      public boolean isDirected()
      Description copied from interface: Graph
      Checks if this graph is directed.
      Specified by:
      isDirected in interface Graph<V>
      Returns:
      true if directed, false if undirected
    • getDefaultWeight

      public W getDefaultWeight()
      Description copied from interface: WeightedGraph
      Returns the default weight for unweighted edge additions.

      Used when addEdge(V, V) is called without a weight. Subclasses should override to provide appropriate default.

      Specified by:
      getDefaultWeight in interface WeightedGraph<V,W>
      Returns:
      the default weight (e.g., 1.0, Real.ONE)