/
config.go
82 lines (70 loc) · 1.93 KB
/
config.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
package main
import (
"flag"
"fmt"
cfg "github.com/jinzhu/configor"
)
var appConfig = struct {
// path to the reference image
RefImage string
Population struct {
// number of individuals in the population
NumIndividuals int `required:"true"`
// number of candidates preserved through elitism
EliteCount int `required:"true"`
}
Image struct {
// MinPolys is the minimum number of polygon in an image
MinPolys int `required:"true"`
// MaxPolys is the minimum number of polygon in an image
MaxPolys int `required:"true"`
}
Polygon struct {
// MinPoints is the minimum number of points in a polygon
MinPoints int `required:"true"`
// MaxPoints is the maximum number of points in a polygon
MaxPoints int `required:"true"`
}
Mutation struct {
// image level mutations
Image struct {
// Rate [0, 1] of add polygon mutation
AddPoly float64 `required:"true"`
// Rate [0, 1] of remove polygon mutation
RemovePoly float64 `required:"true"`
// Rate [0, 1] of swap polygon mutation
SwapPolys float64 `required:"true"`
}
// polygon level mutations
Polygon struct {
// Rate [0, 1] of add point mutation
AddPoint float64 `required:"true"`
// Rate [0, 1] of remove point mutation
RemovePoint float64 `required:"true"`
// Rate [0, 1] of change polygon color mutation
ChangeColor float64 `required:"true"`
}
// point level mutations
Point struct {
// Rate [0, 1] of move point mutation
Move float64 `required:"true"`
}
}
}{}
var (
configFile = flag.String("cfg", "config.yml", "configuration file")
refImage = flag.String("img", "", "reference image (PNG)")
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
)
func readConfig() error {
flag.Parse()
err := cfg.Load(&appConfig, *configFile)
if err != nil {
return fmt.Errorf("read config error: %v", err)
}
fmt.Println(appConfig)
if len(*refImage) > 0 {
appConfig.RefImage = *refImage
}
return nil
}