Skip to content

Commit b0db674

Browse files
committed
use _VarArray and minimize changes compares to master
1 parent c733e02 commit b0db674

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/pyscipopt/scip.pxi

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11862,11 +11862,12 @@ cdef class Model:
1186211862
the objective sense (Default value = 'minimize')
1186311863
1186411864
"""
11865-
cdef SCIP_VAR** _vars
11865+
cdef SCIP_VAR** vars
1186611866
cdef int nvars
1186711867
cdef SCIP_Real* _coeffs
1186811868
cdef SCIP_OBJSENSE objsense
1186911869
cdef int i
11870+
cdef _VarArray wrapper
1187011871

1187111872
if sense == "minimize":
1187211873
objsense = SCIP_OBJSENSE_MINIMIZE
@@ -11889,25 +11890,22 @@ cdef class Model:
1188911890
return
1189011891

1189111892
_coeffs = <SCIP_Real*> malloc(nvars * sizeof(SCIP_Real))
11892-
_vars = <SCIP_VAR**> malloc(nvars * sizeof(SCIP_VAR*))
11893+
vars = <SCIP_VAR**> malloc(nvars * sizeof(SCIP_VAR*))
1189311894

1189411895
i = 0
1189511896
for term, coef in coeffs.terms.items():
1189611897
# avoid CONST term of Expr
1189711898
if term != CONST:
11898-
assert len(term) == 1
11899-
if not isinstance(term[0], Variable):
11900-
raise TypeError(f"Expected Variable, got {type(term[0])}.")
11901-
_vars[i] = (<Variable>term[0]).scip_var
11899+
wrapper = _VarArray(term[0])
11900+
vars[i] = wrapper.ptr[0]
1190211901
_coeffs[i] = coef
1190311902
i += 1
1190411903

11905-
PY_SCIP_CALL(SCIPchgReoptObjective(self._scip, objsense, _vars, _coeffs, nvars))
11904+
PY_SCIP_CALL(SCIPchgReoptObjective(self._scip, objsense, vars, _coeffs, nvars))
1190611905

11907-
free(_vars)
11906+
free(vars)
1190811907
free(_coeffs)
1190911908

11910-
1191111909
def chgVarBranchPriority(self, Variable var, priority):
1191211910
"""
1191311911
Sets the branch priority of the variable.

0 commit comments

Comments
 (0)