-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseries_test.go
More file actions
80 lines (68 loc) · 1.92 KB
/
Copy pathseries_test.go
File metadata and controls
80 lines (68 loc) · 1.92 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cgc_optimize
import (
"math"
"math/rand"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
)
func NewTestSeries(n int) Series {
cl1 := NewTestCluster()
clx := make([]Sequencer, n)
for i := 0; i < n; i++ {
clx[i] = cl1
}
return NewSeries(clx...)
}
func TestSeriesCostCoefficients(t *testing.T) {
pid1, _ := uuid.NewUUID()
pid2, _ := uuid.NewUUID()
inf := math.Inf(1)
a1 := NewBasicUnit(pid1, 1, 2, 3, 4, inf, inf, inf, inf)
a2 := NewBasicUnit(pid2, 5, 6, 7, 8, inf, inf, inf, inf)
g := NewGroup(a1, a2)
cl := NewCluster(g)
s := NewSeries(cl, cl)
cc := s.CostCoefficients()
assert.Equal(t, []float64{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8}, cc)
}
func TestSeriesConstraints1(t *testing.T) {
s := NewTestSeries(24)
c := make([]float64, s.ColumnSize()+2)
for i := 1; i < s.ColumnSize()-1; i++ {
c[i] = rand.Float64()
}
err := s.NewConstraint(c)
assert.Nil(t, err)
sc := s.Constraints()
assert.Equal(t, c, sc[0])
}
func TestSeriesBounds(t *testing.T) {
s := NewTestSeries(2)
b := s.Bounds()
inf := math.Inf(1)
expBnds := make([][2]float64, s.ColumnSize())
for i := 0; i < s.ColumnSize(); i++ {
expBnds[i] = [2]float64{0, inf}
}
assert.Equal(t, expBnds, b)
}
func TestSeriesBatteryEnergyConstraint(t *testing.T) {
pid1, _ := uuid.NewUUID()
pid2, _ := uuid.NewUUID()
inf := math.Inf(1)
a1 := NewBasicUnit(pid1, 1, 2, 3, 4, inf, inf, inf, inf)
a2 := NewBasicUnit(pid2, 5, 6, 7, 8, inf, inf, inf, inf)
g := NewGroup(a1, a2)
cl := NewCluster(g)
s := NewSeries(cl, cl, cl)
bec := BatteryEnergyConstraint(&s, pid1, 1)
for _, c := range bec {
//fmt.Println(bec)
err := s.NewConstraint(c)
assert.Nil(t, err)
}
sec := s.Constraints()
assert.Equal(t, []float64{0, -1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, sec[0])
assert.Equal(t, []float64{0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0}, sec[1])
}