Skip to content

Commit eff4bd0

Browse files
authored
Fix pipelines (#834)
* Use backwards compatible type hint * Install bison in macos pipeline * Enable integration test for pull requests for now * Install locales needed by tests in ubuntu integration test * Turn off again integration tests for PRs
1 parent cc24fc8 commit eff4bd0

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

.github/workflows/integration-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
wget --quiet --no-check-certificate https://github.com/scipopt/scip/releases/download/$(echo "v${{env.version}}" | tr -d '.')/SCIPOptSuite-${{ env.version }}-Linux-ubuntu20.deb
2626
sudo apt-get update && sudo apt install -y ./SCIPOptSuite-${{ env.version }}-Linux-ubuntu20.deb
2727
28+
- name: Install locales for tests
29+
run: sudo apt-get install tzdata locales -y && sudo locale-gen pt_PT && sudo update-locale # add pt_PT locale that is used in tests
30+
2831
- name: Setup python ${{ matrix.python-version }}
2932
uses: actions/setup-python@v4
3033
with:
@@ -109,7 +112,7 @@ jobs:
109112
- name: Install dependencies (SCIPOptSuite)
110113
if: steps.cache-scip.outputs.cache-hit != 'true'
111114
run: |
112-
brew install tbb boost
115+
brew install tbb boost bison
113116
wget --quiet --no-check-certificate https://github.com/scipopt/scip/releases/download/$(echo "v${{env.version}}" | tr -d '.')/scipoptsuite-${{ env.version }}.tgz
114117
tar xfz scipoptsuite-${{ env.version }}.tgz
115118
cd scipoptsuite-${{ env.version }}

src/pyscipopt/recipes/piecewise.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
from typing import List
12

23
from pyscipopt import Model, quicksum, Variable, Constraint
34

4-
def add_piecewise_linear_cons(model: Model, X: Variable, Y: Variable, a: list[float], b: list[float]) -> Constraint:
5-
"""add constraint of the form y = f(x), where f is a piecewise linear function
65

6+
def add_piecewise_linear_cons(model: Model, X: Variable, Y: Variable, a: List[float], b: List[float]) -> Constraint:
7+
"""add constraint of the form y = f(x), where f is a piecewise linear function
8+
9+
:param model: pyscipopt model to add the constraint to
710
:param X: x variable
811
:param Y: y variable
912
:param a: array with x-coordinates of the points in the piecewise linear relation
@@ -12,25 +15,25 @@ def add_piecewise_linear_cons(model: Model, X: Variable, Y: Variable, a: list[fl
1215
Disclaimer: For the moment, can only model 2d piecewise linear functions
1316
Adapted from https://github.com/scipopt/PySCIPOpt/blob/master/examples/finished/piecewise.py
1417
"""
15-
assert len(a) == len(b), "Must have the same number of x and y-coordinates"
18+
assert len(a) == len(b), "Must have the same number of x and y-coordinates"
19+
20+
K = len(a) - 1
21+
w, z = {}, {}
22+
for k in range(K):
23+
w[k] = model.addVar(lb=-model.infinity())
24+
z[k] = model.addVar(vtype="B")
25+
26+
for k in range(K):
27+
model.addCons(w[k] >= a[k] * z[k])
28+
model.addCons(w[k] <= a[k + 1] * z[k])
1629

17-
K = len(a)-1
18-
w,z = {},{}
19-
for k in range(K):
20-
w[k] = model.addVar(lb=-model.infinity())
21-
z[k] = model.addVar(vtype="B")
30+
model.addCons(quicksum(z[k] for k in range(K)) == 1)
2231

23-
for k in range(K):
24-
model.addCons(w[k] >= a[k]*z[k])
25-
model.addCons(w[k] <= a[k+1]*z[k])
32+
model.addCons(X == quicksum(w[k] for k in range(K)))
2633

27-
model.addCons(quicksum(z[k] for k in range(K)) == 1)
34+
c = [float(b[k + 1] - b[k]) / (a[k + 1] - a[k]) for k in range(K)]
35+
d = [b[k] - c[k] * a[k] for k in range(K)]
2836

29-
model.addCons(X == quicksum(w[k] for k in range(K)))
37+
new_cons = model.addCons(Y == quicksum(d[k] * z[k] + c[k] * w[k] for k in range(K)))
3038

31-
c = [float(b[k+1]-b[k]) / (a[k+1]-a[k]) for k in range(K)]
32-
d = [b[k] - c[k]*a[k] for k in range(K)]
33-
34-
new_cons = model.addCons(Y == quicksum(d[k]*z[k] + c[k]*w[k] for k in range(K)))
35-
36-
return new_cons
39+
return new_cons

0 commit comments

Comments
 (0)