-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
44 lines (37 loc) · 994 Bytes
/
utils.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
package highs
type PackedMatrix struct {
arStart []int
arIndex []int
arValue []float64
}
// packRows returns the rows in a flat packed form use in the HiGHS c interface
func packMatrix(matrix [][]float64) PackedMatrix {
arStart := []int{}
arIndex := []int{}
arValue := []float64{}
idx := 0
for _, cols := range matrix {
arStart = append(arStart, idx)
for i, v := range cols {
if v != 0 {
arIndex = append(arIndex, i)
arValue = append(arValue, v)
}
}
idx = len(arIndex)
}
return PackedMatrix{arStart, arIndex, arValue}
}
// separateBounds splits a bounded rows [lb, row..., ub] into its components lb, rows, ub
func separateBounds(bound_rows [][]float64) ([][]float64, []float64, []float64) {
col_size := len(bound_rows[0])
rows := [][]float64{}
lbs := []float64{}
ubs := []float64{}
for _, row := range bound_rows {
rows = append(rows, row[1:col_size-1])
lbs = append(lbs, row[0])
ubs = append(ubs, row[col_size-1])
}
return rows, lbs, ubs
}