math.go 515 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
package strategy

import (
	"math"
	"math/rand"
)

type strategyFunc func(*ledger) bool

func standardStrategy(l *ledger) bool {
	return rand.Float64() <= probabilitySend(l.Accounting.Value())
}

func yesManStrategy(l *ledger) bool {
	return true
}

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)
}