-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulate.go
113 lines (85 loc) · 1.96 KB
/
simulate.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package main
import (
"encoding/json"
"log"
"os"
"flag"
"fmt"
//tf "github.com/spencer-p/traffic"
)
/*
=========================
SIMULATION SECTION
=========================
*/
type Simulation struct {
AgentArray []Agent
EdgeArray []Edge
}
func NewSimulation() Simulation {
return Simulation{make([]Agent, 0), make([]Edge, 0)}
}
func (s *Simulation) AddAgent(a Agent) {
s.AgentArray = append(s.AgentArray, a)
}
func (s *Simulation) AddEdge(e Edge) {
s.EdgeArray = append(s.EdgeArray, e)
}
func (s *Simulation) Simulate() {
fmt.Println("Simulation in progress")
//Insert simulation code here.
}
/*
=========================
MAIN FUNCTION
=========================
*/
func main() {
//Receives "input" and "num" command-line arguments
inputFileName := flag.String("input", "", "GeoData to parse")
flag.Parse()
//Quits if inputFileName is empty
if *inputFileName == "" {
flag.Usage()
os.Exit(1)
}
//Opens data file
inputFile, err := os.Open(*inputFileName)
if err != nil {
log.Fatal(err)
}
//Returns decoder to parse GeoJSON file
data_dec := json.NewDecoder(inputFile)
var places FeatureCollection
err = data_dec.Decode(&places)
if err != nil {
log.Fatal(err)
}
log.Println("Parsed", len(places.Features), "streets")
//Opens "agents.json" file
input, err:= os.Open("agents.json")
if err != nil {
log.Fatal(err)
}
//Returns a decoder to prase file of agents
agent_dec := json.NewDecoder(input)
var people struct{ Agents []agent }
err = agent_dec.Decode(&people)
if err != nil {
log.Fatal(err)
}
log.Println("Parsed", len(people.Agents), "agents")
//Makes a new simulation
newSimulation := NewSimulation()
/* for i, _ := range places.Features {
newSimulation.AddEdge(places.Features[i])
}
*/
//Adds agents to simulation
for i, _ := range people.Agents {
newSimulation.AddAgent(people.Agents[i])
}
log.Println("Added", len(people.Agents), "agents to the simulation")
//Runs simulation
newSimulation.Simulate()
}