Interface WeightedGraph<V>

Type Parameters:
V - the vertex type | 顶点类型
All Superinterfaces:
Graph<V>

public interface WeightedGraph<V> extends Graph<V>
Weighted Graph 加权图

Interface for weighted graph operations with additional weight-related methods.

加权图操作接口,包含额外的权重相关方法。

Features | 特性:

  • All Graph operations | 所有Graph操作
  • Weight modification | 权重修改
  • Total weight calculation | 总权重计算

Usage Examples | 使用示例:

WeightedGraph<String> graph = WeightedGraph.directed();
graph.addEdge("A", "B", 5.0);
graph.setWeight("A", "B", 10.0);
double total = graph.totalWeight();

Security | 安全性:

  • Thread-safe: Depends on implementation - 线程安全: 取决于实现
  • Null-safe: Yes (rejects null vertices) - 空值安全: 是(拒绝null顶点)
Since:
JDK 25, opencode-base-graph V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • setWeight

      boolean setWeight(V from, V to, double weight)
      Set the weight of an edge 设置边的权重
      Parameters:
      from - the source vertex | 源顶点
      to - the target vertex | 目标顶点
      weight - the new weight | 新权重
      Returns:
      true if edge exists and weight was updated | 如果边存在且权重已更新返回true
    • totalWeight

      default double totalWeight()
      Get the total weight of all edges 获取所有边的总权重
      Returns:
      total weight | 总权重
    • minWeight

      default double minWeight()
      Get the minimum edge weight 获取最小边权重
      Returns:
      minimum weight, or Double.MAX_VALUE if no edges | 最小权重,如果无边则返回Double.MAX_VALUE
    • maxWeight

      default double maxWeight()
      Get the maximum edge weight 获取最大边权重
      Returns:
      maximum weight, or Double.MIN_VALUE if no edges | 最大权重,如果无边则返回Double.MIN_VALUE
    • edgesInWeightRange

      default Set<Edge<V>> edgesInWeightRange(double minWeight, double maxWeight)
      Get edges with weight in range 获取权重在范围内的边
      Parameters:
      minWeight - minimum weight (inclusive) | 最小权重(包含)
      maxWeight - maximum weight (inclusive) | 最大权重(包含)
      Returns:
      set of edges in range | 范围内的边集合
    • directed

      static <V> WeightedGraph<V> directed()
      Create a directed weighted graph 创建有向加权图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new directed weighted graph | 新的有向加权图
    • undirected

      static <V> WeightedGraph<V> undirected()
      Create an undirected weighted graph 创建无向加权图
      Type Parameters:
      V - the vertex type | 顶点类型
      Returns:
      a new undirected weighted graph | 新的无向加权图