Commit e658ade6 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

sigmoid strat placeholder

parent 668a90f6
package bitswap
import (
"math"
)
func probabilitySend(ratio float64) float64 {
x := 1 + math.Exp(6-3*ratio)
y := 1 / x
return 1 - y
}
type debtRatio struct {
BytesSent uint64
BytesRecv uint64
}
func (dr *debtRatio) Value() float64 {
return float64(dr.BytesSent) / float64(dr.BytesRecv+1)
}
package bitswap
import (
"testing"
)
func TestProbabilitySendDecreasesAsRatioIncreases(t *testing.T) {
grateful := debtRatio{BytesSent: 0, BytesRecv: 10000}
pWhenGrateful := probabilitySend(grateful.Value())
abused := debtRatio{BytesSent: 10000, BytesRecv: 0}
pWhenAbused := probabilitySend(abused.Value())
if pWhenGrateful < pWhenAbused {
t.Fail()
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment