From be83d504f89f0bc5ad4406c01d9dad736dd70429 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Fri, 20 Dec 2019 12:52:08 +0100 Subject: [PATCH] autopilot: introduce NodeMetric interface for arbitrary graph metrics This commit adds the NodeMetric interface which will be used for all graph metrics not directly part of the autopilot but are useful in composite heuristics to drive autopilot decisions and improve node scores. --- autopilot/interface.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/autopilot/interface.go b/autopilot/interface.go index b63661e3..7efeba76 100644 --- a/autopilot/interface.go +++ b/autopilot/interface.go @@ -147,6 +147,23 @@ type AttachmentHeuristic interface { map[NodeID]*NodeScore, error) } +// NodeMetric is a common interface for all graph metrics that are not +// directly used as autopilot node scores but may be used in compositional +// heuristics or statistical information exposed to users. +type NodeMetric interface { + // Name returns the unique name of this metric. + Name() string + + // Refresh refreshes the metric values based on the current graph. + Refresh(graph ChannelGraph) error + + // GetMetric returns the latest value of this metric. Values in the + // map are per node and can be in arbitrary domain. If normalize is + // set to true, then the returned values are normalized to either + // [0, 1] or [-1, 1] depending on the metric. + GetMetric(normalize bool) map[NodeID]float64 +} + // ScoreSettable is an interface that indicates that the scores returned by the // heuristic can be mutated by an external caller. The ExternalScoreAttachment // currently implements this interface, and so should any heuristic that is