/
decreasing-coefficient.go
56 lines (46 loc) · 1.81 KB
/
decreasing-coefficient.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package satisfaction_levels
import (
"fmt"
"math"
)
type DecreasingCoefficientManager struct {
updateCoefficient func(current, coefficient float64) float64
}
func (d *DecreasingCoefficientManager) Validate(params *IdealCoefficientSatisfactionLevels) {
if params.Coefficient <= 0 || params.Coefficient >= 1 {
panic(fmt.Errorf("satisfaction coefficient degradation level must be in range (0, 1), got %f", params.Coefficient))
}
if params.MinValue <= 0 || params.MinValue > 1 {
panic(fmt.Errorf("min satisfaction coefficient level must be in range (0, 1], got %f", params.MinValue))
}
if params.MaxValue > 1 || params.MaxValue <= 0 {
panic(fmt.Errorf("max satisfaction coefficient level must be in range (0, 1], got %f", params.MaxValue))
}
}
func (d *DecreasingCoefficientManager) UpdateValue(current, coefficient float64) float64 {
return d.updateCoefficient(current, coefficient)
}
func (d *DecreasingCoefficientManager) InitialValue(params *IdealCoefficientSatisfactionLevels) float64 {
return params.MaxValue
}
func (d *DecreasingCoefficientManager) HasNext(params *IdealCoefficientSatisfactionLevels) bool {
return params.currentValue > params.MinValue
}
const IdealDecreasingMul = "idealMultipliedCoefficient"
var IdealDecreasingMulCoefficientSatisfaction = IdealCoefficientSatisfactionLevelsSource{
id: IdealDecreasingMul,
coefficientManager: &DecreasingCoefficientManager{
updateCoefficient: func(current, coefficient float64) float64 {
return current * coefficient
},
},
}
const IdealSubtractive = "idealSubtractiveCoefficient"
var IdealSubtrCoefficientSatisfaction = IdealCoefficientSatisfactionLevelsSource{
id: IdealSubtractive,
coefficientManager: &DecreasingCoefficientManager{
updateCoefficient: func(current, coefficient float64) float64 {
return math.Max(current-coefficient, 0)
},
},
}