Commit ef78d29
* Support MatrixExpr in solution retrieval
Allow MatrixExpr to be queried from Solution and Model methods: add MatrixExpr to type annotations for Solution.__getitem__ and Model.getSolVal, update return types to include np.ndarray, and improve the runtime type check in __getitem__ with a clear TypeError. Simplify best-solution value retrieval by delegating to Solution.__getitem__ (removing the manual loop over MatrixExpr), and update docstrings to reflect the new accepted types and return values.
* Simplify stage check and inline best sol pointer
Refactor model method to directly check SCIP stage (raise a Warning when in INIT or FREE) instead of using an intermediate boolean, and inline the SCIP_SOL* variable declaration when obtaining the best solution. Improves readability and removes an unnecessary temporary variable without changing behavior.
* Add return type annotation to getVal
Annotate Model.getVal in src/pyscipopt/scip.pxi with an explicit return type Union[float, np.ndarray] and remove an extra space in the parameter list. This clarifies that getVal may return either a scalar float or a NumPy array and improves static typing and IDE/type-checker support.
* Add test for Model.getSolVal and getVal
Add test_getSolVal to cover issue #1136. The test creates a Model with a binary scalar and a binary matrix variable, sets an objective, optimizes and obtains the best solution. It asserts that getSolVal(sol, var) matches getVal(var) for both scalar and matrix variables (values expected to be zeros), and verifies that passing a non-variable to getVal or getSolVal raises TypeError.
* Changelog: Model.getSolVal supports MatrixExpr
Add a CHANGELOG entry noting that Model.getSolVal now accepts MatrixExpr. This documents the new support for MatrixExpr inputs in the Model.getSolVal API.
* Use numpy array comparisons in tests
Replace usages of built-in all(...) with np.array_equal(...) to correctly compare array-like results from m.getSolVal and m.getVal. Import numpy as np and construct the expected value as np.array([0, 0]). Also remove an unused itertools import and reorder pyscipopt imports for clarity.
* Refine type hints: use np alias and add overloads
Improve typing in src/pyscipopt/scip.pyi: import Union and overload, alias numpy as np, and switch class bases from numpy.ndarray to np.ndarray. Add overloads for Model.getSolVal and Model.getVal to distinguish scalar returns (Expr/GenExpr -> float) from matrix returns (MatrixExpr -> np.ndarray), improving type accuracy for consumers and IDE/type-checkers.
* Reorder imports in tests/test_model.py
Move 'from helpers.utils import random_mip_1' below the pyscipopt imports to group third-party and local imports (style-only change; no functional impact).
* Apply suggestion from @Joao-Dionisio
---------
Co-authored-by: João Dionísio <57299939+Joao-Dionisio@users.noreply.github.com>
1 parent a03b00e commit ef78d29
File tree
4 files changed
+67
-37
lines changed- src/pyscipopt
- tests
4 files changed
+67
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1098 | 1098 | | |
1099 | 1099 | | |
1100 | 1100 | | |
1101 | | - | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
1102 | 1111 | | |
1103 | 1112 | | |
1104 | 1113 | | |
| |||
10968 | 10977 | | |
10969 | 10978 | | |
10970 | 10979 | | |
10971 | | - | |
| 10980 | + | |
10972 | 10981 | | |
10973 | 10982 | | |
10974 | | - | |
10975 | | - | |
| 10983 | + | |
10976 | 10984 | | |
10977 | 10985 | | |
10978 | 10986 | | |
10979 | 10987 | | |
10980 | | - | |
10981 | | - | |
| 10988 | + | |
| 10989 | + | |
| 10990 | + | |
| 10991 | + | |
| 10992 | + | |
10982 | 10993 | | |
10983 | 10994 | | |
10984 | 10995 | | |
10985 | | - | |
| 10996 | + | |
10986 | 10997 | | |
10987 | 10998 | | |
10988 | 10999 | | |
10989 | 11000 | | |
10990 | 11001 | | |
10991 | 11002 | | |
10992 | | - | |
10993 | | - | |
10994 | | - | |
10995 | | - | |
10996 | | - | |
10997 | 11003 | | |
10998 | 11004 | | |
10999 | 11005 | | |
11000 | | - | |
| 11006 | + | |
11001 | 11007 | | |
11002 | 11008 | | |
11003 | 11009 | | |
11004 | 11010 | | |
11005 | 11011 | | |
11006 | 11012 | | |
11007 | 11013 | | |
| 11014 | + | |
11008 | 11015 | | |
11009 | 11016 | | |
11010 | 11017 | | |
11011 | | - | |
| 11018 | + | |
11012 | 11019 | | |
11013 | 11020 | | |
11014 | 11021 | | |
11015 | 11022 | | |
11016 | 11023 | | |
11017 | 11024 | | |
11018 | | - | |
11019 | | - | |
11020 | | - | |
11021 | | - | |
| 11025 | + | |
11022 | 11026 | | |
11023 | 11027 | | |
11024 | 11028 | | |
11025 | | - | |
| 11029 | + | |
11026 | 11030 | | |
11027 | 11031 | | |
11028 | 11032 | | |
11029 | 11033 | | |
11030 | 11034 | | |
11031 | 11035 | | |
11032 | | - | |
11033 | | - | |
11034 | | - | |
11035 | | - | |
11036 | | - | |
11037 | | - | |
11038 | | - | |
11039 | | - | |
| 11036 | + | |
11040 | 11037 | | |
11041 | 11038 | | |
11042 | 11039 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
499 | | - | |
| 499 | + | |
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| |||
512 | 512 | | |
513 | 513 | | |
514 | 514 | | |
515 | | - | |
| 515 | + | |
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| |||
522 | 522 | | |
523 | 523 | | |
524 | 524 | | |
525 | | - | |
| 525 | + | |
526 | 526 | | |
527 | 527 | | |
528 | 528 | | |
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
1218 | | - | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1219 | 1222 | | |
1220 | 1223 | | |
1221 | 1224 | | |
| |||
1227 | 1230 | | |
1228 | 1231 | | |
1229 | 1232 | | |
1230 | | - | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
1231 | 1237 | | |
1232 | 1238 | | |
1233 | 1239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | | - | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
616 | 619 | | |
617 | 620 | | |
618 | 621 | | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
0 commit comments