-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutator.go
122 lines (112 loc) · 1.93 KB
/
mutator.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
120
121
122
// Copyright 2013 The Seriation Authors. All rights reserved. See the LICENSE file.
package ser
import (
"math/rand"
)
func proposePerm1(p IntVector) {
rows := p.Len()
a := rand.Intn(rows)
b := rand.Intn(rows)
for b == a {
b = rand.Intn(rows)
}
c := rand.Intn(rows)
for c == a || c == b {
c = rand.Intn(rows)
}
x := rand.Float64()
switch {
case x < 0.5:
// swap
p.Swap(a, b)
default:
// invert
p.InvertFromTo(a, b)
}
}
func proposePerm2(p IntVector) {
rows := p.Len()
c := rand.Intn(rows)
b := rand.Intn(c)
a := rand.Intn(b)
x := rand.Float64()
switch {
case x < 0.091:
// swap
p.Swap(a, b)
case x < 0.182:
// invert
p.InvertFromTo(a, b)
case x < 0.273:
p.InvertTo(a)
case x < 0.364:
p.InsideOut(a)
case x < 0.455:
p.InsertAt(a, b)
case x < 0.546:
p.InvertHeadAndTail(a, b)
case x < 0.637:
p.Displace(a, b, c)
case x < 0.728:
p.DisplaceInv(a, b, c)
case x < 0.818:
p.Scramble3(a)
case x < 0.908:
p.Scramble4(a)
default:
p.TwoPointSwapInv(a, b)
}
}
func proposePerm(p IntVector) {
var a, b, c, d int
rows := p.Len()
n := 13
x := rand.Intn(n)
switch {
case x < 5:
a = rand.Intn(rows)
case x < 10:
b = rand.Intn(rows-1) + 1 // avoid zero
a = rand.Intn(b)
case x < 13:
c = rand.Intn(rows-2) + 2
b = rand.Intn(c-1) + 1
a = rand.Intn(b)
default:
d = rand.Intn(rows-3) + 3
c = rand.Intn(d-2) + 2
b = rand.Intn(c-1) + 1
a = rand.Intn(b)
}
switch {
case x == 0:
p.InvertFrom(a)
case x == 1:
p.InvertTo(a)
case x == 2:
p.InsideOut(a)
case x == 3:
p.Scramble3(a)
case x == 4:
p.Scramble4(a)
case x == 5:
p.Swap(a, b)
case x == 6:
p.InvertFromTo(a, b)
case x == 7:
p.InsertAt(a, b)
case x == 8:
p.InvertHeadAndTail(a, b)
case x == 9:
p.TwoPointSwapInv(a, b)
case x == 10:
p.Displace(a, b, c)
case x == 11:
p.DisplaceInv(a, b, c)
case x == 12:
p.ThreePointExch(a, b, c)
case x == 13:
p.FourPointExch(a, b, c, d)
default:
}
}