Compare commits
3 Commits
v0.0.4-dev
...
v0.0.8-dev
Author | SHA1 | Date | |
---|---|---|---|
c0e37c3183 | |||
3db36407ea | |||
685bdef816 |
54
config.yaml
54
config.yaml
@ -1,24 +1,30 @@
|
|||||||
- step: 10
|
last_step: 100
|
||||||
amount: 100
|
init_amount: 10
|
||||||
neighbours: 1
|
steps:
|
||||||
- step: 100
|
- step: 10
|
||||||
amount: 100
|
amount: 1
|
||||||
neighbours: 50
|
neighbours: 1
|
||||||
- step: 200
|
- step: 20
|
||||||
amount: 500
|
amount: 100
|
||||||
neighbours: 20
|
neighbours: 1
|
||||||
- step: 400
|
- step: 30
|
||||||
amount: 10
|
amount: 1
|
||||||
neighbours: 5
|
neighbours: 1
|
||||||
- step: 500
|
- step: 40
|
||||||
amount: 1
|
amount: 10
|
||||||
neighbours: 1
|
neighbours: 2
|
||||||
- step: 600
|
- step: 50
|
||||||
amount: 500
|
Amount: 2
|
||||||
neighbours: 50
|
neighbours: 1
|
||||||
- step: 1500
|
- step: 60
|
||||||
amount: 10
|
amount: 2
|
||||||
neighbours: 1
|
neighbours: 1
|
||||||
- step: 2000
|
- step: 70
|
||||||
amount: 1
|
amount: 3
|
||||||
neighbours: 1
|
neighbours: 2
|
||||||
|
- step: 80
|
||||||
|
amount: 3
|
||||||
|
neighbours: 1
|
||||||
|
- step: 3000
|
||||||
|
amount: 3
|
||||||
|
neighbours: 1
|
||||||
|
48
main.go
48
main.go
@ -22,12 +22,17 @@ import (
|
|||||||
var windowWidth, windowHeight = 1000, 700
|
var windowWidth, windowHeight = 1000, 700
|
||||||
var goidSize = 3
|
var goidSize = 3
|
||||||
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
|
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
|
||||||
var populationSize = 10
|
var populationSize = 0
|
||||||
var loops = 3000
|
var loops = 3000
|
||||||
var numNeighbours = 5
|
var numNeighbours = 5
|
||||||
var separationFactor = float64(goidSize * 5)
|
var separationFactor = float64(goidSize * 5)
|
||||||
var coherenceFactor = 8
|
var coherenceFactor = 8
|
||||||
|
|
||||||
|
type configuration struct {
|
||||||
|
Steps []steps `yaml:"steps"`
|
||||||
|
LastStep int `yaml:"last_step"`
|
||||||
|
InitAmount int `yaml:"init_amount"`
|
||||||
|
}
|
||||||
type steps struct {
|
type steps struct {
|
||||||
Step int `yaml:"step"`
|
Step int `yaml:"step"`
|
||||||
Amount int `yaml:"amount"`
|
Amount int `yaml:"amount"`
|
||||||
@ -65,8 +70,11 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
td := []steps{}
|
config := configuration{}
|
||||||
err = yaml.Unmarshal(conf, &td)
|
err = yaml.Unmarshal(conf, &config)
|
||||||
|
steps := config.Steps
|
||||||
|
loops = config.LastStep
|
||||||
|
populationSize = config.InitAmount
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := fo.Close(); err != nil {
|
if err := fo.Close(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -75,21 +83,19 @@ func main() {
|
|||||||
clearScreen()
|
clearScreen()
|
||||||
hideCursor()
|
hideCursor()
|
||||||
var goids []*Goid
|
var goids []*Goid
|
||||||
|
for i := 0; i < populationSize; i++ {
|
||||||
// for i := 0; i < populationSize; i++ {
|
g := createRandomGoid()
|
||||||
// g := createRandomGoid()
|
goids = append(goids, &g)
|
||||||
// goids = append(goids, &g)
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
current_stage := 0
|
current_stage := 0
|
||||||
for i := 0; i < loops; i++ {
|
for i := 0; i < loops; i++ {
|
||||||
goids, populationSize = fixGoids(goids, populationSize, td[current_stage].Amount)
|
goids, populationSize = fixGoids(goids, populationSize, steps[current_stage].Amount)
|
||||||
if td[current_stage].NumNeighbours >= populationSize {
|
if steps[current_stage].NumNeighbours >= populationSize {
|
||||||
numNeighbours = populationSize - 1
|
numNeighbours = populationSize
|
||||||
} else {
|
} else {
|
||||||
numNeighbours = td[current_stage].NumNeighbours
|
numNeighbours = steps[current_stage].NumNeighbours
|
||||||
}
|
}
|
||||||
if i == td[current_stage+1].Step {
|
if i == steps[current_stage+1].Step {
|
||||||
current_stage += 1
|
current_stage += 1
|
||||||
}
|
}
|
||||||
move(goids, fo, i)
|
move(goids, fo, i)
|
||||||
@ -97,7 +103,7 @@ func main() {
|
|||||||
printImage(frame.SubImage(frame.Rect))
|
printImage(frame.SubImage(frame.Rect))
|
||||||
}
|
}
|
||||||
showCursor()
|
showCursor()
|
||||||
|
|
||||||
out, err := ioutil.ReadFile("/tmp/goids.yaml")
|
out, err := ioutil.ReadFile("/tmp/goids.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
@ -115,23 +121,23 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
for i := 0; i <= total; i++{
|
for i := 0; i <= total; i++ {
|
||||||
var x []string
|
var x []string
|
||||||
var y []string
|
var y []string
|
||||||
outfile.Write([]byte(fmt.Sprintf("GOID: %d\n", i)))
|
outfile.Write([]byte(fmt.Sprintf("GOID: %d\n", i)))
|
||||||
for z := 0; z <= loops; z++ {
|
for z := 0; z <= loops; z++ {
|
||||||
check := false
|
check := false
|
||||||
for _, g := range output {
|
for _, g := range output {
|
||||||
if g.Goid == i && g.Loop == z{
|
if g.Goid == i && g.Loop == z {
|
||||||
check = true
|
check = true
|
||||||
x = append(x, strconv.Itoa(g.Data.X))
|
x = append(x, strconv.Itoa(g.Data.X))
|
||||||
y = append(y, strconv.Itoa(g.Data.Y))
|
y = append(y, strconv.Itoa(g.Data.Y))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !check {
|
if !check {
|
||||||
x = append(x, "-")
|
x = append(x, "-")
|
||||||
y = append(y, "-")
|
y = append(y, "-")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user