-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (67 loc) · 1.36 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
)
func subMain() {
var bnp BankNoteProblem
input, err := os.Open("./data/bnp1.txt")
if err != nil {
fmt.Print(err)
os.Exit(-1)
}
readRobberShare(input, &bnp)
readBankNoteDecks(input, &bnp)
_ = bnp.validate()
config := GeneticAlgorithmConfig{
maxGenerationCount: 20,
maxCandidateCount: 100,
noOfMutantForEachCandidate: 100,
maxMutateCount: 10,
maxAttemptCount: 100,
intensityFunc: func(generationCount, maxGenerationCount int) float64 {
return 1.0
/*
intensity := 1.0 - float64(generationCount) / float64(maxGenerationCount)
if intensity < 0.1 {
intensity = 0.1
}
return intensity
*/
}}
bns, err := bnp.getGeneticAlgorithmSolution(config)
if err != nil {
fmt.Print(err)
os.Exit(-1)
}
if err = bns.validate(&bnp); err != nil {
fmt.Print(err)
os.Exit(-1)
}
fmt.Println(bns)
if bns.String() != testsbns[2].String() {
fmt.Print(err)
os.Exit(-1)
}
}
func profileWrapper(func1 func()) {
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
func1()
defer pprof.StopCPUProfile()
} else {
func1()
}
}
func main() {
profileWrapper(subMain)
}