Skip to content

Refactor metric calculations #7

Description

@starovoid
  1. Avoid .unwrap().
    Where .unwrap() appears as a result of comparing distances, it may be necessary to impose additional restrictions on the types used.

  2. Add MetricCalculator type with methods

  • weighted(bool)
  • center()
  • diameter()
  • radius()
  • periphery()
  • eccentricity()

At now, each of the metric functions calculates a distance matrix at the beginning of its work. The MetricsCalculator will lazily calculate the distance matrix once, and then use it when calling metric methods.
For a weighted graph, the distance matrix will be calculated using the Floyd-Warshall algorithm, for an unweighted graph, BFS will be used.

  1. Additionally, the MetricCalculator will have the
with_distance_mapping(mut self, distances: FnMut(G::NodeId, G::NodeId) -> FloatMeasure) -> Self

method, which allows you to specify the working distance map/matrix in advance.
This can be useful if you already have a distance matrix and don't want to calculate it again.

  1. Add function
fn floyd_wharshall_distances(...) -> FnMut((G::NodeId, G::NodeID)) -> K,

for simple getting distance mapping.

  1. The currently available functions for finding metrics should remain unchanged, but they will call the MetricCalculator inside themselves.

P.s. I will be very glad to suggestions on how to further improve the API or optimize calculations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions