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

Support for integer/binary vars for MOSEK #275

Merged
merged 4 commits into from
May 3, 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
9 changes: 8 additions & 1 deletion linopy/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,13 @@
bux = [b if b < np.inf else 0.0 for b in M.ub]
task.putvarboundslice(0, model.nvars, bkx, blx, bux)

if len(model.binaries.labels) + len(model.integers.labels) > 0:
idx = [i for (i, v) in enumerate(M.vtypes) if v in ["B", "I"]]
task.putvartypelist(idx, [mosek.variabletype.type_int] * len(idx))

Check warning on line 369 in linopy/io.py

View check run for this annotation

Codecov / codecov/patch

linopy/io.py#L369

Added line #L369 was not covered by tests
if len(model.binaries.labels) > 0:
bidx = [i for (i, v) in enumerate(M.vtypes) if v == "B"]
task.putvarboundlistconst(bidx, mosek.boundkey.ra, 0.0, 1.0)

Check warning on line 372 in linopy/io.py

View check run for this annotation

Codecov / codecov/patch

linopy/io.py#L372

Added line #L372 was not covered by tests

## Constraints

if len(model.constraints) > 0:
Expand Down Expand Up @@ -396,7 +403,7 @@
if model.is_quadratic:
Q = (0.5 * tril(M.Q + M.Q.transpose())).tocoo()
task.putqobj(Q.row, Q.col, Q.data)
task.putclist(np.arange(model.nvars), M.c)
task.putclist(list(np.arange(model.nvars)), M.c)

Check warning on line 406 in linopy/io.py

View check run for this annotation

Codecov / codecov/patch

linopy/io.py#L406

Added line #L406 was not covered by tests

if model.objective.sense == "max":
task.putobjsense(mosek.objsense.maximize)
Expand Down
3 changes: 1 addition & 2 deletions linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,9 +913,8 @@
"Keyword argument `io_api` has to be one of `lp`, `mps`, `direct` or None"
)

problem_fn = model.to_file(problem_fn)

if io_api != "direct" and io_api is not None:
problem_fn = model.to_file(problem_fn)

Check warning on line 917 in linopy/solvers.py

View check run for this annotation

Codecov / codecov/patch

linopy/solvers.py#L917

Added line #L917 was not covered by tests
problem_fn = maybe_convert_path(problem_fn)
log_fn = maybe_convert_path(log_fn)
warmstart_fn = maybe_convert_path(warmstart_fn)
Expand Down
Loading