-
Notifications
You must be signed in to change notification settings - Fork 0
/
heuristic-utils.go
53 lines (48 loc) · 1.75 KB
/
heuristic-utils.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
package limited_rationality
import (
"github.com/Azbesciak/RealDecisionMaker/lib/model"
"github.com/Azbesciak/RealDecisionMaker/lib/utils"
)
type HeuristicParams interface {
GetCurrentChoice() string
GetRandomSeed() int64
IsRandomAlternativesOrdering() bool
}
func GetAlternativesSearchOrder(
dm *model.DecisionMakingParams,
params HeuristicParams,
generator utils.ValueGenerator,
) (model.AlternativeWithCriteria, []model.AlternativeWithCriteria) {
if len(params.GetCurrentChoice()) > 0 {
allAlternatives := dm.AllAlternatives()
choice := model.FetchAlternative(&allAlternatives, params.GetCurrentChoice())
leftAlternatives := model.RemoveAlternative(dm.ConsideredAlternatives, choice)
otherAlternatives := OrderAlternatives(params.IsRandomAlternativesOrdering(), &leftAlternatives, generator)
return choice, *otherAlternatives
} else {
alternatives := *OrderAlternatives(params.IsRandomAlternativesOrdering(), &dm.ConsideredAlternatives, generator)
return alternatives[0], alternatives[1:]
}
}
func OrderAlternatives(isRandomOrder bool, alternatives *[]model.AlternativeWithCriteria, generator utils.ValueGenerator) *[]model.AlternativeWithCriteria {
if isRandomOrder {
return model.ShuffleAlternatives(alternatives, generator)
} else {
return model.CopyAlternatives(alternatives)
}
}
func PrepareSequentialRanking(result model.AlternativeResults, resultIds []model.Alternative) model.AlternativesRanking {
resultsCount := len(result)
ranking := make(model.AlternativesRanking, resultsCount)
for i, r := range result {
lastIndex := i + 2
if lastIndex > resultsCount {
lastIndex = resultsCount
}
ranking[i] = model.AlternativesRankEntry{
AlternativeResult: r,
BetterThanOrSameAs: resultIds[i+1 : lastIndex],
}
}
return ranking
}