code: private void weightGraphGenerateHelper(TopologySpec topologySpec) {
      try {
        Map<ServiceNode, ServiceNode> capabilities = topologySpec.getSpecExecutor().getCapabilities().get();
        for (Map.Entry<ServiceNode, ServiceNode> capability : capabilities.entrySet()) {
  
          BaseServiceNodeImpl sourceNode = new BaseServiceNodeImpl(capability.getKey().getNodeName());
          BaseServiceNodeImpl targetNode = new BaseServiceNodeImpl(capability.getValue().getNodeName());
  
          if (!weightedGraph.containsVertex(sourceNode)) {
            weightedGraph.addVertex(sourceNode);
          }
          if (!weightedGraph.containsVertex(targetNode)) {
            weightedGraph.addVertex(targetNode);
          }
  
          FlowEdge flowEdge =
              new LoadBasedFlowEdgeImpl(sourceNode, targetNode, defaultFlowEdgeProps, topologySpec.getSpecExecutor());
  
          // In Multi-Graph if flowEdge existed, just skip it.
          if (!weightedGraph.containsEdge(flowEdge)) {
            weightedGraph.addEdge(sourceNode, targetNode, flowEdge);
          }
        }
      } catch (InterruptedException | ExecutionException e) {
        Instrumented.markMeter(this.flowCompilationFailedMeter);
        throw new RuntimeException("Cannot determine topology capabilities", e);
      }
    }
docs: Helper function for transform TopologySpecMap into a weightedDirectedGraph.