Skip to content

Commit 797a461

Browse files
Merge pull request #92 from nextmv-io/develop
Release v0.20.0
2 parents 56c0c63 + 90baaac commit 797a461

21 files changed

+615
-198
lines changed

.github/workflows/go-build-test.yml

+24-25
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,9 @@ jobs:
1212
- name: set up go
1313
uses: actions/setup-go@v3
1414
with:
15-
go-version: 1.18
15+
go-version: 1.19
1616
id: go
1717

18-
- name: git clone
19-
uses: actions/checkout@v3
20-
21-
- name: clone plugins repository
22-
uses: actions/checkout@v3
23-
with:
24-
repository: nextmv-io/plugins
25-
path: ${{env.RESOURCES}}
26-
ref: develop
27-
ssh-key: ${{ secrets.NEXTMVBOT_SSH_KEY }}
28-
ssh-known-hosts: ssh-keyscan github.com
29-
3018
- name: setup SSH Keys and known_hosts
3119
run: |
3220
mkdir -p ~/.ssh
@@ -37,17 +25,28 @@ jobs:
3725
- name: use ssh instead of https for git
3826
run: git config --global url."[email protected]:".insteadOf "https://github.com/"
3927

40-
# Installs Nextmv CLI dependency regardless of the distribution.
41-
- name: install Nextmv CLI dependency
42-
run: |
43-
NEXTMV_API_KEY=${{ secrets.API_KEY_PROD }} NEXTMV_BASE_URL=https://api.cloud.nextmv.io bash <(curl -s "https://cloud.nextmv.io/install-cli.txt")
44-
mv ~/.nextmv/nextmv /usr/local/bin/nextmv
45-
chmod a+x /usr/local/bin/nextmv
28+
- name: initialize local branch name
29+
run: echo "LOCAL_BRANCH=${{ github.head_ref || github.ref_name }}" >> $GITHUB_ENV
4630

47-
- name: configure Nextmv CLI
48-
run: |
49-
nextmv configure -a ${{ secrets.API_KEY_PROD }}
50-
nextmv activate -t local -r 123
31+
# Gets the token and stores it in a variable.
32+
- name: export local branch
33+
run: echo "BRANCH_CHECK=$(git ls-remote --heads https://github.com/nextmv-io/plugins ${{ env.LOCAL_BRANCH }})" >> $GITHUB_ENV
34+
35+
- name: override with develop if empty
36+
if: "${{ env.BRANCH_CHECK == '' }}"
37+
run: echo "LOCAL_BRANCH=develop" >> $GITHUB_ENV
38+
39+
- name: git clone
40+
uses: actions/checkout@v3
41+
42+
- name: clone plugins repository
43+
uses: actions/checkout@v3
44+
with:
45+
repository: nextmv-io/plugins
46+
path: ${{ env.RESOURCES }}
47+
ref: ${{ env.LOCAL_BRANCH }}
48+
ssh-key: ${{ secrets.NEXTMVBOT_SSH_KEY }}
49+
ssh-known-hosts: ssh-keyscan github.com
5150

5251
- name: export sdk path used in this action
5352
run: echo "SDK_PATH=$(pwd)" >> $GITHUB_ENV
@@ -60,11 +59,11 @@ jobs:
6059
go mod edit -replace=github.com/nextmv-io/sdk=${{env.SDK_PATH}}
6160
6261
# Build the plugins.
63-
REMOVE_TRIMPATH=1 NEXTMV_LIBRARY_PATH=${{ env.NEXTMV_LIBRARY_PATH }} bash scripts/build.sh
62+
REMOVE_TRIMPATH=1 NEXTMV_LIBRARY_PATH=${{ env.NEXTMV_LIBRARY_PATH }} bash scripts/build.sh > /dev/null 2>&1
6463
working-directory: ${{env.RESOURCES}}
6564

6665
- name: go build
6766
run: go build -v ./...
6867

