-
Notifications
You must be signed in to change notification settings - Fork 0
/
rounds.go
87 lines (68 loc) · 1.96 KB
/
rounds.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
package bifrost
type Rounds struct {
Rounds []map[uint64]StopArrival
MarkedStops map[uint64]bool
MarkedStopsForTransfer map[uint64]bool
EarliestArrivals map[uint64]uint64
Queue map[uint32]uint32
}
func (b *Bifrost) NewRounds() *Rounds {
rounds := make([]map[uint64]StopArrival, (b.TransferLimit+1)*2+2)
for i := range rounds {
rounds[i] = make(map[uint64]StopArrival)
}
return &Rounds{
Rounds: rounds,
MarkedStops: make(map[uint64]bool),
MarkedStopsForTransfer: make(map[uint64]bool),
EarliestArrivals: make(map[uint64]uint64),
Queue: make(map[uint32]uint32, 10000),
}
}
type StopArrival struct {
Arrival uint64 // arrival time in unix ms
Trip uint32 // trip id, special TripId are defined (for example TripIdWalk)
EnterKey uint64 // stop sequence key in route for trips, vertex key for transfers
Departure uint64 // departure day for trips, departure time in unix ms for transfers
TransferTime uint32 // time in ms to walk or cycle to this stop from the previous stop
Vehicles uint8 // bitmask of vehicles available at this stop
}
func (r *Rounds) NewSession() {
r.ResetRounds()
for i := range r.MarkedStops {
//r.MarkedStops[i] = false
delete(r.MarkedStops, i)
}
for i := range r.MarkedStopsForTransfer {
//r.MarkedStopsForTransfer[i] = false
delete(r.MarkedStopsForTransfer, i)
}
for i := range r.EarliestArrivals {
//r.EarliestArrivals[i] = ArrivalTimeNotReached
delete(r.EarliestArrivals, i)
}
for k := range r.Queue {
delete(r.Queue, k)
}
}
func (r *Rounds) ResetRounds() {
done := make(chan bool)
maxThreads := 12
free := make(chan bool, maxThreads)
for i := 0; i < maxThreads; i++ {
free <- true
}
for i := range r.Rounds {
go func(i int) {
<-free
for k := range r.Rounds[i] {
delete(r.Rounds[i], k)
}
done <- true
free <- true
}(i)
}
for i := 0; i < len(r.Rounds); i++ {
<-done
}
}