-
Notifications
You must be signed in to change notification settings - Fork 0
/
playoutActor.go
53 lines (47 loc) · 881 Bytes
/
playoutActor.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
package nrpa
import (
"alda/entities"
"context"
"sync"
)
type action func()
type playoutActor struct {
t *entities.TSPTW
data *PlayoutData
chIn chan action
}
type Message struct {
Rollout *Rollout
LegalMovesPerStep [][]int
}
func StartPlayoutActor(ctx context.Context, t *entities.TSPTW) *playoutActor {
a := &playoutActor{
t: t,
chIn: make(chan action),
data: NewPlayoutData(t),
}
go a.Loop(ctx)
return a
}
func (a *playoutActor) Playout(policy [][]float64, chOut chan *Message, wg *sync.WaitGroup) {
a.chIn <- func() {
defer wg.Done()
a.data.Reset()
r := NewRollout(a.data)
r.Do(policy)
chOut <- &Message{
Rollout: r,
LegalMovesPerStep: a.data.legalMovesPerStep,
}
}
}
func (a *playoutActor) Loop(ctx context.Context) {
for {
select {
case do := <-a.chIn:
do()
case <-ctx.Done():
return
}
}
}