6968
- name: go test
70-
run: NEXTMV_LIBRARY_PATH=${{ env.NEXTMV_LIBRARY_PATH }} NEXTMV_TOKEN=$(nextmv token) go test ./...
69+
run: NEXTMV_LIBRARY_PATH=${{ env.NEXTMV_LIBRARY_PATH }} NEXTMV_TOKEN=${{ secrets.NEXTMV_TOKEN }} go test ./...

.github/workflows/go-lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
- name: set up go
88
uses: actions/setup-go@v3
99
with:
10-
go-version: 1.18
10+
go-version: 1.19
1111
id: go
1212

1313
- name: git clone
@@ -16,4 +16,4 @@ jobs:
1616
- name: golangci-lint
1717
uses: golangci/golangci-lint-action@v3
1818
with:
19-
version: v1.48.0
19+
version: v1.49.0

.golangci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Options for analysis running. Details: https://golangci-lint.run/usage/configuration/#run-configuration
22
run:
33
timeout: 5m
4-
go: "1.18"
4+
go: "1.19"
55

66
# Configures linters. Details: https://golangci-lint.run/usage/linters
77
linters-settings:
@@ -18,13 +18,13 @@ linters-settings:
1818
min-complexity: 10
1919
# Set correct go version.
2020
gofumpt:
21-
lang-version: "1.18"
21+
lang-version: "1.19"
2222
gosimple:
23-
go: "1.18"
23+
go: "1.19"
2424
staticcheck:
25-
go: "1.18"
25+
go: "1.19"
2626
stylecheck:
27-
go: "1.18"
27+
go: "1.19"
2828
# Check case of struct tags
2929
tagliatelle:
3030
case:

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.19.1
1+
v0.20.0

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/nextmv-io/sdk
22

3-
go 1.18
3+
go 1.19

