7 Commits

Author SHA1 Message Date
c0e37c3183 add init_amount to config 2022-12-01 22:12:05 +01:00
3db36407ea add last_step to config file 2022-11-26 16:01:37 +01:00
685bdef816 fix panic in the runtime 2022-11-19 20:10:59 +01:00
eb57a18a02 set initial params in hardcode 2022-11-16 18:57:18 +01:00
206796cf0f fix logic 2022-11-16 18:02:35 +01:00
d1bb82d2a1 write to file 2022-11-16 17:09:16 +01:00
659b913130 write to file 2022-11-15 09:05:27 +01:00
2 changed files with 68 additions and 41 deletions

View File

@ -1,16 +1,30 @@
- step: 10 last_step: 100
amount: 100 init_amount: 10
neighbours: 1 steps:
- step: 100 - step: 10
amount: 100
neighbours: 50
- step: 200
amount: 500
neighbours: 20
- step: 400
amount: 10
neighbours: 5
- step: 500
amount: 1 amount: 1
neighbours: 1 neighbours: 1
- step: 20
amount: 100
neighbours: 1
- step: 30
amount: 1
neighbours: 1
- step: 40
amount: 10
neighbours: 2
- step: 50
Amount: 2
neighbours: 1
- step: 60
amount: 2
neighbours: 1
- step: 70
amount: 3
neighbours: 2
- step: 80
amount: 3
neighbours: 1
- step: 3000
amount: 3
neighbours: 1

45
main.go
View File

@ -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 = 20 var populationSize = 0
var loops = 500 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,18 +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)
numNeighbours = td[current_stage].NumNeighbours if steps[current_stage].NumNeighbours >= populationSize {
if i > td[current_stage].Step { numNeighbours = populationSize
} else {
numNeighbours = steps[current_stage].NumNeighbours
}
if i == steps[current_stage+1].Step {
current_stage += 1 current_stage += 1
} }
move(goids, fo, i) move(goids, fo, i)
@ -107,16 +116,19 @@ func main() {
total = goid.Goid total = goid.Goid
} }
} }
fmt.Println(total)
for i := 0; i <= total; i++{ outfile, err := os.Create("./goids.txt")
if err != nil {
panic(err)
}
for i := 0; i <= total; i++ {
var x []string var x []string
var y []string var y []string
fmt.Println("GOID: ", 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))
@ -128,8 +140,9 @@ func main() {
y = append(y, "-") y = append(y, "-")
} }
} }
fmt.Printf("%v\n", x)
fmt.Printf("%v\n", y) outfile.Write([]byte(fmt.Sprintf("%v\n", x)))
outfile.Write([]byte(fmt.Sprintf("%v\n", y)))
} }
} }