protected void seedLeftSideForFirstIteration()

in graphjet-core/src/main/java/com/twitter/graphjet/algorithms/salsa/SalsaIterations.java [105:146]


  protected void seedLeftSideForFirstIteration() {
    long queryNode = salsaInternalState.getSalsaRequest().getQueryNode();
    salsaStats.setNumDirectNeighbors(
        salsaInternalState.getBipartiteGraph().getLeftNodeDegree(queryNode));

    Long2DoubleMap seedNodesWithWeight =
        salsaInternalState.getSalsaRequest().getLeftSeedNodesWithWeight();
    LongSet nonZeroSeedSet = salsaInternalState.getNonZeroSeedSet();

    double totalWeight = 0.0;
    for (Long2DoubleMap.Entry entry : seedNodesWithWeight.long2DoubleEntrySet()) {
      if (salsaInternalState.getBipartiteGraph().getLeftNodeDegree(entry.getLongKey())
          > 0) {
        totalWeight += entry.getDoubleValue();
        nonZeroSeedSet.add(entry.getLongKey());
      }
    }

    // If there is a pre-specified weight, we let it take precedence, but if not, then we reset
    // weights in accordance with the fraction of weight requested for the query node.
    if (!seedNodesWithWeight.containsKey(queryNode)
        && salsaInternalState.getBipartiteGraph().getLeftNodeDegree(queryNode) > 0) {
      double queryNodeWeight = 1.0;
      if (totalWeight > 0.0) {
        queryNodeWeight =
            totalWeight * salsaInternalState.getSalsaRequest().getQueryNodeWeightFraction()
                / (1.0 - salsaInternalState.getSalsaRequest().getQueryNodeWeightFraction());
      }
      seedNodesWithWeight.put(queryNode, queryNodeWeight);
      totalWeight += queryNodeWeight;
      nonZeroSeedSet.add(queryNode);
    }

    for (long leftNode : nonZeroSeedSet) {
      int numWalksToStart = (int) Math.ceil(
          seedNodesWithWeight.get(leftNode) / totalWeight
              * salsaInternalState.getSalsaRequest().getNumRandomWalks());
        salsaInternalState.getCurrentLeftNodes().put(leftNode, numWalksToStart);
    }

    salsaStats.setNumSeedNodes(salsaInternalState.getCurrentLeftNodes().size());
  }