-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_engine_test.go
119 lines (110 loc) · 2.42 KB
/
meta_engine_test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package fsp
/*
import "testing"
func TestWeight100(t *testing.T) {
t.Log(initWeight(10, 0.8))
}
func check(e, f *Flight, t *testing.T) {
if !equal(*e, *f) {
t.Error(e, "!=", f)
}
}
func checkF32(e, f float32, t *testing.T) {
if e != f {
t.Error(e, "!=", f)
}
}
func TestOrderNoH(t *testing.T) {
flights := []*Flight{
{0, 1, 1, 1, 0},
{0, 2, 1, 3, 0},
{0, 3, 1, 5, 0},
}
ordered := order(flights, nil, 0.4)
check(ordered[0], flights[0], t)
check(ordered[1], flights[1], t)
check(ordered[2], flights[2], t)
}
func TestNormalize(t *testing.T) {
a := make([]float32, 3)
a[0], a[1], a[2] = 5, 1, 10
normalize(a)
checkF32(a[0], 0.5, t)
checkF32(a[1], 0.1, t)
checkF32(a[2], 1, t)
}
func TestOrderHeurIgnore(t *testing.T) {
flights := []*Flight{
{0, 1, 1, 1, 0},
{0, 2, 1, 10, 0},
{0, 3, 1, 100, 0},
}
h := func(fts []*Flight) []float32 {
x := make([]float32, 0, len(fts))
for _, f := range fts {
x = append(x, float32(100-f.Cost))
}
return x
}
ordered := order(flights, h, 0)
check(ordered[0], flights[0], t)
check(ordered[1], flights[1], t)
check(ordered[2], flights[2], t)
}
func TestOrderHeurReverse(t *testing.T) {
flights := []*Flight{
{0, 1, 1, 1, 0},
{0, 2, 1, 10, 0},
{0, 3, 1, 100, 0},
}
h := func(fts []*Flight) []float32 {
x := make([]float32, 0, len(fts))
for _, f := range fts {
x = append(x, float32(101-f.Cost))
}
return x
}
ordered := order(flights, h, 1)
check(ordered[0], flights[2], t)
check(ordered[1], flights[1], t)
check(ordered[2], flights[0], t)
}
func TestOrderHeurRevWeaker(t *testing.T) {
flights := []*Flight{
{0, 1, 1, 1, 0},
{0, 2, 1, 10, 0},
{0, 3, 1, 100, 0},
}
h := func(fts []*Flight) []float32 {
x := make([]float32, 0, len(fts))
for _, f := range fts {
x = append(x, float32(101-f.Cost))
}
return x
}
//f 0.01, 0.1, 1
//h 1, 0.91, 0.01
//s 0.406, 0.424, 0.604
ordered := order(flights, h, 0.4)
check(ordered[0], flights[0], t)
check(ordered[1], flights[1], t)
check(ordered[2], flights[2], t)
}
func TestOrderHeurRevStronger(t *testing.T) {
flights := []*Flight{
{0, 1, 1, 1, 0},
{0, 2, 1, 10, 0},
{0, 3, 1, 100, 0},
}
h := func(fts []*Flight) []float32 {
x := make([]float32, 0, len(fts))
for _, f := range fts {
x = append(x, float32(101-f.Cost))
}
return x
}
ordered := order(flights, h, 0.6)
check(ordered[0], flights[2], t)
check(ordered[1], flights[1], t)
check(ordered[2], flights[0], t)
}*/