Class WeightedGraphBuilder<V,W>

java.lang.Object
org.episteme.core.mathematics.discrete.WeightedGraphBuilder<V,W>

public class WeightedGraphBuilder<V,W> extends Object
Fluent builder for weighted graphs.

Provides a convenient API for constructing weighted graphs:

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

    • directed

      public static <V,W> WeightedGraphBuilder<V,W> directed()
      Creates a builder for a directed weighted graph.
      Type Parameters:
      V - the type of vertices
      W - the type of edge weights
      Returns:
      a new builder
    • directed

      public static <V,W> WeightedGraphBuilder<V,W> directed(W defaultWeight)
      Creates a builder for a directed weighted graph with custom default weight.
      Type Parameters:
      V - the type of vertices
      W - the type of edge weights
      Parameters:
      defaultWeight - the default weight for unweighted edges
      Returns:
      a new builder
    • addVertex

      public WeightedGraphBuilder<V,W> addVertex(V vertex)
      Adds a vertex to the graph.
      Parameters:
      vertex - the vertex to add
      Returns:
      this builder for chaining
    • addVertices

      @SafeVarargs public final WeightedGraphBuilder<V,W> addVertices(V... vertices)
      Adds multiple vertices to the graph.
      Parameters:
      vertices - the vertices to add
      Returns:
      this builder for chaining
    • addEdge

      public WeightedGraphBuilder<V,W> addEdge(V source, V target, W weight)
      Adds a weighted edge to the graph.
      Parameters:
      source - the source vertex
      target - the target vertex
      weight - the edge weight
      Returns:
      this builder for chaining
    • addEdge

      public WeightedGraphBuilder<V,W> addEdge(V source, V target)
      Adds an unweighted edge using the default weight.
      Parameters:
      source - the source vertex
      target - the target vertex
      Returns:
      this builder for chaining
    • build

      public WeightedGraph<V,W> build()
      Builds and returns the graph.
      Returns:
      the constructed weighted graph