-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_model_test.go
70 lines (58 loc) · 1.18 KB
/
example_model_test.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
// © 2019-present nextmv.io inc
package mip_test
import (
"fmt"
mip "github.com/nextmv-io/go-mip"
)
func ExampleModel_empty() {
model := mip.NewModel()
fmt.Println(len(model.Constraints()))
fmt.Println(len(model.Vars()))
fmt.Println(len(model.Objective().Terms()))
fmt.Println(model.Objective().IsMaximize())
fmt.Println(model)
// Output:
// 0
// 0
// 0
// false
// minimize
}
func ExampleModel_queries() {
model := mip.NewModel()
model.NewBool()
model.NewFloat(1.0, 2.0)
model.NewBool()
model.NewConstraint(mip.Equal, 0.0)
fmt.Println(len(model.Vars()))
fmt.Println(len(model.Constraints()))
fmt.Println(model)
// Output:
// 3
// 1
// minimize
// 0: = 0
// 0: B0 [0, 1]
// 1: F1 [1, 2]
// 2: B2 [0, 1]
}
func ExampleModel_copy() {
model := mip.NewModel()
model.Objective().SetMaximize()
model.NewBool()
model.NewFloat(1.0, 2.0)
model.NewBool()
model.NewConstraint(mip.Equal, 0.0)
copyModel := model.Copy()
fmt.Println(len(copyModel.Vars()))
fmt.Println(len(copyModel.Constraints()))
fmt.Println(copyModel)
// Output:
// 3
// 1
// maximize
// 0: = 0
// 0: B0 [0, 1]
// 1: F1 [1, 2]
// 2: B2 [0, 1]
}