Пример #1
0
  @Override
  public double centrality(WeightedGraph<Integer> weightedGraph, Integer node) {

    ArrayList<Integer> allNodesButThis = new ArrayList<>(weightedGraph.allNodes());
    allNodesButThis.remove(node);

    List<PathBetweenNodes<Integer>> allShortestPaths =
        weightedGraph
            .allNodes()
            .stream()
            .flatMap(
                n1 ->
                    weightedGraph
                        .allNodes()
                        .stream()
                        .filter(n2 -> n1 != n2)
                        .map(n2 -> weightedGraph.shortestPath(n1, n2)))
            .filter(path -> path.isPresent())
            .map(path -> path.get())
            .collect(Collectors.toList());

    double pathsWithNode =
        allShortestPaths.stream().filter((path) -> (path.getNodes().contains(node))).count();

    double centrality = pathsWithNode / allShortestPaths.size();
    return centrality;
  }
Пример #2
0
  /**
   * Devuelve el grado con el que el grupo indicado es un clique.
   *
   * @param datasetLoader
   * @param group Grupo a comprobar.
   * @return Valor difuso con el que un grupo es un clique.
   */
  @Override
  public double getMeasure(DatasetLoader<? extends Rating> datasetLoader, GroupOfUsers group)
      throws CannotLoadRatingsDataset {

    WeightedGraph<Integer> trustNetwork =
        getWeightedGraphCalculation().computeTrustValues(datasetLoader, group.getIdMembers());

    double sumDistance = 0;

    for (int idMember1 : group.getIdMembers()) {
      for (int idMember2 : group.getIdMembers()) {
        double distance;
        distance = trustNetwork.distance(idMember1, idMember2);
        sumDistance += distance;
      }
    }
    return sumDistance;
  }