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

Add transformed option to getVarDict #934

Merged
merged 2 commits into from
Dec 10, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Added
- Added transformed option to getVarDict, updated test
- Added categorical data example
- Added printProblem to print problem to stdout
- Added stage checks to presolve, freereoptsolve, freetransform
Expand Down
9 changes: 7 additions & 2 deletions src/pyscipopt/scip.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
if rc == SCIP_OKAY:
pass
elif rc == SCIP_ERROR:
raise Exception('SCIP: unspecified error!')

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.8)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / test-coverage (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.9)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.10)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.11)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Windows-test (3.12)

SCIP: unspecified error!

Check failure on line 275 in src/pyscipopt/scip.pxi

View workflow job for this annotation

GitHub Actions / Integration-test (3.12)

SCIP: unspecified error!
elif rc == SCIP_NOMEMORY:
raise MemoryError('SCIP: insufficient memory error!')
elif rc == SCIP_READERROR:
Expand Down Expand Up @@ -3458,17 +3458,22 @@
"""
return SCIPgetNContVars(self._scip)

def getVarDict(self):
def getVarDict(self, transformed=False):
"""
Gets dictionary with variables names as keys and current variable values as items.

Parameters
----------
transformed : bool, optional
Get transformed variables instead of original (Default value = False)

Returns
-------
dict of str to float

"""
var_dict = {}
for var in self.getVars():
for var in self.getVars(transformed=transformed):
var_dict[var.name] = self.getVal(var)
return var_dict

Expand Down
11 changes: 9 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,21 @@ def test_getVarsDict():
x = {}
for i in range(5):
x[i] = model.addVar(lb = -i, ub = i, vtype="C")
for i in range(10,15):
for i in range(5,10):
x[i] = model.addVar(lb = -i, ub = i, vtype="I")
for i in range(20,25):
for i in range(10,15):
x[i] = model.addVar(vtype="B")

model.addConsIndicator(x[0] <= 4, x[10])

model.setPresolve(0)
model.hideOutput()
model.optimize()
var_dict = model.getVarDict()
var_dict_transformed = model.getVarDict(transformed=True)
assert len(var_dict) == model.getNVars(transformed=False)
assert len(var_dict_transformed) == model.getNVars(transformed=True)

for v in x.values():
assert v.name in var_dict
assert model.getVal(v) == var_dict[v.name]
Expand Down
Loading