Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pipelines #834

Merged
merged 6 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
wget --quiet --no-check-certificate https://github.com/scipopt/scip/releases/download/$(echo "v${{env.version}}" | tr -d '.')/SCIPOptSuite-${{ env.version }}-Linux-ubuntu20.deb
sudo apt-get update && sudo apt install -y ./SCIPOptSuite-${{ env.version }}-Linux-ubuntu20.deb

- name: Install locales for tests
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

- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -109,7 +112,7 @@ jobs:
- name: Install dependencies (SCIPOptSuite)
if: steps.cache-scip.outputs.cache-hit != 'true'
run: |
brew install tbb boost
brew install tbb boost bison
wget --quiet --no-check-certificate https://github.com/scipopt/scip/releases/download/$(echo "v${{env.version}}" | tr -d '.')/scipoptsuite-${{ env.version }}.tgz
tar xfz scipoptsuite-${{ env.version }}.tgz
cd scipoptsuite-${{ env.version }}
Expand Down
41 changes: 22 additions & 19 deletions src/pyscipopt/recipes/piecewise.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from typing import List

Check warning on line 1 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L1

Added line #L1 was not covered by tests

from pyscipopt import Model, quicksum, Variable, Constraint

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

def add_piecewise_linear_cons(model: Model, X: Variable, Y: Variable, a: List[float], b: List[float]) -> Constraint:

Check warning on line 6 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L6

Added line #L6 was not covered by tests
"""add constraint of the form y = f(x), where f is a piecewise linear function

:param model: pyscipopt model to add the constraint to
:param X: x variable
:param Y: y variable
:param a: array with x-coordinates of the points in the piecewise linear relation
Expand All @@ -12,25 +15,25 @@
Disclaimer: For the moment, can only model 2d piecewise linear functions
Adapted from https://github.com/scipopt/PySCIPOpt/blob/master/examples/finished/piecewise.py
"""
assert len(a) == len(b), "Must have the same number of x and y-coordinates"
assert len(a) == len(b), "Must have the same number of x and y-coordinates"

Check warning on line 18 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L18

Added line #L18 was not covered by tests

K = len(a) - 1
w, z = {}, {}
for k in range(K):
w[k] = model.addVar(lb=-model.infinity())
z[k] = model.addVar(vtype="B")

Check warning on line 24 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L20-L24

Added lines #L20 - L24 were not covered by tests

for k in range(K):
model.addCons(w[k] >= a[k] * z[k])
model.addCons(w[k] <= a[k + 1] * z[k])

Check warning on line 28 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L26-L28

Added lines #L26 - L28 were not covered by tests

K = len(a)-1
w,z = {},{}
for k in range(K):
w[k] = model.addVar(lb=-model.infinity())
z[k] = model.addVar(vtype="B")
model.addCons(quicksum(z[k] for k in range(K)) == 1)

Check warning on line 30 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L30

Added line #L30 was not covered by tests

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

Check warning on line 32 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L32

Added line #L32 was not covered by tests

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

Check warning on line 35 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L34-L35

Added lines #L34 - L35 were not covered by tests

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

Check warning on line 37 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L37

Added line #L37 was not covered by tests

c = [float(b[k+1]-b[k]) / (a[k+1]-a[k]) for k in range(K)]
d = [b[k] - c[k]*a[k] for k in range(K)]

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

return new_cons
return new_cons

Check warning on line 39 in src/pyscipopt/recipes/piecewise.py

View check run for this annotation

Codecov / codecov/patch

src/pyscipopt/recipes/piecewise.py#L39

Added line #L39 was not covered by tests
Loading