computeRoutes method

LinkStateRoutingTable<T> computeRoutes(
  1. Map<T, Map<T, num>> network,
  2. T sourceNode, {
  3. Map<String, dynamic>? topologyOptimizations,
})

Computes complete routing table using link-state algorithm

network - Network topology as adjacency list sourceNode - Source node for routing table computation topologyOptimizations - Optional topology optimization parameters

Returns complete routing table with optimal paths

Throws ArgumentError if source node doesn't exist in network

Implementation

LinkStateRoutingTable<T> computeRoutes(
  Map<T, Map<T, num>> network,
  T sourceNode, {
  Map<String, dynamic>? topologyOptimizations,
}) {
  // Input validation
  if (!network.containsKey(sourceNode)) {
    throw ArgumentError('Source node $sourceNode not found in network');
  }

  // Apply topology optimizations to network if enabled
  Map<T, Map<T, num>> optimizedNetwork = network;
  if (enableTopologyOptimization && topologyOptimizations != null) {
    optimizedNetwork = _applyTopologyOptimizationsToNetwork(
      network,
      topologyOptimizations,
    );
  }

  // Build complete link-state database
  final lsdb = _buildLinkStateDatabase(optimizedNetwork);

  // Compute optimal routes using Dijkstra's algorithm
  final routes = _computeOptimalRoutes(lsdb, sourceNode);

  // Compress paths if enabled
  if (enablePathCompression) {
    _compressPaths(routes);
  }

  return LinkStateRoutingTable<T>(
    sourceNode: sourceNode,
    routes: Map.unmodifiable(routes),
    topology: lsdb,
    lastUpdate: DateTime.now(),
    totalRoutes: routes.length,
    totalNodes: network.length,
  );
}