routing: create mc getWeight method
This commit is contained in:
parent
a3f7dbc633
commit
843c87a203
@ -260,16 +260,25 @@ func (m *MissionControl) getProbAfterFail(lastFailure time.Time) float64 {
|
|||||||
|
|
||||||
timeSinceLastFailure := m.now().Sub(lastFailure)
|
timeSinceLastFailure := m.now().Sub(lastFailure)
|
||||||
|
|
||||||
// Calculate success probability. It is an exponential curve that brings
|
// Calculate success probability based on the weight of the last
|
||||||
// the probability down to zero when a failure occurs. From there it
|
// failure. When the failure is fresh, its weight is 1 and we'll return
|
||||||
// recovers asymptotically back to the a priori probability. The rate at
|
// probability 0. Over time the probability recovers to the a priori
|
||||||
// which this happens is controlled by the penaltyHalfLife parameter.
|
// probability.
|
||||||
exp := -timeSinceLastFailure.Hours() / m.cfg.PenaltyHalfLife.Hours()
|
weight := m.getWeight(timeSinceLastFailure)
|
||||||
probability := m.cfg.AprioriHopProbability * (1 - math.Pow(2, exp))
|
probability := m.cfg.AprioriHopProbability * (1 - weight)
|
||||||
|
|
||||||
return probability
|
return probability
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getWeight calculates a weight in the range [0, 1] that should be assigned to
|
||||||
|
// a payment result. Weight follows an exponential curve that starts at 1 when
|
||||||
|
// the result is fresh and asymptotically approaches zero over time. The rate at
|
||||||
|
// which this happens is controlled by the penaltyHalfLife parameter.
|
||||||
|
func (m *MissionControl) getWeight(age time.Duration) float64 {
|
||||||
|
exp := -age.Hours() / m.cfg.PenaltyHalfLife.Hours()
|
||||||
|
return math.Pow(2, exp)
|
||||||
|
}
|
||||||
|
|
||||||
// getLastPairResult gets the last recorded result for a node pair.
|
// getLastPairResult gets the last recorded result for a node pair.
|
||||||
func (m *MissionControl) getLastPairResult(fromNode,
|
func (m *MissionControl) getLastPairResult(fromNode,
|
||||||
toNode route.Vertex) *timedPairResult {
|
toNode route.Vertex) *timedPairResult {
|
||||||
|
Loading…
Reference in New Issue
Block a user