-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulation.go
More file actions
58 lines (44 loc) · 1.27 KB
/
Copy pathSimulation.go
File metadata and controls
58 lines (44 loc) · 1.27 KB
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
package polias
import (
"fmt"
"io"
"github.com/spf13/viper"
)
//Simulation contains all agents, all relationships, and all settings of polias model
type Simulation struct {
Name string
SocialGroups []SocialGroup
// aTable|SG|,|SG| with values in [−1,1]
SocialGroupAttitudes [][]float64
Individuals []Individual
}
type socialGroupConfig struct {
Name string
Attitudes []float64
}
type simulationConfig struct {
SG []socialGroupConfig
Alpha float64
Epsilon float64
}
//MakeIndividual is a function that is temporary and stupid
func MakeIndividual() Individual {
return Individual{SocialGroup: SocialGroup{Name: 2}, Beliefs: []Belief{}, Contacts: []Individual{}, Broadcast: make(chan Message)}
}
//LoadModel loads a Model
func LoadModel(config io.Reader) Simulation {
viper.SetConfigType("yaml")
var cfg simulationConfig
if err := viper.ReadConfig(config); err != nil { // Handle errors reading the config file
panic(fmt.Errorf("fatal error config file %s ", err))
}
if err := viper.Unmarshal(&cfg); err != nil {
panic(fmt.Errorf("fatal error marshaling %s ", err))
}
aTable := make([][]float64, len(cfg.SG))
for i, socialGroup := range cfg.SG {
aTable[i] = socialGroup.Attitudes
}
fmt.Println(aTable)
return Simulation{}
}