mip/constraint.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,31 @@ const (
3535
//
3636
// 2.5 * x and 3.5 * y are 2 terms in this example
3737
type Constraint interface {
38+
// Name returns assigned name. If no name has been set it will return
39+
// a unique auto-generated name.
40+
Name() string
3841
// NewTerm adds a term to the invoking constraint, invoking this API
3942
// multiple times for the same variable will take the sum of coefficients
4043
// of earlier added terms for that variable
4144
//
42-
// d := mip.NewModel()
45+
// m := mip.NewModel()
4346
//
44-
// x, _ := d.NewContinuousVar(10.0, 100.0)
45-
//
46-
// c, _ := d.NewConstraint(mip.LessThanOrEqual, 123.4)
47+
// x := m.NewFloat(10.0, 100.0)
4748
//
49+
// c := m.NewConstraint(mip.LessThanOrEqual, 123.4)
4850
// c.NewTerm(1.0, x) // results in 1.0 * x <= 123.4 in solver
4951
// c.NewTerm(2.0, x) // results in 3.0 * x <= 123.4 in solver
5052
NewTerm(coefficient float64, variable Var) Term
5153
// RightHandSide returns the right-hand side of the invoking constraint.
5254
RightHandSide() float64
5355
// Sense returns the sense of the invoking constraint.
5456
Sense() Sense
57+
// SetName assigns name to invoking constraint
58+
SetName(name string)
59+
// Term returns a term for variable with the sum of all coefficients of
60+
// defined terms for variable. The second return argument defines how many
61+
// terms have been defined on the objective for variable.
62+
Term(variable Var) (Term, int)
5563
// Terms returns a copy slice of terms of the invoking constraint,
5664
// each variable is reported once. If the same variable has been
5765
// added multiple times the sum of coefficients is reported for that

mip/doc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ A new Model is created:
1111
1212
Var instances are created and added to the model:
1313
14-
x, _ := d.NewContinuousVar(0.0, 100.0)
15-
y, _ := d.NewIntegerVar(0, 100)
14+
x := d.NewFloat(0.0, 100.0)
15+
y := d.NewInt(0, 100)
1616
1717
Constraint instances are created and added to the model:
1818
19-
c1, _ := d.NewConstraint(mip.GreaterThanOrEqual, 1.0)
19+
c1 := d.NewConstraint(mip.GreaterThanOrEqual, 1.0)
2020
c1.NewTerm(-2.0, x)
2121
c1.NewTerm(2.0, y)
2222
23-
c2, _ := d.NewConstraint(mip.LessThanOrEqual, 13.0)
23+
c2 := d.NewConstraint(mip.LessThanOrEqual, 13.0)
2424
c2.NewTerm(-8.0, x)
2525
c2.NewTerm(10.0, y)
2626

mip/example_constraint_test.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func ExampleConstraint_greaterThanEqual() {
1111
model := mip.NewModel()
1212

13-
c, _ := model.NewConstraint(mip.GreaterThanOrEqual, 1.0)
13+
c := model.NewConstraint(mip.GreaterThanOrEqual, 1.0)
1414

1515
fmt.Println(c.Sense())
1616
fmt.Println(c.RightHandSide())
@@ -24,7 +24,7 @@ func ExampleConstraint_greaterThanEqual() {
2424
func ExampleConstraint_equal() {
2525
model := mip.NewModel()
2626

27-
c, _ := model.NewConstraint(mip.Equal, 1.0)
27+
c := model.NewConstraint(mip.Equal, 1.0)
2828

2929
fmt.Println(c.Sense())
3030
fmt.Println(c.RightHandSide())
@@ -38,22 +38,24 @@ func ExampleConstraint_equal() {
3838
func ExampleConstraint_lessThanOrEqual() {
3939
model := mip.NewModel()
4040

41-
c, _ := model.NewConstraint(mip.LessThanOrEqual, 1.0)
42-
41+
c := model.NewConstraint(mip.LessThanOrEqual, 1.0)
42+
c.SetName("constraint")
4343
fmt.Println(c.Sense())
4444
fmt.Println(c.RightHandSide())
4545
fmt.Println(c)
46+
fmt.Println(c.Name())
4647
// Output:
4748
// 0
4849
// 1
4950
// <= 1
51+
// constraint
5052
}
5153

5254
func ExampleConstraint_terms() {
5355
model := mip.NewModel()
5456

55-
v, _ := model.NewBinaryVar()
56-
c, _ := model.NewConstraint(mip.Equal, 1.0)
57+
v := model.NewBool()
58+
c := model.NewConstraint(mip.Equal, 1.0)
5759

5860
t1 := c.NewTerm(1.0, v)
5961
t2 := c.NewTerm(2.0, v)
@@ -64,21 +66,23 @@ func ExampleConstraint_terms() {
6466
fmt.Println(len(c.Terms()))
6567
fmt.Println(c.Terms()[0].Coefficient())
6668
fmt.Println(c)
69+
fmt.Println(c.Term(v))
6770
// Output:
6871
// 0
6972
// 1
7073
// 2
7174
// 1
7275
// 3
7376
// 3 B0 = 1
77+
// 3 B0 2
7478
}
7579

7680
func benchmarkNewConstraintNewTerms(nrTerms int, b *testing.B) {
7781
model := mip.NewModel()
78-
v, _ := model.NewContinuousVar(1.0, 2.0)
82+
v := model.NewFloat(1.0, 2.0)
7983

8084
for i := 0; i < b.N; i++ {
81-
c, _ := model.NewConstraint(mip.Equal, 1.0)
85+
c := model.NewConstraint(mip.Equal, 1.0)
8286
for i := 0; i < nrTerms; i++ {
8387
c.NewTerm(1.0, v)
8488
}

mip/example_model_test.go

+5-18
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,10 @@ func ExampleModel_empty() {
2525
func ExampleModel_queries() {
2626
model := mip.NewModel()
2727

28-
_, err := model.NewBinaryVar()
29-
if err != nil {
30-
panic(err)
31-
}
32-
_, err = model.NewContinuousVar(1.0, 2.0)
33-
if err != nil {
34-
panic(err)
35-
}
36-
_, err = model.NewBinaryVar()
37-
if err != nil {
38-
panic(err)
39-
}
40-
41-
_, err = model.NewConstraint(mip.Equal, 0.0)
42-
if err != nil {
43-
panic(err)
44-
}
28+
model.NewBool()
29+
model.NewFloat(1.0, 2.0)
30+
model.NewBool()
31+
model.NewConstraint(mip.Equal, 0.0)
4532

4633
fmt.Println(len(model.Vars()))
4734
fmt.Println(len(model.Constraints()))
@@ -52,6 +39,6 @@ func ExampleModel_queries() {
5239
// minimize
5340
// 0: = 0
5441
// 0: B0 [0, 1]
55-
// 1: C1 [1, 2]
42+
// 1: F1 [1, 2]
5643
// 2: B2 [0, 1]
5744
}

mip/example_objective_test.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func ExampleObjective_sense() {
2929
func ExampleObjective_terms() {
3030
model := mip.NewModel()
3131

32-
v1, _ := model.NewBinaryVar()
33-
v2, _ := model.NewBinaryVar()
32+
v1 := model.NewBool()
33+
v2 := model.NewBool()
3434

3535
fmt.Println(len(model.Objective().Terms()))
3636

@@ -73,9 +73,31 @@ func ExampleObjective_terms() {
7373
// isMaximize: false
7474
}
7575

76+
func ExampleObjective_termsToString() {
77+
m := mip.NewModel()
78+
x0 := m.NewBool()
79+
x1 := m.NewBool()
80+
x2 := m.NewBool()
81+
x3 := m.NewBool()
82+
z := m.Objective()
83+
z.NewTerm(3, x2)
84+
z.NewTerm(2, x1)
85+
z.NewTerm(1, x0)
86+
fmt.Println(z)
87+
fmt.Println(z.Term(x0))
88+
z.NewTerm(1, x0)
89+
fmt.Println(z.Term(x0))
90+
fmt.Println(z.Term(x3))
91+
// Output:
92+
// minimize 1 B0 + 2 B1 + 3 B2
93+
// 1 B0 1
94+
// 2 B0 2
95+
// 0 B3 0
96+
}
97+
7698
func benchmarkObjectiveNewTerms(nrTerms int, b *testing.B) {
7799
model := mip.NewModel()
78-
v, _ := model.NewContinuousVar(1.0, 2.0)
100+
v := model.NewFloat(1.0, 2.0)
79101

80102
for i := 0; i < b.N; i++ {
81103
for i := 0; i < nrTerms; i++ {

mip/example_solveoptions_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import (
1010
func ExampleSolveOptions_default() {
1111
solveOptions := mip.NewSolveOptions()
1212

13-
fmt.Println(solveOptions.SolverVerboseLevel())
13+
fmt.Println(solveOptions.Verbosity())
1414
fmt.Println(solveOptions.MIPGapAbsolute())
1515
fmt.Println(solveOptions.MIPGapRelative())
1616
fmt.Println(solveOptions.MaximumDuration())
1717
// Output:
1818
// 0
19-
// 1e-11
20-
// 0.05
19+
// 0
20+
// 0
2121
// 10m0s
2222
}
2323

2424
func ExampleSolveOptions_change() {
2525
solveOptions := mip.NewSolveOptions()
26-
solveOptions.SetVerboseLevel(mip.HIGH)
26+
solveOptions.SetVerbosity(mip.High)
2727
err := solveOptions.SetMIPGapAbsolute(1.23)
2828
if err != nil {
2929
panic(err)
@@ -37,7 +37,7 @@ func ExampleSolveOptions_change() {
3737
panic(err)
3838
}
3939

40-
fmt.Println(solveOptions.SolverVerboseLevel())
40+
fmt.Println(solveOptions.Verbosity())
4141
fmt.Println(solveOptions.MIPGapAbsolute())
4242
fmt.Println(solveOptions.MIPGapRelative())
4343
fmt.Println(solveOptions.MaximumDuration())

0 commit comments

Comments
 (0)