Interface WeightedGraph<V,W>

All Superinterfaces:
Graph<V>
All Known Implementing Classes:
BayesianBeliefNetwork, DirectedWeightedGraph, SocialNetwork

public interface WeightedGraph<V,W> extends Graph<V>
A graph with weighted edges.

Extends the basic Graph interface to support edges with numeric weights. Weights can be any comparable type (Real, Integer, Double, etc.).

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

    • addEdge

      boolean addEdge(V source, V target, W weight)
      Adds a weighted edge to the graph.

      Vertices are automatically added if not already present.

      Parameters:
      source - the source vertex
      target - the target vertex
      weight - the edge weight
      Returns:
      true if the edge was added
    • getWeight

      W getWeight(V source, V target)
      Returns the weight of an edge.
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      the edge weight, or null if no such edge exists
    • getWeightedEdges

      Set<WeightedEdge<V,W>> getWeightedEdges()
      Returns all weighted edges in the graph.
      Returns:
      unmodifiable set of weighted edges
    • getWeightedEdgesFrom

      Set<WeightedEdge<V,W>> getWeightedEdgesFrom(V vertex)
      Returns weighted edges originating from a vertex.
      Parameters:
      vertex - the source vertex
      Returns:
      set of weighted edges from vertex
    • hasEdge

      default boolean hasEdge(V source, V target, W weight)
      Checks if an edge exists with a specific weight.
      Parameters:
      source - the source vertex
      target - the target vertex
      weight - the expected weight
      Returns:
      true if edge exists with given weight
    • getDefaultWeight

      W getDefaultWeight()
      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.

      Returns:
      the default weight (e.g., 1.0, Real.ONE)
    • addEdge

      default boolean addEdge(V source, V target)
      Adds an unweighted edge using the default weight.

      Maintains backward compatibility with Graph interface.

      Specified by:
      addEdge in interface Graph<V>
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      true if edge was added