-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.go
More file actions
48 lines (40 loc) · 1.32 KB
/
Copy pathstatistics.go
File metadata and controls
48 lines (40 loc) · 1.32 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
package alns
import (
"fmt"
"time"
)
type Statistics struct {
IterationCount uint // the number of iterations
TotalRuntime time.Duration // the total runtime
Objectives []ObjectiveRecord // previous objective values, tracking progress
DestroyOperatorCounts []OperatorCounts // the destroy operator counts
RepairOperatorCounts []OperatorCounts // the repair operator counts
}
func newStatistics(numDestroy, numRepair int) Statistics {
return Statistics{
Objectives: make([]ObjectiveRecord, 0, 128),
DestroyOperatorCounts: make([]OperatorCounts, numDestroy),
RepairOperatorCounts: make([]OperatorCounts, numRepair),
}
}
func (s *Statistics) collectObjective(elapsedTime time.Duration, objective float64) {
s.Objectives = append(s.Objectives, ObjectiveRecord{ElapsedTime: elapsedTime, Objective: objective})
}
func (s *Statistics) collectOperators(dIdx, rIdx int, outcome Outcome) {
s.DestroyOperatorCounts[dIdx][outcome]++
s.RepairOperatorCounts[rIdx][outcome]++
}
type ObjectiveRecord struct {
ElapsedTime time.Duration
Objective float64
}
type OperatorCounts [4]uint // see Outcome
func (o OperatorCounts) String() string {
return fmt.Sprintf(
"{%s:%d %s:%d %s:%d %s:%d}",
Best, o[Best],
Better, o[Better],
Accept, o[Accept],
Reject, o[Reject],
)
}