From 459e8e1d74d9f22694931c675b23126784059092 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 10:13:34 +0100 Subject: [PATCH 1/9] type integer loop variables --- src/pyscipopt/scip.pxi | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index b3e16e3b1..14ed0a663 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -508,11 +508,13 @@ cdef class Row: def getCols(self): """gets list with columns of nonzero entries""" cdef SCIP_COL** cols = SCIProwGetCols(self.scip_row) + cdef int i return [Column.create(cols[i]) for i in range(self.getNNonz())] def getVals(self): """gets list with coefficients of nonzero entries""" cdef SCIP_Real* vals = SCIProwGetVals(self.scip_row) + cdef int i return [vals[i] for i in range(self.getNNonz())] def getNorm(self): @@ -551,6 +553,7 @@ cdef class NLRow: cdef SCIP_VAR** linvars = SCIPnlrowGetLinearVars(self.scip_nlrow) cdef SCIP_Real* lincoefs = SCIPnlrowGetLinearCoefs(self.scip_nlrow) cdef int nlinvars = SCIPnlrowGetNLinearVars(self.scip_nlrow) + cdef int i return [(Variable.create(linvars[i]), lincoefs[i]) for i in range(nlinvars)] def getLhs(self): @@ -612,6 +615,7 @@ cdef class Solution: vals = {} self._checkStage("SCIPgetSolVal") + cdef int i for i in range(SCIPgetNOrigVars(self.scip)): scip_var = SCIPgetOrigVars(self.scip)[i] @@ -678,6 +682,7 @@ cdef class DomainChanges: def getBoundchgs(self): """Returns the bound changes in the domain change.""" nboundchgs = SCIPdomchgGetNBoundchgs(self.scip_domchg) + cdef int i return [BoundChange.create(SCIPdomchgGetBoundchg(self.scip_domchg, i)) for i in range(nboundchgs)] @@ -725,6 +730,7 @@ cdef class Node: cdef int nconss SCIPnodeGetAddedConss(self.scip_node, addedconss, &nconss, addedconsssize) assert nconss == addedconsssize + cdef int i constraints = [Constraint.create(addedconss[i]) for i in range(nconss)] free(addedconss) return constraints @@ -768,6 +774,7 @@ cdef class Node: SCIPnodeGetParentBranchings(self.scip_node, branchvars, branchbounds, boundtypes, &nbranchvars, nbranchvars) + cdef int i py_variables = [Variable.create(branchvars[i]) for i in range(nbranchvars)] py_branchbounds = [branchbounds[i] for i in range(nbranchvars)] py_boundtypes = [boundtypes[i] for i in range(nbranchvars)] @@ -1325,6 +1332,7 @@ cdef class Model: """ cdef SCIP_VAR** _vars cdef int _nvars + cdef int i # turn the constant value into an Expr instance for further processing if not isinstance(coeffs, Expr): @@ -1748,6 +1756,7 @@ cdef class Model: cdef SCIP_VAR** _vars cdef SCIP_VAR* _var cdef int _nvars + cdef int i vars = [] if transformed: @@ -1845,6 +1854,7 @@ cdef class Model: cdef int _nleaves cdef int _nchildren cdef int _nsiblings + cdef int i PY_SCIP_CALL(SCIPgetOpenNodesData(self._scip, &_leaves, &_children, &_siblings, &_nleaves, &_nchildren, &_nsiblings)) @@ -1885,6 +1895,7 @@ cdef class Model: """Retrieve current LP columns""" cdef SCIP_COL** cols cdef int ncols + cdef int i PY_SCIP_CALL(SCIPgetLPColsData(self._scip, &cols, &ncols)) return [Column.create(cols[i]) for i in range(ncols)] @@ -1893,6 +1904,7 @@ cdef class Model: """Retrieve current LP rows""" cdef SCIP_ROW** rows cdef int nrows + cdef int i PY_SCIP_CALL(SCIPgetLPRowsData(self._scip, &rows, &nrows)) return [Row.create(rows[i]) for i in range(nrows)] @@ -1909,6 +1921,7 @@ cdef class Model: """Gets all indices of basic columns and rows: index i >= 0 corresponds to column i, index i < 0 to row -i-1""" cdef int nrows = SCIPgetNLPRows(self._scip) cdef int* inds = malloc(nrows * sizeof(int)) + cdef int i PY_SCIP_CALL(SCIPgetLPBasisInd(self._scip, inds)) result = [inds[i] for i in range(nrows)] @@ -1920,6 +1933,7 @@ cdef class Model: # TODO: sparsity information cdef int nrows = SCIPgetNLPRows(self._scip) cdef SCIP_Real* coefs = malloc(nrows * sizeof(SCIP_Real)) + cdef int i PY_SCIP_CALL(SCIPgetLPBInvRow(self._scip, row, coefs, NULL, NULL)) result = [coefs[i] for i in range(nrows)] @@ -1931,6 +1945,7 @@ cdef class Model: # TODO: sparsity information cdef int ncols = SCIPgetNLPCols(self._scip) cdef SCIP_Real* coefs = malloc(ncols * sizeof(SCIP_Real)) + cdef int i PY_SCIP_CALL(SCIPgetLPBInvARow(self._scip, row, NULL, coefs, NULL, NULL)) result = [coefs[i] for i in range(ncols)] @@ -2169,6 +2184,8 @@ cdef class Model: return list(repeat(elem, length)) assert isinstance(conss, Iterable), "Given constraint list is not iterable." + cdef int idx + cdef int i conss = list(conss) n_conss = len(conss) @@ -2225,6 +2242,7 @@ cdef class Model: """ cdef SCIP_Bool success cdef int _nvars + cdef int i SCIPgetConsNVars(self._scip, constraint.scip_cons, &_nvars, &success) @@ -2253,6 +2271,7 @@ cdef class Model: assert lincons.expr.degree() <= 1, "given constraint is not linear, degree == %d" % lincons.expr.degree() terms = lincons.expr.terms + cdef int i cdef SCIP_CONS* scip_cons @@ -2328,6 +2347,7 @@ cdef class Model: cdef SCIP_EXPR** monomials cdef int* idxs cdef SCIP_CONS* scip_cons + cdef int i terms = cons.expr.terms @@ -2383,6 +2403,7 @@ cdef class Model: cdef SCIP_EXPR** scipexprs cdef SCIP_CONS* scip_cons cdef int nchildren + cdef int i # get arrays from python's expression tree expr = cons.expr @@ -2578,6 +2599,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef int _nvars + cdef int i PY_SCIP_CALL(SCIPcreateConsSOS1(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -2617,6 +2639,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef int _nvars + cdef int i PY_SCIP_CALL(SCIPcreateConsSOS2(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -2654,6 +2677,7 @@ cdef class Model: :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False) """ cdef SCIP_CONS* scip_cons + cdef int idx nvars = len(vars) @@ -2693,6 +2717,7 @@ cdef class Model: :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False) """ cdef SCIP_CONS* scip_cons + cdef int idx nvars = len(vars) @@ -2732,6 +2757,7 @@ cdef class Model: :param stickingatnode: should the constraint always be kept at the node where it was added, even if it may be moved to a more global node? (Default value = False) """ cdef SCIP_CONS* scip_cons + cdef int idx nvars = len(vars) @@ -2775,6 +2801,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef SCIP_VAR* indvar + cdef int i PY_SCIP_CALL(SCIPcreateConsCardinality(self._scip, &scip_cons, str_conversion(name), 0, NULL, cardval, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -3148,6 +3175,7 @@ cdef class Model: def getNlRows(self): """returns a list with the nonlinear rows in SCIP's internal NLP""" cdef SCIP_NLROW** nlrows + cdef int i nlrows = SCIPgetNLPNlRows(self._scip) return [NLRow.create(nlrows[i]) for i in range(self.getNNlRows())] @@ -3271,6 +3299,7 @@ cdef class Model: """Retrieve all constraints.""" cdef SCIP_CONS** _conss cdef int _nconss + cdef int i conss = [] _conss = SCIPgetConss(self._scip) @@ -3305,6 +3334,7 @@ cdef class Model: """ cdef SCIP_Real* _vals cdef SCIP_VAR** _vars + cdef int i constype = bytes(SCIPconshdlrGetName(SCIPconsGetHdlr(cons.scip_cons))).decode('UTF-8') if not constype == 'linear': @@ -3429,6 +3459,7 @@ cdef class Model: """ cdef SCIP** subprobs cdef SCIP_BENDERS* benders + cdef int idx # checking whether subproblems is a dictionary if isinstance(subproblems, dict): @@ -3469,6 +3500,7 @@ cdef class Model: cdef SCIP_Bool _infeasible cdef int nbenders cdef int nsubproblems + cdef int i solvecip = True @@ -3491,6 +3523,7 @@ cdef class Model: cdef SCIP_BENDERS** _benders cdef int nbenders cdef int nsubproblems + cdef int i nbenders = SCIPgetNActiveBenders(self._scip) _benders = SCIPgetBenders(self._scip) @@ -4098,6 +4131,7 @@ cdef class Model: cdef int nlpcands cdef int npriolpcands cdef int nfracimplvars + cdef int i cdef SCIP_VAR** lpcands cdef SCIP_Real* lpcandssol @@ -4122,6 +4156,7 @@ cdef class Model: """ cdef int npseudocands cdef int npriopseudocands + cdef int i cdef SCIP_VAR** pseudocands @@ -4660,6 +4695,7 @@ cdef class Model: """Retrieve list of all feasible primal solutions stored in the solution storage.""" cdef SCIP_SOL** _sols cdef SCIP_SOL* _sol + cdef int i _sols = SCIPgetSols(self._scip) nsols = SCIPgetNSols(self._scip) sols = [] @@ -4760,6 +4796,7 @@ cdef class Model: cdef int _nvars = SCIPgetNVars(self._scip) cdef SCIP_VAR ** _vars = SCIPgetVars(self._scip) + cdef int i ray = [] for i in range(_nvars): @@ -5107,6 +5144,7 @@ cdef class Model: """Gets the values of all parameters as a dict mapping parameter names to their values.""" cdef SCIP_PARAM** params + cdef int i params = SCIPgetParams(self._scip) result = {} @@ -5221,7 +5259,7 @@ cdef class Model: :param sense: the objective sense (Default value = 'minimize') """ - + cdef SCIP_OBJSENSE objsense if sense == "minimize": @@ -5240,6 +5278,7 @@ cdef class Model: cdef SCIP_VAR** _vars cdef int _nvars + cdef int i _vars = SCIPgetOrigVars(self._scip) _nvars = SCIPgetNOrigVars(self._scip) _coeffs = malloc(_nvars * sizeof(SCIP_Real)) From f546bb58b4acf2e5b33367060778ba4a778704b8 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 10:26:47 +0100 Subject: [PATCH 2/9] type SCIP_Real and Variable and Node variables --- src/pyscipopt/scip.pxi | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 14ed0a663..0d242f7d3 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -594,6 +594,7 @@ cdef class Solution: def __getitem__(self, Expr expr): # fast track for Variable + cdef SCIP_Real coeff if isinstance(expr, Variable): self._checkStage("SCIPgetSolVal") var = expr @@ -1333,6 +1334,7 @@ cdef class Model: cdef SCIP_VAR** _vars cdef int _nvars cdef int i + cdef SCIP_Real coef # turn the constant value into an Expr instance for further processing if not isinstance(coeffs, Expr): @@ -1369,6 +1371,7 @@ cdef class Model: def getObjective(self): """Retrieve objective function as Expr""" + cdef Variable var variables = self.getVars() objective = Expr() for var in variables: @@ -1799,6 +1802,7 @@ cdef class Model: def getVarDict(self): """gets dictionary with variables names as keys and current variable values as items""" + cdef Variable var var_dict = {} for var in self.getVars(): var_dict[var.name] = self.getVal(var) @@ -1816,6 +1820,7 @@ cdef class Model: def relax(self): """Relaxes the integrality restrictions of the model""" + cdef Variable var if self.getStage() != SCIP_STAGE_PROBLEM: raise Warning("method can only be called in stage PROBLEM") @@ -2186,6 +2191,7 @@ cdef class Model: assert isinstance(conss, Iterable), "Given constraint list is not iterable." cdef int idx cdef int i + cdef Constraint cons conss = list(conss) n_conss = len(conss) @@ -2272,6 +2278,7 @@ cdef class Model: assert lincons.expr.degree() <= 1, "given constraint is not linear, degree == %d" % lincons.expr.degree() terms = lincons.expr.terms cdef int i + cdef SCIP_Real coeff cdef SCIP_CONS* scip_cons @@ -2348,6 +2355,10 @@ cdef class Model: cdef int* idxs cdef SCIP_CONS* scip_cons cdef int i + cdef int j + cdef int idx + cdef SCIP_Real coef + cdef Variable var terms = cons.expr.terms @@ -2404,6 +2415,8 @@ cdef class Model: cdef SCIP_CONS* scip_cons cdef int nchildren cdef int i + cdef Node node + cdef int c # get arrays from python's expression tree expr = cons.expr @@ -2600,6 +2613,7 @@ cdef class Model: cdef SCIP_CONS* scip_cons cdef int _nvars cdef int i + cdef Variable var PY_SCIP_CALL(SCIPcreateConsSOS1(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -2640,6 +2654,7 @@ cdef class Model: cdef SCIP_CONS* scip_cons cdef int _nvars cdef int i + cdef Variable var PY_SCIP_CALL(SCIPcreateConsSOS2(self._scip, &scip_cons, str_conversion(name), 0, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -2678,6 +2693,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef int idx + cdef Variable var nvars = len(vars) @@ -2718,6 +2734,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef int idx + cdef Variable var nvars = len(vars) @@ -2758,6 +2775,7 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons cdef int idx + cdef Variable var nvars = len(vars) @@ -2802,6 +2820,7 @@ cdef class Model: cdef SCIP_CONS* scip_cons cdef SCIP_VAR* indvar cdef int i + cdef Variable v PY_SCIP_CALL(SCIPcreateConsCardinality(self._scip, &scip_cons, str_conversion(name), 0, NULL, cardval, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode)) @@ -2855,6 +2874,8 @@ cdef class Model: assert isinstance(cons, ExprCons), "given constraint is not ExprCons but %s" % cons.__class__.__name__ cdef SCIP_CONS* scip_cons cdef SCIP_VAR* _binVar + cdef SCIP_Real coeff + if cons._lhs is not None and cons._rhs is not None: raise ValueError("expected inequality that has either only a left or right hand side") @@ -3235,6 +3256,7 @@ cdef class Model: """ cdef SCIP_EXPR* expr + cdef int termidx # linear terms cdef SCIP_EXPR** _linexprs @@ -3501,6 +3523,7 @@ cdef class Model: cdef int nbenders cdef int nsubproblems cdef int i + cdef int j solvecip = True @@ -3524,6 +3547,7 @@ cdef class Model: cdef int nbenders cdef int nsubproblems cdef int i + cdef int j nbenders = SCIPgetNActiveBenders(self._scip) _benders = SCIPgetBenders(self._scip) @@ -5259,7 +5283,7 @@ cdef class Model: :param sense: the objective sense (Default value = 'minimize') """ - + cdef SCIP_Real coef cdef SCIP_OBJSENSE objsense if sense == "minimize": @@ -5279,6 +5303,7 @@ cdef class Model: cdef SCIP_VAR** _vars cdef int _nvars cdef int i + cdef SCIP_Real coef _vars = SCIPgetOrigVars(self._scip) _nvars = SCIPgetNOrigVars(self._scip) _coeffs = malloc(_nvars * sizeof(SCIP_Real)) From e95be67880fb9fc5f8b20133176536e380d021e4 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 10:49:11 +0100 Subject: [PATCH 3/9] type loop variables in remaining pxi files --- src/pyscipopt/benders.pxi | 2 ++ src/pyscipopt/conshdlr.pxi | 16 ++++++++++++++++ src/pyscipopt/cutsel.pxi | 3 ++- src/pyscipopt/expr.pxi | 1 + src/pyscipopt/lp.pxi | 12 ++++++++++++ src/pyscipopt/scip.pxi | 3 --- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/pyscipopt/benders.pxi b/src/pyscipopt/benders.pxi index 66a394d8d..0a592f553 100644 --- a/src/pyscipopt/benders.pxi +++ b/src/pyscipopt/benders.pxi @@ -176,6 +176,8 @@ cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SO SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint, SCIP_Bool infeasible, SCIP_Bool* merged) noexcept with gil: cdef SCIP_BENDERSDATA* bendersdata + cdef int i + bendersdata = SCIPbendersGetData(benders) PyBenders = bendersdata if sol == NULL: diff --git a/src/pyscipopt/conshdlr.pxi b/src/pyscipopt/conshdlr.pxi index 207177802..4b8e15947 100644 --- a/src/pyscipopt/conshdlr.pxi +++ b/src/pyscipopt/conshdlr.pxi @@ -169,6 +169,7 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) + cdef int i cdef constraints = [] for i in range(nconss): constraints.append(getPyCons(conss[i])) @@ -178,6 +179,7 @@ cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consexit(constraints) @@ -186,6 +188,7 @@ cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consinitpre(constraints) @@ -194,6 +197,7 @@ cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consexitpre(constraints) @@ -202,6 +206,7 @@ cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consinitsol(constraints) @@ -210,6 +215,7 @@ cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cdef SCIP_RETCODE PyConsExitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool restart) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consexitsol(constraints, restart) @@ -246,6 +252,7 @@ cdef SCIP_RETCODE PyConsTrans (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* s cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool* infeasible) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) result_dict = PyConshdlr.consinitlp(constraints) @@ -255,6 +262,7 @@ cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** cdef SCIP_RETCODE PyConsSepalp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) result_dict = PyConshdlr.conssepalp(constraints, nusefulconss) @@ -265,6 +273,7 @@ cdef SCIP_RETCODE PyConsSepasol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* SCIP_SOL* sol, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) solution = Solution.create(scip, sol) @@ -276,6 +285,7 @@ cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) result_dict = PyConshdlr.consenfolp(constraints, nusefulconss, solinfeasible) @@ -285,6 +295,7 @@ cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** cdef SCIP_RETCODE PyConsEnforelax (SCIP* scip, SCIP_SOL* sol, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) solution = Solution.create(scip, sol) @@ -296,6 +307,7 @@ cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** SCIP_Bool solinfeasible, SCIP_Bool objinfeasible, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) result_dict = PyConshdlr.consenfops(constraints, nusefulconss, solinfeasible, objinfeasible) @@ -306,6 +318,7 @@ cdef SCIP_RETCODE PyConsCheck (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) solution = Solution.create(scip, sol) @@ -317,6 +330,7 @@ cdef SCIP_RETCODE PyConsProp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** c SCIP_PROPTIMING proptiming, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, proptiming) @@ -330,6 +344,7 @@ cdef SCIP_RETCODE PyConsPresol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) # dictionary for input/output parameters @@ -403,6 +418,7 @@ cdef SCIP_RETCODE PyConsDisable (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* cdef SCIP_RETCODE PyConsDelvars (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consdelvars(constraints) diff --git a/src/pyscipopt/cutsel.pxi b/src/pyscipopt/cutsel.pxi index d259fb28e..adb5f06af 100644 --- a/src/pyscipopt/cutsel.pxi +++ b/src/pyscipopt/cutsel.pxi @@ -76,7 +76,8 @@ cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cu cdef SCIP_ROW* scip_row cutseldata = SCIPcutselGetData(cutsel) PyCutsel = cutseldata - + cdef int i + # translate cuts to python pycuts = [Row.create(cuts[i]) for i in range(ncuts)] pyforcedcuts = [Row.create(forcedcuts[i]) for i in range(nforcedcuts)] diff --git a/src/pyscipopt/expr.pxi b/src/pyscipopt/expr.pxi index aac19817c..b3a80d7e4 100644 --- a/src/pyscipopt/expr.pxi +++ b/src/pyscipopt/expr.pxi @@ -115,6 +115,7 @@ CONST = Term() # helper function def buildGenExprObj(expr): """helper function to generate an object of type GenExpr""" + cdef SCIP_Real coef if _is_number(expr): return Constant(expr) elif isinstance(expr, Expr): diff --git a/src/pyscipopt/lp.pxi b/src/pyscipopt/lp.pxi index 04f6fde3d..0729bf40a 100644 --- a/src/pyscipopt/lp.pxi +++ b/src/pyscipopt/lp.pxi @@ -71,6 +71,7 @@ cdef class LP: cdef SCIP_Real c_lb cdef SCIP_Real c_ub cdef int c_beg + cdef int i c_obj = obj c_lb = lb @@ -105,6 +106,7 @@ cdef class LP: cdef SCIP_Real* c_coefs cdef int* c_inds cdef int* c_beg + cdef int i if nnonz > 0: @@ -160,6 +162,7 @@ cdef class LP: """ beg = 0 nnonz = len(entries) + cdef int i cdef SCIP_Real* c_coefs = malloc(nnonz * sizeof(SCIP_Real)) cdef int* c_inds = malloc(nnonz * sizeof(int)) @@ -190,6 +193,7 @@ cdef class LP: """ nrows = len(entrieslist) nnonz = sum(len(entries) for entries in entrieslist) + cdef int i cdef SCIP_Real* c_lhss = malloc(nrows * sizeof(SCIP_Real)) cdef SCIP_Real* c_rhss = malloc(nrows * sizeof(SCIP_Real)) @@ -232,6 +236,7 @@ cdef class LP: firstcol -- first column (default 0) lastcol -- last column (default ncols - 1) """ + cdef int i lastcol = lastcol if lastcol != None else self.ncols() - 1 if firstcol > lastcol: @@ -261,6 +266,7 @@ cdef class LP: firstrow -- first row (default 0) lastrow -- last row (default nrows - 1) """ + cdef int i lastrow = lastrow if lastrow != None else self.nrows() - 1 if firstrow > lastrow: @@ -363,6 +369,7 @@ cdef class LP: def getPrimal(self): """Returns the primal solution of the last LP solve.""" + cdef int i ncols = self.ncols() cdef SCIP_Real* c_primalsol = malloc(ncols * sizeof(SCIP_Real)) PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, c_primalsol, NULL, NULL, NULL)) @@ -379,6 +386,7 @@ cdef class LP: def getDual(self): """Returns the dual solution of the last LP solve.""" + cdef int i nrows = self.nrows() cdef SCIP_Real* c_dualsol = malloc(nrows * sizeof(SCIP_Real)) PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, NULL, c_dualsol, NULL, NULL)) @@ -395,6 +403,7 @@ cdef class LP: def getPrimalRay(self): """Returns a primal ray if possible, None otherwise.""" + cdef int i if not SCIPlpiHasPrimalRay(self.lpi): return None ncols = self.ncols() @@ -409,6 +418,7 @@ cdef class LP: def getDualRay(self): """Returns a dual ray if possible, None otherwise.""" + cdef int i if not SCIPlpiHasDualRay(self.lpi): return None nrows = self.nrows() @@ -429,6 +439,7 @@ cdef class LP: def getRedcost(self): """Returns the reduced cost vector of the last LP solve.""" + cdef int i ncols = self.ncols() cdef SCIP_Real* c_redcost = malloc(ncols * sizeof(SCIP_Real)) @@ -443,6 +454,7 @@ cdef class LP: def getBasisInds(self): """Returns the indices of the basic columns and rows; index i >= 0 corresponds to column i, index i < 0 to row -i-1""" + cdef int i nrows = self.nrows() cdef int* c_binds = malloc(nrows * sizeof(int)) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 0d242f7d3..f869d6083 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2191,7 +2191,6 @@ cdef class Model: assert isinstance(conss, Iterable), "Given constraint list is not iterable." cdef int idx cdef int i - cdef Constraint cons conss = list(conss) n_conss = len(conss) @@ -2415,7 +2414,6 @@ cdef class Model: cdef SCIP_CONS* scip_cons cdef int nchildren cdef int i - cdef Node node cdef int c # get arrays from python's expression tree @@ -5283,7 +5281,6 @@ cdef class Model: :param sense: the objective sense (Default value = 'minimize') """ - cdef SCIP_Real coef cdef SCIP_OBJSENSE objsense if sense == "minimize": From ee40ac9e46c0c33be6567c9a7b23fc4990b9012d Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 14:32:32 +0100 Subject: [PATCH 4/9] Add type hints to scip.pxi --- src/pyscipopt/reader.pxi | 1 + src/pyscipopt/scip.pxi | 369 ++++++++++++++++++++------------------- tests/test_gomory.py | 2 +- 3 files changed, 187 insertions(+), 185 deletions(-) diff --git a/src/pyscipopt/reader.pxi b/src/pyscipopt/reader.pxi index 2c45585d6..09e937c56 100644 --- a/src/pyscipopt/reader.pxi +++ b/src/pyscipopt/reader.pxi @@ -46,6 +46,7 @@ cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file, SCIP_CONS** conss, int nconss, int maxnconss, int startnconss, SCIP_Bool genericnames, SCIP_RESULT* result) noexcept with gil: cdef SCIP_READERDATA* readerdata + cdef int i readerdata = SCIPreaderGetData(reader) cdef int fd = fileno(file) PyFile = os.fdopen(fd, "w", closefd=False) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index f869d6083..44c47ae06 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -999,7 +999,7 @@ cdef void relayErrorMessage(void *messagehdlr, FILE *file, const char *msg) noex cdef class Model: """Main class holding a pointer to SCIP for managing most interactions""" - def __init__(self, problemName='model', defaultPlugins=True, Model sourceModel=None, origcopy=False, globalcopy=True, enablepricing=False, createscip=True, threadsafe=False): + def __init__(self, str problemName='model', SCIP_Bool defaultPlugins=True, Model sourceModel=None, SCIP_Bool origcopy=False, SCIP_Bool globalcopy=True, SCIP_Bool enablepricing=False, SCIP_Bool createscip=True, SCIP_Bool threadsafe=False): """ :param problemName: name of the problem (default 'model') :param defaultPlugins: use default plugins? (default True) @@ -1109,7 +1109,7 @@ cdef class Model: """Includes all default plug-ins into SCIP""" PY_SCIP_CALL(SCIPincludeDefaultPlugins(self._scip)) - def createProbBasic(self, problemName='model'): + def createProbBasic(self, str problemName='model'): """Create new problem instance with given name :param problemName: name of model or problem (Default value = 'model') @@ -1220,59 +1220,59 @@ cdef class Model: """Retrieve feasibility tolerance""" return SCIPfeastol(self._scip) - def feasFrac(self, value): + def feasFrac(self, SCIP_Real value): """returns fractional part of value, i.e. x - floor(x) in feasible tolerance: x - floor(x+feastol)""" return SCIPfeasFrac(self._scip, value) - def frac(self, value): + def frac(self, SCIP_Real value): """returns fractional part of value, i.e. x - floor(x) in epsilon tolerance: x - floor(x+eps)""" return SCIPfrac(self._scip, value) - def isZero(self, value): + def isZero(self, SCIP_Real value): """returns whether abs(value) < eps""" return SCIPisZero(self._scip, value) - def isFeasZero(self, value): + def isFeasZero(self, SCIP_Real value): """returns whether abs(value) < feastol""" return SCIPisFeasZero(self._scip, value) - def isInfinity(self, value): + def isInfinity(self, SCIP_Real value): """returns whether value is SCIP's infinity""" return SCIPisInfinity(self._scip, value) - def isFeasNegative(self, value): + def isFeasNegative(self, SCIP_Real value): """returns whether value < -feastol""" return SCIPisFeasNegative(self._scip, value) - def isFeasIntegral(self, value): + def isFeasIntegral(self, SCIP_Real value): """returns whether value is integral within the LP feasibility bounds""" return SCIPisFeasIntegral(self._scip, value) - def isEQ(self, val1, val2): + def isEQ(self, SCIP_Real val1, SCIP_Real val2): """checks, if values are in range of epsilon""" return SCIPisEQ(self._scip, val1, val2) - def isFeasEQ(self, val1, val2): + def isFeasEQ(self, SCIP_Real val1, SCIP_Real val2): """checks, if relative difference of values is in range of feasibility tolerance""" return SCIPisFeasEQ(self._scip, val1, val2) - def isLE(self, val1, val2): + def isLE(self, SCIP_Real val1, SCIP_Real val2): """returns whether val1 <= val2 + eps""" return SCIPisLE(self._scip, val1, val2) - def isLT(self, val1, val2): + def isLT(self, SCIP_Real val1, SCIP_Real val2): """returns whether val1 < val2 - eps""" return SCIPisLT(self._scip, val1, val2) - def isGE(self, val1, val2): + def isGE(self, SCIP_Real val1, SCIP_Real val2): """returns whether val1 >= val2 - eps""" return SCIPisGE(self._scip, val1, val2) - def isGT(self, val1, val2): + def isGT(self, SCIP_Real val1, SCIP_Real val2): """returns whether val1 > val2 + eps""" return SCIPisGT(self._scip, val1, val2) - def getCondition(self, exact=False): + def getCondition(self, SCIP_Bool exact=False): """Get the current LP's condition number :param exact: whether to get an estimate or the exact value (Default value = False) @@ -1288,7 +1288,7 @@ cdef class Model: return quality - def enableReoptimization(self, enable=True): + def enableReoptimization(self, SCIP_Bool enable=True): """include specific heuristics and branching rules for reoptimization""" PY_SCIP_CALL(SCIPenableReoptimization(self._scip, enable)) @@ -1310,7 +1310,7 @@ cdef class Model: """Set the objective sense to maximization.""" PY_SCIP_CALL(SCIPsetObjsense(self._scip, SCIP_OBJSENSE_MAXIMIZE)) - def setObjlimit(self, objlimit): + def setObjlimit(self, SCIP_Real objlimit): """Set a limit on the objective function. Only solutions with objective value better than this limit are accepted. @@ -1323,12 +1323,12 @@ cdef class Model: """returns current limit on objective function.""" return SCIPgetObjlimit(self._scip) - def setObjective(self, coeffs, sense = 'minimize', clear = 'true'): + def setObjective(self, coeffs, str sense = 'minimize', SCIP_Bool clear = True): """Establish the objective function as a linear expression. :param coeffs: the coefficients :param sense: the objective sense (Default value = 'minimize') - :param clear: set all other variables objective coefficient to zero (Default value = 'true') + :param clear: set all other variables objective coefficient to zero (Default value = True) """ cdef SCIP_VAR** _vars @@ -1381,7 +1381,7 @@ cdef class Model: objective.normalize() return objective - def addObjoffset(self, offset, solutions = False): + def addObjoffset(self, SCIP_Real offset, SCIP_Bool solutions = False): """Add constant offset to objective :param offset: offset to add @@ -1393,7 +1393,7 @@ cdef class Model: else: PY_SCIP_CALL(SCIPaddOrigObjoffset(self._scip, offset)) - def getObjoffset(self, original = True): + def getObjoffset(self, SCIP_Bool original = True): """Retrieve constant objective offset :param original: offset of original or transformed problem (Default value = True) @@ -1414,7 +1414,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetObjIntegral(self._scip)) - def getLocalEstimate(self, original = False): + def getLocalEstimate(self, SCIP_Bool original = False): """gets estimate of best primal solution w.r.t. original or transformed problem contained in current subtree :param original: estimate of original or transformed problem (Default value = False) @@ -1425,7 +1425,7 @@ cdef class Model: return SCIPgetLocalTransEstimate(self._scip) # Setting parameters - def setPresolve(self, setting): + def setPresolve(self, SCIP_PARAMSETTING setting): """Set presolving parameter settings. :param setting: the parameter settings (SCIP_PARAMSETTING) @@ -1433,12 +1433,12 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetPresolving(self._scip, setting, True)) - def setProbName(self, name): + def setProbName(self, str name): """Set problem name""" n = str_conversion(name) PY_SCIP_CALL(SCIPsetProbName(self._scip, n)) - def setSeparating(self, setting): + def setSeparating(self, SCIP_PARAMSETTING setting): """Set separating parameter settings. :param setting: the parameter settings (SCIP_PARAMSETTING) @@ -1446,7 +1446,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetSeparating(self._scip, setting, True)) - def setHeuristics(self, setting): + def setHeuristics(self, SCIP_PARAMSETTING setting): """Set heuristics parameter settings. :param setting: the parameter setting (SCIP_PARAMSETTING) @@ -1454,7 +1454,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetHeuristics(self._scip, setting, True)) - def disablePropagation(self, onlyroot=False): + def disablePropagation(self, SCIP_Bool onlyroot=False): """Disables propagation in SCIP to avoid modifying the original problem during transformation. :param onlyroot: use propagation when root processing is finished (Default value = False) @@ -1464,7 +1464,7 @@ cdef class Model: if not onlyroot: self.setIntParam("propagating/maxrounds", 0) - def writeProblem(self, filename='model.cip', trans=False, genericnames=False): + def writeProblem(self, str filename='model.cip', SCIP_Bool trans=False, SCIP_Bool genericnames=False): """Write current model/problem to a file. :param filename: the name of the file to be used (Default value = 'model.cip'). Should have an extension corresponding to one of the readable file formats, described in https://www.scipopt.org/doc/html/group__FILEREADERS.php. @@ -1492,7 +1492,7 @@ cdef class Model: # Variable Functions - def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, pricedVar=False, pricedVarScore=1.0): + def addVar(self, str name='', str vtype='C', lb: Union[SCIP_Real, None]=0.0, ub: Union[SCIP_Real, None]=None, SCIP_Real obj=0.0, SCIP_Bool pricedVar=False, SCIP_Real pricedVarScore=1.0): """Create a new variable. Default variable is non-negative and continuous. :param name: name of the variable, generic if empty (Default value = '') @@ -1561,7 +1561,7 @@ cdef class Model: return Variable.create(_tvar) - def addVarLocks(self, Variable var, nlocksdown, nlocksup): + def addVarLocks(self, Variable var, int nlocksdown, int nlocksup): """adds given values to lock numbers of variable for rounding :param Variable var: variable to adjust the locks for @@ -1571,7 +1571,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPaddVarLocks(self._scip, var.scip_var, nlocksdown, nlocksup)) - def fixVar(self, Variable var, val): + def fixVar(self, Variable var, SCIP_Real val): """Fixes the variable var to the value val if possible. :param Variable var: variable to fix @@ -1597,7 +1597,7 @@ cdef class Model: PY_SCIP_CALL(SCIPdelVar(self._scip, var.scip_var, &deleted)) return deleted - def tightenVarLb(self, Variable var, lb, force=False): + def tightenVarLb(self, Variable var, SCIP_Real lb, SCIP_Bool force=False): """Tighten the lower bound in preprocessing or current node, if the bound is tighter. :param var: SCIP variable @@ -1614,7 +1614,7 @@ cdef class Model: return infeasible, tightened - def tightenVarUb(self, Variable var, ub, force=False): + def tightenVarUb(self, Variable var, SCIP_Real ub, SCIP_Bool force=False): """Tighten the upper bound in preprocessing or current node, if the bound is tighter. :param var: SCIP variable @@ -1631,7 +1631,7 @@ cdef class Model: return infeasible, tightened - def tightenVarUbGlobal(self, Variable var, ub, force=False): + def tightenVarUbGlobal(self, Variable var, SCIP_Real ub, SCIP_Bool force=False): """Tighten the global upper bound, if the bound is tighter. :param var: SCIP variable @@ -1647,7 +1647,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarUbGlobal(self._scip, var.scip_var, ub, force, &infeasible, &tightened)) return infeasible, tightened - def tightenVarLbGlobal(self, Variable var, lb, force=False): + def tightenVarLbGlobal(self, Variable var, SCIP_Real lb, SCIP_Bool force=False): """Tighten the global upper bound, if the bound is tighter. :param var: SCIP variable @@ -1663,7 +1663,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarLbGlobal(self._scip, var.scip_var, lb, force, &infeasible, &tightened)) return infeasible, tightened - def chgVarLb(self, Variable var, lb): + def chgVarLb(self, Variable var, SCIP_Real lb): """Changes the lower bound of the specified variable. :param Variable var: variable to change bound of @@ -1674,7 +1674,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLb(self._scip, var.scip_var, lb)) - def chgVarUb(self, Variable var, ub): + def chgVarUb(self, Variable var, SCIP_Real ub): """Changes the upper bound of the specified variable. :param Variable var: variable to change bound of @@ -1685,7 +1685,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUb(self._scip, var.scip_var, ub)) - def chgVarLbGlobal(self, Variable var, lb): + def chgVarLbGlobal(self, Variable var, SCIP_Real lb): """Changes the global lower bound of the specified variable. :param Variable var: variable to change bound of @@ -1696,7 +1696,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbGlobal(self._scip, var.scip_var, lb)) - def chgVarUbGlobal(self, Variable var, ub): + def chgVarUbGlobal(self, Variable var, SCIP_Real ub): """Changes the global upper bound of the specified variable. :param Variable var: variable to change bound of @@ -1707,7 +1707,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUbGlobal(self._scip, var.scip_var, ub)) - def chgVarLbNode(self, Node node, Variable var, lb): + def chgVarLbNode(self, Node node, Variable var, SCIP_Real lb): """Changes the lower bound of the specified variable at the given node. :param Variable var: variable to change bound of @@ -1718,7 +1718,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbNode(self._scip, node.scip_node, var.scip_var, lb)) - def chgVarUbNode(self, Node node, Variable var, ub): + def chgVarUbNode(self, Node node, Variable var, SCIP_Real ub): """Changes the upper bound of the specified variable at the given node. :param Variable var: variable to change bound of @@ -1729,7 +1729,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUbNode(self._scip, node.scip_node, var.scip_var, ub)) - def chgVarType(self, Variable var, vtype): + def chgVarType(self, Variable var, str vtype): """Changes the type of a variable :param Variable var: variable to change type of @@ -1750,7 +1750,7 @@ cdef class Model: if infeasible: print('could not change variable type of variable %s' % var) - def getVars(self, transformed=False): + def getVars(self, SCIP_Bool transformed=False): """Retrieve all variables. :param transformed: get transformed variables instead of original (Default value = False) @@ -1808,7 +1808,7 @@ cdef class Model: var_dict[var.name] = self.getVal(var) return var_dict - def updateNodeLowerbound(self, Node node, lb): + def updateNodeLowerbound(self, Node node, SCIP_Real lb): """if given value is larger than the node's lower bound (in transformed problem), sets the node's lower bound to the new value @@ -1933,7 +1933,7 @@ cdef class Model: free(inds) return result - def getLPBInvRow(self, row): + def getLPBInvRow(self, int row): """gets a row from the inverse basis matrix B^-1""" # TODO: sparsity information cdef int nrows = SCIPgetNLPRows(self._scip) @@ -1945,7 +1945,7 @@ cdef class Model: free(coefs) return result - def getLPBInvARow(self, row): + def getLPBInvARow(self, int row): """gets a row from B^-1 * A""" # TODO: sparsity information cdef int ncols = SCIPgetNLPCols(self._scip) @@ -1963,7 +1963,7 @@ cdef class Model: #TODO: documentation!! # LP Row Methods - def createEmptyRowSepa(self, Sepa sepa, name="row", lhs = 0.0, rhs = None, local = True, modifiable = False, removable = True): + def createEmptyRowSepa(self, Sepa sepa, str name="row", lhs: Union[SCIP_Real, None] = 0.0, rhs: Union[SCIP_Real, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): """creates and captures an LP row without any coefficients from a separator :param sepa: separator that creates the row @@ -1982,7 +1982,7 @@ cdef class Model: PyRow = Row.create(row) return PyRow - def createEmptyRowUnspec(self, name="row", lhs = 0.0, rhs = None, local = True, modifiable = False, removable = True): + def createEmptyRowUnspec(self, str name="row", lhs: Union[SCIP_Real, None] = 0.0, rhs: Union[SCIP_Real, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): """creates and captures an LP row without any coefficients from an unspecified source :param name: name of row (Default value = "row") @@ -2023,7 +2023,7 @@ cdef class Model: """flushes all cached row extensions after a call of cacheRowExtensions() and merges coefficients with equal columns into a single coefficient""" PY_SCIP_CALL(SCIPflushRowExtensions(self._scip, row.scip_row)) - def addVarToRow(self, Row row not None, Variable var not None, value): + def addVarToRow(self, Row row not None, Variable var not None, SCIP_Real value): """resolves variable to columns and adds them with the coefficient to the row""" PY_SCIP_CALL(SCIPaddVarToRow(self._scip, row.scip_row, var.scip_var, value)) @@ -2065,7 +2065,7 @@ cdef class Model: """ returns row's cutoff distance in the direction of the given primal solution""" return SCIPgetCutLPSolCutoffDistance(self._scip, sol.sol, cut.scip_row) - def addCut(self, Row cut not None, forcecut = False): + def addCut(self, Row cut not None, SCIP_Bool forcecut = False): """adds cut to separation storage and returns whether cut has been detected to be infeasible for local bounds""" cdef SCIP_Bool infeasible PY_SCIP_CALL(SCIPaddRow(self._scip, cut.scip_row, forcecut, &infeasible)) @@ -2084,7 +2084,7 @@ cdef class Model: at the current node""" return SCIPgetNSepaRounds(self._scip) - def separateSol(self, Solution sol = None, pretendroot = False, allowlocal = True, onlydelayed = False): + def separateSol(self, Solution sol = None, SCIP_Bool pretendroot = False, SCIP_Bool allowlocal = True, SCIP_Bool onlydelayed = False): """separates the given primal solution or the current LP solution by calling the separators and constraint handlers' separation methods; the generated cuts are stored in the separation storage and can be accessed with the methods SCIPgetCuts() and @@ -2108,10 +2108,10 @@ cdef class Model: return delayed, cutoff # Constraint functions - def addCons(self, cons, name='', initial=True, separate=True, - enforce=True, check=True, propagate=True, local=False, - modifiable=False, dynamic=False, removable=False, - stickingatnode=False): + def addCons(self, cons: Union[Constraint, ExprCons], str name='', SCIP_Bool initial=True, SCIP_Bool separate=True, + SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, SCIP_Bool local=False, + SCIP_Bool modifiable=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, + SCIP_Bool stickingatnode=False): """Add a linear or nonlinear constraint. :param cons: constraint object @@ -2154,10 +2154,10 @@ cdef class Model: else: return self._addNonlinearCons(cons, **kwargs) - def addConss(self, conss, name='', initial=True, separate=True, - enforce=True, check=True, propagate=True, local=False, - modifiable=False, dynamic=False, removable=False, - stickingatnode=False): + def addConss(self, conss: list[Union[Constraint, ExprCons]], name: Union[list[str],str] = '', initial: Union[list[SCIP_Bool], SCIP_Bool] = True, separate: Union[list[SCIP_Bool], SCIP_Bool] = True, + enforce: Union[list[SCIP_Bool], SCIP_Bool] = True, check: Union[list[SCIP_Bool], SCIP_Bool] = True, propagate: Union[list[SCIP_Bool], SCIP_Bool] = True, local: Union[list[SCIP_Bool], SCIP_Bool] = False, + modifiable: Union[list[SCIP_Bool], SCIP_Bool] = False, dynamic: Union[list[SCIP_Bool], SCIP_Bool] = False, removable: Union[list[SCIP_Bool], SCIP_Bool] = False, + stickingatnode: Union[list[SCIP_Bool], SCIP_Bool] = False): """Adds multiple linear or quadratic constraints. Each of the constraints is added to the model using Model.addCons(). @@ -2200,6 +2200,7 @@ cdef class Model: name = ["" for idx in range(n_conss)] else: name = ["%s_%s" % (name, idx) for idx in range(n_conss)] + initial = ensure_iterable(initial, n_conss) separate = ensure_iterable(separate, n_conss) enforce = ensure_iterable(enforce, n_conss) @@ -2551,7 +2552,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddExprNonlinear(self._scip, cons.scip_cons, scip_expr, coef)) self.delCons(temp_cons) - def addConsCoeff(self, Constraint cons, Variable var, coeff): + def addConsCoeff(self, Constraint cons, Variable var, SCIP_Real coeff): """Add coefficient to the linear constraint (if non-zero). :param Constraint cons: constraint to be changed @@ -2588,10 +2589,10 @@ cdef class Model: PY_SCIP_CALL(SCIPaddConsLocal(self._scip, cons.scip_cons, NULL)) Py_INCREF(cons) - def addConsSOS1(self, vars, weights=None, name="SOS1cons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsSOS1(self, list[Variable] vars, list[SCIP_Real] weights=None, str name="SOS1cons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add an SOS1 constraint. :param vars: list of variables to be included @@ -2629,10 +2630,10 @@ cdef class Model: PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) return Constraint.create(scip_cons) - def addConsSOS2(self, vars, weights=None, name="SOS2cons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsSOS2(self, list[Variable] vars, list[SCIP_Real] weights=None, str name="SOS2cons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add an SOS2 constraint. :param vars: list of variables to be included @@ -2670,10 +2671,10 @@ cdef class Model: PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) return Constraint.create(scip_cons) - def addConsAnd(self, vars, resvar, name="ANDcons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, modifiable=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsAnd(self, list[Variable] vars, Variable resvar, str name="ANDcons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool modifiable=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add an AND-constraint. :param vars: list of BINARY variables to be included (operators) :param resvar: BINARY variable (resultant) @@ -2711,10 +2712,10 @@ cdef class Model: return pyCons - def addConsOr(self, vars, resvar, name="ORcons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, modifiable=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsOr(self, list[Variable] vars, Variable resvar, str name="ORcons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool modifiable=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add an OR-constraint. :param vars: list of BINARY variables to be included (operators) :param resvar: BINARY variable (resultant) @@ -2752,10 +2753,10 @@ cdef class Model: return pyCons - def addConsXor(self, vars, rhsvar, name="XORcons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, modifiable=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsXor(self, list[Variable] vars, SCIP_Bool rhsvar, str name="XORcons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool modifiable=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add a XOR-constraint. :param vars: list of BINARY variables to be included (operators) :param rhsvar: BOOLEAN value, explicit True, False or bool(obj) is needed (right-hand side) @@ -2793,10 +2794,10 @@ cdef class Model: return pyCons - def addConsCardinality(self, consvars, cardval, indvars=None, weights=None, name="CardinalityCons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsCardinality(self, list[Variable] consvars, int cardval, list[Varible] indvars=None, list[SCIP_Real] weights=None, str name="CardinalityCons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add a cardinality constraint that allows at most 'cardval' many nonzero variables. :param consvars: list of variables to be included @@ -2845,10 +2846,10 @@ cdef class Model: return pyCons - def addConsIndicator(self, cons, binvar=None, activeone=True, name="IndicatorCons", - initial=True, separate=True, enforce=True, check=True, - propagate=True, local=False, dynamic=False, - removable=False, stickingatnode=False): + def addConsIndicator(self, cons: Union[Constraint, ExprCons], Variable binvar=None, SCIP_Bool activeone=True, str name="IndicatorCons", + SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, + SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, + SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Add an indicator constraint for the linear inequality 'cons'. The 'binvar' argument models the redundancy of the linear constraint. A solution for which @@ -2929,7 +2930,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddCons(self._scip, cons.scip_cons)) Py_INCREF(cons) - def addVarSOS1(self, Constraint cons, Variable var, weight): + def addVarSOS1(self, Constraint cons, Variable var, SCIP_Real weight): """Add variable to SOS1 constraint. :param Constraint cons: SOS1 constraint @@ -2948,7 +2949,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPappendVarSOS1(self._scip, cons.scip_cons, var.scip_var)) - def addVarSOS2(self, Constraint cons, Variable var, weight): + def addVarSOS2(self, Constraint cons, Variable var, SCIP_Real weight): """Add variable to SOS2 constraint. :param Constraint cons: SOS2 constraint @@ -2967,7 +2968,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPappendVarSOS2(self._scip, cons.scip_cons, var.scip_var)) - def setInitial(self, Constraint cons, newInit): + def setInitial(self, Constraint cons, SCIP_Bool newInit): """Set "initial" flag of a constraint. Keyword arguments: @@ -2976,7 +2977,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetConsInitial(self._scip, cons.scip_cons, newInit)) - def setRemovable(self, Constraint cons, newRem): + def setRemovable(self, Constraint cons, SCIP_Bool newRem): """Set "removable" flag of a constraint. Keyword arguments: @@ -2985,7 +2986,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetConsRemovable(self._scip, cons.scip_cons, newRem)) - def setEnforced(self, Constraint cons, newEnf): + def setEnforced(self, Constraint cons, SCIP_Bool newEnf): """Set "enforced" flag of a constraint. Keyword arguments: @@ -2994,7 +2995,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetConsEnforced(self._scip, cons.scip_cons, newEnf)) - def setCheck(self, Constraint cons, newCheck): + def setCheck(self, Constraint cons, SCIP_Bool newCheck): """Set "check" flag of a constraint. Keyword arguments: @@ -3006,7 +3007,7 @@ cdef class Model: def chgRhs(self, Constraint cons, rhs): """Change right hand side value of a constraint. - :param Constraint cons: linear or quadratic constraint + :param cons Constraint: linear or quadratic constraint :param rhs: new right hand side (set to None for +infinity) """ @@ -3069,7 +3070,7 @@ cdef class Model: else: raise Warning("method cannot be called for constraints of type " + constype) - def chgCoefLinear(self, Constraint cons, Variable var, value): + def chgCoefLinear(self, Constraint cons, Variable var, SCIP_Real value): """Changes coefficient of variable in linear constraint; deletes the variable if coefficient is zero; adds variable if not yet contained in the constraint This method may only be called during problem creation stage for an original constraint and variable. @@ -3094,7 +3095,7 @@ cdef class Model: PY_SCIP_CALL( SCIPdelCoefLinear(self._scip, cons.scip_cons, var.scip_var) ) - def addCoefLinear(self, Constraint cons, Variable var, value): + def addCoefLinear(self, Constraint cons, Variable var, SCIP_Real value): """Adds coefficient to linear constraint (if it is not zero) :param Constraint cons: linear constraint @@ -3133,7 +3134,7 @@ cdef class Model: return activity - def getSlack(self, Constraint cons, Solution sol = None, side = None): + def getSlack(self, Constraint cons, Solution sol = None, str side = None): """Retrieve slack of given constraint. Can only be called after solving is completed. @@ -3311,7 +3312,7 @@ cdef class Model: return (bilinterms, quadterms, linterms) - def setRelaxSolVal(self, Variable var, val): + def setRelaxSolVal(self, Variable var, SCIP_Real val): """sets the value of the given variable in the global relaxation solution""" PY_SCIP_CALL(SCIPsetRelaxSolVal(self._scip, NULL, var.scip_var, val)) @@ -3434,7 +3435,7 @@ cdef class Model: raise Warning("no reduced cost available for variable " + var.name) return redcost - def getDualSolVal(self, Constraint cons, boundconstraint=False): + def getDualSolVal(self, Constraint cons, SCIP_Bool boundconstraint=False): """Retrieve returns dual solution value of a constraint. :param Constraint cons: constraint to get the dual solution value of @@ -3594,7 +3595,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPaddBendersSubproblem(self._scip, benders._benders, (subproblem)._scip)) - def setBendersSubproblemIsConvex(self, Benders benders, probnumber, isconvex = True): + def setBendersSubproblemIsConvex(self, Benders benders, int probnumber, SCIP_Bool isconvex = True): """sets a flag indicating whether the subproblem is convex Keyword arguments: @@ -3604,7 +3605,7 @@ cdef class Model: """ SCIPbendersSetSubproblemIsConvex(benders._benders, probnumber, isconvex) - def setupBendersSubproblem(self, probnumber, Benders benders = None, Solution solution = None, checktype = PY_SCIP_BENDERSENFOTYPE.LP): + def setupBendersSubproblem(self, int probnumber, Benders benders = None, Solution solution = None, checktype = PY_SCIP_BENDERSENFOTYPE.LP): """ sets up the Benders' subproblem given the master problem solution Keyword arguments: @@ -3631,7 +3632,7 @@ cdef class Model: PY_SCIP_CALL(retcode) - def solveBendersSubproblem(self, probnumber, solvecip, Benders benders = None, Solution solution = None): + def solveBendersSubproblem(self, int probnumber, SCIP_Bool solvecip, Benders benders = None, Solution solution = None): """ solves the Benders' decomposition subproblem. The convex relaxation will be solved unless the parameter solvecip is set to True. @@ -3662,7 +3663,7 @@ cdef class Model: return infeasible, objective - def getBendersSubproblem(self, probnumber, Benders benders = None): + def getBendersSubproblem(self, int probnumber, Benders benders = None): """Returns a Model object that wraps around the SCIP instance of the subproblem. NOTE: This Model object is just a place holder and SCIP instance will not be freed when the object is destroyed. @@ -3682,7 +3683,7 @@ cdef class Model: return Model.create(scip_subprob) - def getBendersVar(self, Variable var, Benders benders = None, probnumber = -1): + def getBendersVar(self, Variable var, Benders benders = None, int probnumber = -1): """Returns the variable for the subproblem or master problem depending on the input probnumber @@ -3711,7 +3712,7 @@ cdef class Model: return mappedvar - def getBendersAuxiliaryVar(self, probnumber, Benders benders = None): + def getBendersAuxiliaryVar(self, int probnumber, Benders benders = None): """Returns the auxiliary variable that is associated with the input problem number Keyword arguments: @@ -3731,7 +3732,7 @@ cdef class Model: return auxvar - def checkBendersSubproblemOptimality(self, Solution solution, probnumber, Benders benders = None): + def checkBendersSubproblemOptimality(self, Solution solution, int probnumber, Benders benders = None): """Returns whether the subproblem is optimal w.r.t the master problem auxiliary variables. Keyword arguments: @@ -3767,7 +3768,7 @@ cdef class Model: PY_SCIP_CALL( SCIPincludeBendersDefaultCuts(self._scip, benders._benders) ) - def includeEventhdlr(self, Eventhdlr eventhdlr, name, desc): + def includeEventhdlr(self, Eventhdlr eventhdlr, str name, str desc): """Include an event handler. Keyword arguments: @@ -3791,7 +3792,7 @@ cdef class Model: eventhdlr.name = name Py_INCREF(eventhdlr) - def includePricer(self, Pricer pricer, name, desc, priority=1, delay=True): + def includePricer(self, Pricer pricer, str name, str desc, int priority=1, SCIP_Bool delay=True): """Include a pricer. :param Pricer pricer: pricer @@ -3813,12 +3814,12 @@ cdef class Model: pricer.model = weakref.proxy(self) Py_INCREF(pricer) - def includeConshdlr(self, Conshdlr conshdlr, name, desc, sepapriority=0, - enfopriority=0, chckpriority=0, sepafreq=-1, propfreq=-1, - eagerfreq=100, maxprerounds=-1, delaysepa=False, - delayprop=False, needscons=True, - proptiming=PY_SCIP_PROPTIMING.BEFORELP, - presoltiming=PY_SCIP_PRESOLTIMING.MEDIUM): + def includeConshdlr(self, Conshdlr conshdlr, str name, str desc, int sepapriority=0, + int enfopriority=0, int chckpriority=0, int sepafreq=-1, int propfreq=-1, + int eagerfreq=100, int maxprerounds=-1, SCIP_Bool delaysepa=False, + SCIP_Bool delayprop=False, SCIP_Bool needscons=True, + SCIP_PROPTIMING proptiming=PY_SCIP_PROPTIMING.BEFORELP, + SCIP_PRESOLTIMING presoltiming=PY_SCIP_PRESOLTIMING.MEDIUM): """Include a constraint handler :param Conshdlr conshdlr: constraint handler @@ -3852,8 +3853,8 @@ cdef class Model: conshdlr.name = name Py_INCREF(conshdlr) - def createCons(self, Conshdlr conshdlr, name, initial=True, separate=True, enforce=True, check=True, propagate=True, - local=False, modifiable=False, dynamic=False, removable=False, stickingatnode=False): + def createCons(self, Conshdlr conshdlr, str name, SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, + SCIP_Bool local=False, SCIP_Bool modifiable=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): """Create a constraint of a custom constraint handler :param Conshdlr conshdlr: constraint handler @@ -3879,7 +3880,7 @@ cdef class Model: initial, separate, enforce, check, propagate, local, modifiable, dynamic, removable, stickingatnode)) return constraint - def includePresol(self, Presol presol, name, desc, priority, maxrounds, timing=SCIP_PRESOLTIMING_FAST): + def includePresol(self, Presol presol, str name, str desc, int priority, int maxrounds, SCIP_PRESOLTIMING timing=SCIP_PRESOLTIMING_FAST): """Include a presolver :param Presol presol: presolver @@ -3897,7 +3898,7 @@ cdef class Model: presol.model = weakref.proxy(self) Py_INCREF(presol) - def includeSepa(self, Sepa sepa, name, desc, priority=0, freq=10, maxbounddist=1.0, usessubscip=False, delay=False): + def includeSepa(self, Sepa sepa, str name, str desc, int priority=0, int freq=10, SCIP_Real maxbounddist=1.0, SCIP_Bool usessubscip=False, SCIP_Bool delay=False): """Include a separator :param Sepa sepa: separator @@ -3918,7 +3919,7 @@ cdef class Model: sepa.name = name Py_INCREF(sepa) - def includeReader(self, Reader reader, name, desc, ext): + def includeReader(self, Reader reader, str name, str desc, ext): """Include a reader :param Reader reader: reader @@ -3936,8 +3937,8 @@ cdef class Model: reader.name = name Py_INCREF(reader) - def includeProp(self, Prop prop, name, desc, presolpriority, presolmaxrounds, - proptiming, presoltiming=SCIP_PRESOLTIMING_FAST, priority=1, freq=1, delay=True): + def includeProp(self, Prop prop, str name, str desc, int presolpriority, int presolmaxrounds, + SCIP_PROPTIMING proptiming, SCIP_PRESOLTIMING presoltiming=SCIP_PRESOLTIMING_FAST, int priority=1, int freq=1, SCIP_Bool delay=True): """Include a propagator. :param Prop prop: propagator @@ -3964,8 +3965,8 @@ cdef class Model: prop.model = weakref.proxy(self) Py_INCREF(prop) - def includeHeur(self, Heur heur, name, desc, dispchar, priority=10000, freq=1, freqofs=0, - maxdepth=-1, timingmask=SCIP_HEURTIMING_BEFORENODE, usessubscip=False): + def includeHeur(self, Heur heur, str name, str desc, str dispchar, int priority=10000, int freq=1, int freqofs=0, + int maxdepth=-1, SCIP_HEURTIMING timingmask=SCIP_HEURTIMING_BEFORENODE, SCIP_Bool usessubscip=False): """Include a primal heuristic. :param Heur heur: heuristic @@ -3993,7 +3994,7 @@ cdef class Model: heur.name = name Py_INCREF(heur) - def includeRelax(self, Relax relax, name, desc, priority=10000, freq=1): + def includeRelax(self, Relax relax, str name, str desc, int priority=10000, int freq=1): """Include a relaxation handler. :param Relax relax: relaxation handler @@ -4012,7 +4013,7 @@ cdef class Model: Py_INCREF(relax) - def includeCutsel(self, Cutsel cutsel, name, desc, priority): + def includeCutsel(self, Cutsel cutsel, str name, str desc, int priority): """include a cut selector :param Cutsel cutsel: cut selector @@ -4030,7 +4031,7 @@ cdef class Model: cutsel.model = weakref.proxy(self) Py_INCREF(cutsel) - def includeBranchrule(self, Branchrule branchrule, name, desc, priority, maxdepth, maxbounddist): + def includeBranchrule(self, Branchrule branchrule, str name, str desc, int priority, int maxdepth, SCIP_Real maxbounddist): """Include a branching rule. :param Branchrule branchrule: branching rule @@ -4051,7 +4052,7 @@ cdef class Model: branchrule.model = weakref.proxy(self) Py_INCREF(branchrule) - def includeNodesel(self, Nodesel nodesel, name, desc, stdpriority, memsavepriority): + def includeNodesel(self, Nodesel nodesel, str name, str desc, int stdpriority, int memsavepriority): """Include a node selector. :param Nodesel nodesel: node selector @@ -4071,8 +4072,8 @@ cdef class Model: nodesel.model = weakref.proxy(self) Py_INCREF(nodesel) - def includeBenders(self, Benders benders, name, desc, priority=1, cutlp=True, cutpseudo=True, cutrelax=True, - shareaux=False): + def includeBenders(self, Benders benders, str name, str desc, int priority=1, SCIP_Bool cutlp=True, SCIP_Bool cutpseudo=True, SCIP_Bool cutrelax=True, + SCIP_Bool shareaux=False): """Include a Benders' decomposition. Keyword arguments: @@ -4101,7 +4102,7 @@ cdef class Model: benders._benders = scip_benders Py_INCREF(benders) - def includeBenderscut(self, Benders benders, Benderscut benderscut, name, desc, priority=1, islpcut=True): + def includeBenderscut(self, Benders benders, Benderscut benderscut, str name, str desc, int priority=1, SCIP_Bool islpcut=True): """ Include a Benders' decomposition cutting method Keyword arguments: @@ -4202,7 +4203,7 @@ cdef class Model: return Node.create(downchild), Node.create(eqchild), Node.create(upchild) - def branchVarVal(self, variable, value): + def branchVarVal(self, Variable variable, SCIP_Real value): """Branches on variable using a value which separates the domain of the variable. :param variable: Variable to branch on @@ -4219,7 +4220,7 @@ cdef class Model: return Node.create(downchild), Node.create(eqchild), Node.create(upchild) - def calcNodeselPriority(self, Variable variable, branchdir, targetvalue): + def calcNodeselPriority(self, Variable variable, int branchdir, SCIP_Real targetvalue): """calculates the node selection priority for moving the given variable's LP value to the given target value; this node selection priority can be given to the SCIPcreateChild() call @@ -4232,7 +4233,7 @@ cdef class Model: """ return SCIPcalcNodeselPriority(self._scip, variable.scip_var, branchdir, targetvalue) - def calcChildEstimate(self, Variable variable, targetvalue): + def calcChildEstimate(self, Variable variable, SCIP_Real targetvalue): """Calculates an estimate for the objective of the best feasible solution contained in the subtree after applying the given branching; this estimate can be given to the SCIPcreateChild() call @@ -4244,7 +4245,7 @@ cdef class Model: """ return SCIPcalcChildEstimate(self._scip, variable.scip_var, targetvalue) - def createChild(self, nodeselprio, estimate): + def createChild(self, SCIP_Real nodeselprio, SCIP_Real estimate): """Create a child node of the focus node. :param nodeselprio: float, node selection priority of new node @@ -4268,15 +4269,15 @@ cdef class Model: """Quits probing and resets bounds and constraints to the focus node's environment""" PY_SCIP_CALL(SCIPendDive(self._scip)) - def chgVarObjDive(self, Variable var, newobj): + def chgVarObjDive(self, Variable var, SCIP_Real newobj): """changes (column) variable's objective value in current dive""" PY_SCIP_CALL(SCIPchgVarObjDive(self._scip, var.scip_var, newobj)) - def chgVarLbDive(self, Variable var, newbound): + def chgVarLbDive(self, Variable var, SCIP_Real newbound): """changes variable's current lb in current dive""" PY_SCIP_CALL(SCIPchgVarLbDive(self._scip, var.scip_var, newbound)) - def chgVarUbDive(self, Variable var, newbound): + def chgVarUbDive(self, Variable var, SCIP_Real newbound): """changes variable's current ub in current dive""" PY_SCIP_CALL(SCIPchgVarUbDive(self._scip, var.scip_var, newbound)) @@ -4288,13 +4289,13 @@ cdef class Model: """returns variable's current ub in current dive""" return SCIPgetVarUbDive(self._scip, var.scip_var) - def chgRowLhsDive(self, Row row, newlhs): + def chgRowLhsDive(self, Row row, SCIP_Real newlhs): """changes row lhs in current dive, change will be undone after diving ends, for permanent changes use SCIPchgRowLhs() """ PY_SCIP_CALL(SCIPchgRowLhsDive(self._scip, row.scip_row, newlhs)) - def chgRowRhsDive(self, Row row, newrhs): + def chgRowRhsDive(self, Row row, SCIP_Real newrhs): """changes row rhs in current dive, change will be undone after diving ends, for permanent changes use SCIPchgRowLhs() """ @@ -4304,7 +4305,7 @@ cdef class Model: """adds a row to the LP in current dive""" PY_SCIP_CALL(SCIPaddRowDive(self._scip, row.scip_row)) - def solveDiveLP(self, itlim = -1): + def solveDiveLP(self, int itlim = -1): """solves the LP of the current dive no separation or pricing is applied no separation or pricing is applied :param itlim: maximal number of LP iterations to perform (Default value = -1, that is, no limit) @@ -4339,7 +4340,7 @@ cdef class Model: """ PY_SCIP_CALL( SCIPnewProbingNode(self._scip) ) - def backtrackProbing(self, probingdepth): + def backtrackProbing(self, int probingdepth): """undoes all changes to the problem applied in probing up to the given probing depth :param probingdepth: probing depth of the node in the probing path that should be reactivated """ @@ -4349,11 +4350,11 @@ cdef class Model: """returns the current probing depth""" return SCIPgetProbingDepth(self._scip) - def chgVarObjProbing(self, Variable var, newobj): + def chgVarObjProbing(self, Variable var, SCIP_Real newobj): """changes (column) variable's objective value during probing mode""" PY_SCIP_CALL( SCIPchgVarObjProbing(self._scip, var.scip_var, newobj) ) - def chgVarLbProbing(self, Variable var, lb): + def chgVarLbProbing(self, Variable var, SCIP_Real lb): """changes the variable lower bound during probing mode :param Variable var: variable to change bound of @@ -4363,7 +4364,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbProbing(self._scip, var.scip_var, lb)) - def chgVarUbProbing(self, Variable var, ub): + def chgVarUbProbing(self, Variable var, SCIP_Real ub): """changes the variable upper bound during probing mode :param Variable var: variable to change bound of @@ -4373,7 +4374,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUbProbing(self._scip, var.scip_var, ub)) - def fixVarProbing(self, Variable var, fixedval): + def fixVarProbing(self, Variable var, SCIP_Real fixedval): """Fixes a variable at the current probing node.""" PY_SCIP_CALL( SCIPfixVarProbing(self._scip, var.scip_var, fixedval) ) @@ -4385,7 +4386,7 @@ cdef class Model: """returns whether we are in probing mode; probing mode is activated via startProbing() and stopped via endProbing()""" return SCIPinProbing(self._scip) - def solveProbingLP(self, itlim = -1): + def solveProbingLP(self, int itlim = -1): """solves the LP at the current probing node (cannot be applied at preprocessing stage) no separation or pricing is applied :param itlim: maximal number of LP iterations to perform (Default value = -1, that is, no limit) @@ -4411,7 +4412,7 @@ cdef class Model: PY_SCIP_CALL( SCIPapplyCutsProbing(self._scip, &cutoff) ) return cutoff - def propagateProbing(self, maxproprounds): + def propagateProbing(self, int maxproprounds): """applies domain propagation on the probing sub problem, that was changed after SCIPstartProbing() was called; the propagated domains of the variables can be accessed with the usual bound accessing calls SCIPvarGetLbLocal() and SCIPvarGetUbLocal(); the propagation is only valid locally, i.e. the local bounds as well as the changed @@ -4437,7 +4438,7 @@ cdef class Model: # Solution functions - def writeLP(self, filename="LP.lp"): + def writeLP(self, str filename="LP.lp"): """writes current LP to a file :param filename: file name (Default value = "LP.lp") """ @@ -4484,7 +4485,7 @@ cdef class Model: partialsolution = Solution.create(self._scip, _sol) return partialsolution - def printBestSol(self, write_zeros=False): + def printBestSol(self, SCIP_Bool write_zeros=False): """Prints the best feasible primal solution.""" user_locale = locale.getlocale() locale.setlocale(locale.LC_ALL, "C") @@ -4493,7 +4494,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def printSol(self, Solution solution=None, write_zeros=False): + def printSol(self, Solution solution=None, SCIP_Bool write_zeros=False): """Print the given primal solution. Keyword arguments: @@ -4511,7 +4512,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def writeBestSol(self, filename="origprob.sol", write_zeros=False): + def writeBestSol(self, str filename="origprob.sol", SCIP_Bool write_zeros=False): """Write the best feasible primal solution to a file. Keyword arguments: @@ -4530,7 +4531,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def writeBestTransSol(self, filename="transprob.sol", write_zeros=False): + def writeBestTransSol(self, str filename="transprob.sol", SCIP_Bool write_zeros=False): """Write the best feasible primal solution for the transformed problem to a file. Keyword arguments: @@ -4548,7 +4549,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def writeSol(self, Solution solution, filename="origprob.sol", write_zeros=False): + def writeSol(self, Solution solution, str filename="origprob.sol", SCIP_Bool write_zeros=False): """Write the given primal solution to a file. Keyword arguments: @@ -4567,7 +4568,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def writeTransSol(self, Solution solution, filename="transprob.sol", write_zeros=False): + def writeTransSol(self, Solution solution, str filename="transprob.sol", SCIP_Bool write_zeros=False): """Write the given transformed primal solution to a file. Keyword arguments: @@ -4587,8 +4588,8 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) # perhaps this should not be included as it implements duplicated functionality - # (as does it's namesake in SCIP) - def readSol(self, filename): + # (as does its namesake in SCIP) + def readSol(self, str filename): """Reads a given solution file, problem has to be transformed in advance. Keyword arguments: @@ -4597,7 +4598,7 @@ cdef class Model: absfile = str_conversion(abspath(filename)) PY_SCIP_CALL(SCIPreadSol(self._scip, absfile)) - def readSolFile(self, filename): + def readSolFile(self, str filename): """Reads a given solution file. Solution is created but not added to storage/the model. @@ -4620,7 +4621,7 @@ cdef class Model: return solution - def setSolVal(self, Solution solution, Variable var, val): + def setSolVal(self, Solution solution, Variable var, SCIP_Real val): """Set a variable in a solution. :param Solution solution: solution to be modified @@ -4634,7 +4635,7 @@ cdef class Model: assert _sol != NULL, "Cannot set value to a freed solution." PY_SCIP_CALL(SCIPsetSolVal(self._scip, _sol, var.scip_var, val)) - def trySol(self, Solution solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, free=True): + def trySol(self, Solution solution, SCIP_Bool printreason=True, SCIP_Bool completely=False, SCIP_Bool checkbounds=True, SCIP_Bool checkintegrality=True, SCIP_Bool checklprows=True, SCIP_Bool free=True): """Check given primal solution for feasibility and try to add it to the storage. :param Solution solution: solution to store @@ -4653,7 +4654,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtrySol(self._scip, solution.sol, printreason, completely, checkbounds, checkintegrality, checklprows, &stored)) return stored - def checkSol(self, Solution solution, printreason=True, completely=False, checkbounds=True, checkintegrality=True, checklprows=True, original=False): + def checkSol(self, Solution solution, SCIP_Bool printreason=True, SCIP_Bool completely=False, SCIP_Bool checkbounds=True, SCIP_Bool checkintegrality=True, SCIP_Bool checklprows=True, SCIP_Bool original=False): """Check given primal solution for feasibility without adding it to the storage. :param Solution solution: solution to store @@ -4672,7 +4673,7 @@ cdef class Model: PY_SCIP_CALL(SCIPcheckSol(self._scip, solution.sol, printreason, completely, checkbounds, checkintegrality, checklprows, &feasible)) return feasible - def addSol(self, Solution solution, free=True): + def addSol(self, Solution solution, SCIP_Bool free=True): """Try to add a solution to the storage. :param Solution solution: solution to store @@ -4732,7 +4733,7 @@ cdef class Model: self._bestSol = Solution.create(self._scip, SCIPgetBestSol(self._scip)) return self._bestSol - def getSolObjVal(self, Solution sol, original=True): + def getSolObjVal(self, Solution sol, SCIP_Bool original=True): """Retrieve the objective value of the solution. :param Solution sol: solution @@ -4756,7 +4757,7 @@ cdef class Model: """ return SCIPgetSolTime(self._scip, sol.sol) - def getObjVal(self, original=True): + def getObjVal(self, SCIP_Bool original=True): """Retrieve the objective value of value of best solution. Can only be called after solving is completed. @@ -4987,7 +4988,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def writeStatistics(self, filename="origprob.stats"): + def writeStatistics(self, str filename="origprob.stats"): """Write statistics to a file. Keyword arguments: @@ -5010,7 +5011,7 @@ cdef class Model: # Verbosity Methods - def hideOutput(self, quiet = True): + def hideOutput(self, SCIP_Bool quiet = True): """Hide the output. :param quiet: hide output? (Default value = True) @@ -5029,7 +5030,7 @@ cdef class Model: PY_SCIP_CALL(SCIPsetMessagehdlr(self._scip, myMessageHandler)) SCIPmessageSetErrorPrinting(relayErrorMessage, NULL) - def setLogfile(self, path): + def setLogfile(self, str path): """sets the log file name for the currently installed message handler :param path: name of log file, or None (no log) """ @@ -5041,7 +5042,7 @@ cdef class Model: # Parameter Methods - def setBoolParam(self, name, value): + def setBoolParam(self, str name, SCIP_Bool value): """Set a boolean-valued parameter. :param name: name of parameter @@ -5051,7 +5052,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetBoolParam(self._scip, n, value)) - def setIntParam(self, name, value): + def setIntParam(self, str name, int value): """Set an int-valued parameter. :param name: name of parameter @@ -5061,7 +5062,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetIntParam(self._scip, n, value)) - def setLongintParam(self, name, value): + def setLongintParam(self, str name, long int value): """Set a long-valued parameter. :param name: name of parameter @@ -5071,7 +5072,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetLongintParam(self._scip, n, value)) - def setRealParam(self, name, value): + def setRealParam(self, str name, SCIP_Real value): """Set a real-valued parameter. :param name: name of parameter @@ -5081,7 +5082,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetRealParam(self._scip, n, value)) - def setCharParam(self, name, value): + def setCharParam(self, str name, char value): """Set a char-valued parameter. :param name: name of parameter @@ -5091,7 +5092,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetCharParam(self._scip, n, ord(value))) - def setStringParam(self, name, value): + def setStringParam(self, str name, str value): """Set a string-valued parameter. :param name: name of parameter @@ -5102,7 +5103,7 @@ cdef class Model: v = str_conversion(value) PY_SCIP_CALL(SCIPsetStringParam(self._scip, n, v)) - def setParam(self, name, value): + def setParam(self, str name, value): """Set a parameter with value in int, bool, real, long, char or str. :param name: name of parameter @@ -5133,7 +5134,7 @@ cdef class Model: PY_SCIP_CALL(SCIPsetStringParam(self._scip, n, v)) - def getParam(self, name): + def getParam(self, str name): """Get the value of a parameter of type int, bool, real, long, char or str. @@ -5175,7 +5176,7 @@ cdef class Model: result[name] = self.getParam(name) return result - def setParams(self, params): + def setParams(self, params: Union[dict, list[str]]): """Sets multiple parameters at once. :param params: dict mapping parameter names to their values. @@ -5183,7 +5184,7 @@ cdef class Model: for name, value in params.items(): self.setParam(name, value) - def readParams(self, file): + def readParams(self, str file): """Read an external parameter file. :param file: file to be read @@ -5192,7 +5193,7 @@ cdef class Model: absfile = str_conversion(abspath(file)) PY_SCIP_CALL(SCIPreadParams(self._scip, absfile)) - def writeParams(self, filename='param.set', comments = True, onlychanged = True): + def writeParams(self, str filename='param.set', SCIP_Bool comments = True, SCIP_Bool onlychanged = True): """Write parameter settings to an external file. :param filename: file to be written (Default value = 'param.set') @@ -5210,7 +5211,7 @@ cdef class Model: locale.setlocale(locale.LC_ALL, user_locale) - def resetParam(self, name): + def resetParam(self, str name): """Reset parameter setting to its default value :param name: parameter to reset @@ -5223,7 +5224,7 @@ cdef class Model: """Reset parameter settings to their default values""" PY_SCIP_CALL(SCIPresetParams(self._scip)) - def setEmphasis(self, paraemphasis, quiet = True): + def setEmphasis(self, paraemphasis, SCIP_Bool quiet = True): """Set emphasis settings :param paraemphasis: emphasis to set @@ -5232,7 +5233,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetEmphasis(self._scip, paraemphasis, quiet)) - def readProblem(self, filename, extension = None): + def readProblem(self, str filename, extension = None): """Read a problem instance from an external file. :param filename: problem file name @@ -5274,7 +5275,7 @@ cdef class Model: """Frees all solution process data and prepares for reoptimization""" PY_SCIP_CALL(SCIPfreeReoptSolve(self._scip)) - def chgReoptObjective(self, coeffs, sense = 'minimize'): + def chgReoptObjective(self, Expr coeffs, str sense = 'minimize'): """Establish the objective function as a linear expression. :param coeffs: the coefficients @@ -5321,7 +5322,7 @@ cdef class Model: free(_coeffs) - def chgVarBranchPriority(self, Variable var, priority): + def chgVarBranchPriority(self, Variable var, int priority): """Sets the branch priority of the variable. Variables with higher branch priority are always preferred to variables with lower priority in selection of branching variable. diff --git a/tests/test_gomory.py b/tests/test_gomory.py index b95537045..6e319b17e 100644 --- a/tests/test_gomory.py +++ b/tests/test_gomory.py @@ -330,7 +330,7 @@ def test_CKS(): # add variables x1 = s.addVar("x1", vtype='I') x2 = s.addVar("x2", vtype='I') - y = s.addVar("y", obj=-1, vtype='C') + y = s.addVar("y", obj=-1, vtype='C') # add constraint s.addCons(-x1 + y <= 0) From 68e82637c3d49452e629ae1a3c80002f3e8ded92 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 15:11:14 +0100 Subject: [PATCH 5/9] type callbacks --- src/pyscipopt/branchrule.pxi | 6 +++--- src/pyscipopt/conshdlr.pxi | 40 ++++++++++++++++++------------------ src/pyscipopt/cutsel.pxi | 2 +- src/pyscipopt/expr.pxi | 18 ++++++++-------- src/pyscipopt/heuristic.pxi | 2 +- src/pyscipopt/lp.pxi | 16 +++++++-------- src/pyscipopt/nodesel.pxi | 2 +- src/pyscipopt/presol.pxi | 2 +- src/pyscipopt/propagator.pxi | 4 ++-- src/pyscipopt/reader.pxi | 4 ++-- src/pyscipopt/sepa.pxi | 2 +- 11 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/pyscipopt/branchrule.pxi b/src/pyscipopt/branchrule.pxi index 2d3411d2c..8be329dec 100644 --- a/src/pyscipopt/branchrule.pxi +++ b/src/pyscipopt/branchrule.pxi @@ -23,16 +23,16 @@ cdef class Branchrule: '''informs branching rule that the branch and bound process data is being freed''' pass - def branchexeclp(self, allowaddcons): + def branchexeclp(self, SCIP_Bool allowaddcons): '''executes branching rule for fractional LP solution''' raise NotImplementedError("branchexeclp() is a fundamental callback and should be implemented in the derived " "class") - def branchexecext(self, allowaddcons): + def branchexecext(self, SCIP_Bool allowaddcons): '''executes branching rule for external branching candidates ''' raise NotImplementedError("branchexecext() is a fundamental callback and should be implemented in the derived class") - def branchexecps(self, allowaddcons): + def branchexecps(self, SCIP_Bool allowaddcons): '''executes branching rule for not completely fixed pseudo solution ''' # this method needs to be implemented by the user raise NotImplementedError("branchexecps() is a fundamental callback and should be implemented in the derived class") diff --git a/src/pyscipopt/conshdlr.pxi b/src/pyscipopt/conshdlr.pxi index 4b8e15947..8ef4ff81f 100644 --- a/src/pyscipopt/conshdlr.pxi +++ b/src/pyscipopt/conshdlr.pxi @@ -29,7 +29,7 @@ cdef class Conshdlr: '''informs constraint handler that the branch and bound process is being started ''' pass - def consexitsol(self, constraints, restart): + def consexitsol(self, constraints, SCIP_Bool restart): '''informs constraint handler that the branch and bound process data is being freed ''' pass @@ -45,41 +45,41 @@ cdef class Conshdlr: '''calls LP initialization method of constraint handler to separate all initial active constraints ''' return {} - def conssepalp(self, constraints, nusefulconss): + def conssepalp(self, constraints, int nusefulconss): '''calls separator method of constraint handler to separate LP solution ''' return {} - def conssepasol(self, constraints, nusefulconss, solution): + def conssepasol(self, constraints, int nusefulconss, Solution solution): '''calls separator method of constraint handler to separate given primal solution ''' return {} - def consenfolp(self, constraints, nusefulconss, solinfeasible): + def consenfolp(self, constraints, int nusefulconss, SCIP_Bool solinfeasible): '''calls enforcing method of constraint handler for LP solution for all constraints added''' print("python error in consenfolp: this method needs to be implemented") return {} - def consenforelax(self, solution, constraints, nusefulconss, solinfeasible): + def consenforelax(self, Solution solution, constraints, int nusefulconss, solinfeasible): '''calls enforcing method of constraint handler for a relaxation solution for all constraints added''' print("python error in consenforelax: this method needs to be implemented") return {} - def consenfops(self, constraints, nusefulconss, solinfeasible, objinfeasible): + def consenfops(self, constraints, int nusefulconss, SCIP_Bool solinfeasible, SCIP_Bool objinfeasible): '''calls enforcing method of constraint handler for pseudo solution for all constraints added''' print("python error in consenfops: this method needs to be implemented") return {} - def conscheck(self, constraints, solution, checkintegrality, checklprows, printreason, completely): + def conscheck(self, constraints, Solution solution, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_Bool completely): '''calls feasibility check method of constraint handler ''' print("python error in conscheck: this method needs to be implemented") return {} - def consprop(self, constraints, nusefulconss, nmarkedconss, proptiming): + def consprop(self, constraints, int nusefulconss, int nmarkedconss, SCIP_PROPTIMING proptiming): '''calls propagation method of constraint handler ''' return {} - def conspresol(self, constraints, nrounds, presoltiming, - nnewfixedvars, nnewaggrvars, nnewchgvartypes, nnewchgbds, nnewholes, - nnewdelconss, nnewaddconss, nnewupgdconss, nnewchgcoefs, nnewchgsides, result_dict): + def conspresol(self, constraints, int nrounds, SCIP_PRESOLTIMING presoltiming, + int nnewfixedvars, int nnewaggrvars, int nnewchgvartypes, int nnewchgbds, int nnewholes, + int nnewdelconss, int nnewaddconss, int nnewupgdconss, int nnewchgcoefs, int nnewchgsides, result_dict): '''calls presolving method of constraint handler ''' return result_dict @@ -87,32 +87,32 @@ cdef class Conshdlr: '''sets propagation conflict resolving method of constraint handler ''' return {} - def conslock(self, constraint, locktype, nlockspos, nlocksneg): + def conslock(self, constraint: Union[Constraint, ExprCons], int locktype, int nlockspos, int nlocksneg): '''variable rounding lock method of constraint handler''' print("python error in conslock: this method needs to be implemented") return {} - def consactive(self, constraint): + def consactive(self, constraint: Union[Constraint, ExprCons]): '''sets activation notification method of constraint handler ''' pass - def consdeactive(self, constraint): + def consdeactive(self, constraint: Union[Constraint, ExprCons]): '''sets deactivation notification method of constraint handler ''' pass - def consenable(self, constraint): + def consenable(self, constraint: Union[Constraint, ExprCons]): '''sets enabling notification method of constraint handler ''' pass - def consdisable(self, constraint): + def consdisable(self, constraint: Union[Constraint, ExprCons]): '''sets disabling notification method of constraint handler ''' pass - def consdelvars(self, constraints): + def consdelvars(self, constraint: Union[Constraint, ExprCons]): '''calls variable deletion method of constraint handler''' pass - def consprint(self, constraint): + def consprint(self, constraint: Union[Constraint, ExprCons]): '''sets constraint display method of constraint handler ''' pass @@ -124,11 +124,11 @@ cdef class Conshdlr: '''sets constraint parsing method of constraint handler ''' pass - def consgetvars(self, constraint): + def consgetvars(self, constraint: Union[Constraint, ExprCons]): '''sets constraint variable getter method of constraint handler''' pass - def consgetnvars(self, constraint): + def consgetnvars(self, constraint: Union[Constraint, ExprCons]): '''sets constraint variable number getter method of constraint handler ''' return {} diff --git a/src/pyscipopt/cutsel.pxi b/src/pyscipopt/cutsel.pxi index adb5f06af..59a3953fb 100644 --- a/src/pyscipopt/cutsel.pxi +++ b/src/pyscipopt/cutsel.pxi @@ -23,7 +23,7 @@ cdef class Cutsel: '''executed before the branch-and-bound process is freed''' pass - def cutselselect(self, cuts, forcedcuts, root, maxnselectedcuts): + def cutselselect(self, list[SCIP_ROW] cuts, int forcedcuts, SCIP_Bool root, int maxnselectedcuts): '''first method called in each iteration in the main solving loop. ''' # this method needs to be implemented by the user return {} diff --git a/src/pyscipopt/expr.pxi b/src/pyscipopt/expr.pxi index b3a80d7e4..87dddd155 100644 --- a/src/pyscipopt/expr.pxi +++ b/src/pyscipopt/expr.pxi @@ -54,7 +54,7 @@ def _is_number(e): return False -def _expr_richcmp(self, other, op): +def _expr_richcmp(self, other, int op): if op == 1: # <= if isinstance(other, Expr) or isinstance(other, GenExpr): return (self - other) <= 0.0 @@ -90,7 +90,7 @@ class Term: self.ptrtuple = tuple(v.ptr() for v in self.vartuple) self.hashval = sum(self.ptrtuple) - def __getitem__(self, idx): + def __getitem__(self, int idx): return self.vartuple[idx] def __hash__(self): @@ -144,7 +144,7 @@ def buildGenExprObj(expr): #See also the @ref ExprDetails "description" in the expr.pxi. cdef class Expr: - def __init__(self, terms=None): + def __init__(self, terms: Union[None, dict[Variable,SCIP_Real]] = None): '''terms is a dict of variables to coefficients. CONST is used as key for the constant term.''' @@ -621,23 +621,23 @@ cdef class Constant(GenExpr): def __repr__(self): return str(self.number) -def exp(expr): +def exp(expr: Union[Expr, GenExpr]): """returns expression with exp-function""" return UnaryExpr(Operator.exp, buildGenExprObj(expr)) -def log(expr): +def log(expr: Union[Expr, GenExpr]): """returns expression with log-function""" return UnaryExpr(Operator.log, buildGenExprObj(expr)) -def sqrt(expr): +def sqrt(expr: Union[Expr, GenExpr]): """returns expression with sqrt-function""" return UnaryExpr(Operator.sqrt, buildGenExprObj(expr)) -def sin(expr): +def sin(expr: Union[Expr, GenExpr]): """returns expression with sin-function""" return UnaryExpr(Operator.sin, buildGenExprObj(expr)) -def cos(expr): +def cos(expr: Union[Expr, GenExpr]): """returns expression with cos-function""" return UnaryExpr(Operator.cos, buildGenExprObj(expr)) -def expr_to_nodes(expr): +def expr_to_nodes(expr: Union[Expr, GenExpr]): '''transforms tree to an array of nodes. each node is an operator and the position of the children of that operator (i.e. the other nodes) in the array''' assert isinstance(expr, GenExpr) diff --git a/src/pyscipopt/heuristic.pxi b/src/pyscipopt/heuristic.pxi index 930315630..dda5d755d 100644 --- a/src/pyscipopt/heuristic.pxi +++ b/src/pyscipopt/heuristic.pxi @@ -24,7 +24,7 @@ cdef class Heur: '''informs primal heuristic that the branch and bound process data is being freed''' pass - def heurexec(self, heurtiming, nodeinfeasible): + def heurexec(self, SCIP_HEURTIMING heurtiming, SCIP_Bool nodeinfeasible): '''should the heuristic the executed at the given depth, frequency, timing,...''' print("python error in heurexec: this method needs to be implemented") return {} diff --git a/src/pyscipopt/lp.pxi b/src/pyscipopt/lp.pxi index 0729bf40a..a388c8be1 100644 --- a/src/pyscipopt/lp.pxi +++ b/src/pyscipopt/lp.pxi @@ -4,7 +4,7 @@ cdef class LP: cdef SCIP_LPI* lpi cdef readonly str name - def __init__(self, name="LP", sense="minimize"): + def __init__(self, str name="LP", str sense="minimize"): """ Keyword arguments: name -- the name of the problem (default 'LP') @@ -46,7 +46,7 @@ cdef class LP: """ return SCIPlpiInfinity(self.lpi) - def isInfinity(self, val): + def isInfinity(self, SCIP_Real val): """Checks if a given value is equal to the infinity value of the LP. Keyword arguments: @@ -54,7 +54,7 @@ cdef class LP: """ return SCIPlpiIsInfinity(self.lpi, val) - def addCol(self, entries, obj = 0.0, lb = 0.0, ub = None): + def addCol(self, entries, SCIP_Real obj = 0.0, lb: Union[SCIP_Real, None] = 0.0, ub: Union[SCIP_Real, None] = None): """Adds a single column to the LP. Keyword arguments: @@ -220,7 +220,7 @@ cdef class LP: free(c_lhss) free(c_rhss) - def delRows(self, firstrow, lastrow): + def delRows(self, int firstrow, int lastrow): """Deletes a range of rows from the LP. Keyword arguments: @@ -229,7 +229,7 @@ cdef class LP: """ PY_SCIP_CALL(SCIPlpiDelRows(self.lpi, firstrow, lastrow)) - def getBounds(self, firstcol = 0, lastcol = None): + def getBounds(self, int firstcol = 0, lastcol: Union[int, None] = None): """Returns all lower and upper bounds for a range of columns. Keyword arguments: @@ -259,7 +259,7 @@ cdef class LP: return lbs, ubs - def getSides(self, firstrow = 0, lastrow = None): + def getSides(self, int firstrow = 0, lastrow: Union[int, None] = None): """Returns all left- and right-hand sides for a range of rows. Keyword arguments: @@ -300,7 +300,7 @@ cdef class LP: cdef SCIP_Real c_obj = obj PY_SCIP_CALL(SCIPlpiChgObj(self.lpi, 1, &c_col, &c_obj)) - def chgCoef(self, row, col, newval): + def chgCoef(self, int row, int col, SCIP_Real newval): """Changes a single coefficient in the LP. Keyword arguments: @@ -352,7 +352,7 @@ cdef class LP: PY_SCIP_CALL(SCIPlpiGetNCols(self.lpi, &ncols)) return ncols - def solve(self, dual=True): + def solve(self, SCIP_Bool dual=True): """Solves the current LP. Keyword arguments: diff --git a/src/pyscipopt/nodesel.pxi b/src/pyscipopt/nodesel.pxi index a3e832f15..efe70517d 100644 --- a/src/pyscipopt/nodesel.pxi +++ b/src/pyscipopt/nodesel.pxi @@ -28,7 +28,7 @@ cdef class Nodesel: # this method needs to be implemented by the user return {} - def nodecomp(self, node1, node2): + def nodecomp(self, Node node1, Node node2): ''' compare two leaves of the current branching tree diff --git a/src/pyscipopt/presol.pxi b/src/pyscipopt/presol.pxi index 13bd9a623..667235ab2 100644 --- a/src/pyscipopt/presol.pxi +++ b/src/pyscipopt/presol.pxi @@ -23,7 +23,7 @@ cdef class Presol: '''informs presolver that the presolving process is finished''' pass - def presolexec(self, nrounds, presoltiming): + def presolexec(self, int nrounds, SCIP_PRESOLTIMING presoltiming): '''executes presolver''' print("python error in presolexec: this method needs to be implemented") return {} diff --git a/src/pyscipopt/propagator.pxi b/src/pyscipopt/propagator.pxi index 4508efe78..79f96cf7b 100644 --- a/src/pyscipopt/propagator.pxi +++ b/src/pyscipopt/propagator.pxi @@ -31,11 +31,11 @@ cdef class Prop: '''informs propagator that the presolving process is finished''' pass - def proppresol(self, nrounds, presoltiming, result_dict): + def proppresol(self, int nrounds, SCIP_PRESOLTIMING presoltiming, dict result_dict): '''executes presolving method of propagator''' pass - def propexec(self, proptiming): + def propexec(self, SCIP_PROPTIMING proptiming): '''calls execution method of propagator''' print("python error in propexec: this method needs to be implemented") return {} diff --git a/src/pyscipopt/reader.pxi b/src/pyscipopt/reader.pxi index 09e937c56..446637bf1 100644 --- a/src/pyscipopt/reader.pxi +++ b/src/pyscipopt/reader.pxi @@ -12,8 +12,8 @@ cdef class Reader: '''calls read method of reader''' return {} - def readerwrite(self, file, name, transformed, objsense, objscale, objoffset, binvars, intvars, - implvars, contvars, fixedvars, startnvars, conss, maxnconss, startnconss, genericnames): + def readerwrite(self, file, str name, SCIP_Bool transformed, int objsense, SCIP_Real objscale, SCIP_Real objoffset, list[Variable] binvars, list[Variable] intvars, + list[Variable] implvars, list[Variable] contvars, list[Variable] fixedvars, int startnvars, conss: list[Union[Constraint, ExprCons]], int maxnconss, int startnconss, SCIP_Bool genericnames): '''calls write method of reader''' return {} diff --git a/src/pyscipopt/sepa.pxi b/src/pyscipopt/sepa.pxi index 94355a7d2..8b76d9b2d 100644 --- a/src/pyscipopt/sepa.pxi +++ b/src/pyscipopt/sepa.pxi @@ -28,7 +28,7 @@ cdef class Sepa: '''calls LP separation method of separator''' return {} - def sepaexecsol(self, solution): + def sepaexecsol(self, Solution solution): '''calls primal solution separation method of separator''' return {} From 1bfb40158091e0b4647bb8665c8aabbe0d4a6c5c Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 16:11:52 +0100 Subject: [PATCH 6/9] some fixes --- src/pyscipopt/scip.pxi | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 9a1d2e215..bd4ead83f 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2707,7 +2707,7 @@ cdef class Model: """ return SCIPgetObjlimit(self._scip) - def setObjective(self, coeffs, str sense = 'minimize', SCIP_Bool clear = True): + def setObjective(self, expr: Union[Expr, SCIP_Real], str sense = 'minimize', SCIP_Bool clear = True): """ Establish the objective function as a linear expression. @@ -5424,7 +5424,7 @@ cdef class Model: return pyCons - def addConsIndicator(self, cons: Union[Constraint, ExprCons], Variable binvar=None, SCIP_Bool activeone=True, str name="IndicatorCons", + def addConsIndicator(self, cons: Union[Constraint, ExprCons], Variable binvar=None, SCIP_Bool activeone=True, str name="", SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): @@ -9145,7 +9145,7 @@ cdef class Model: locale.setlocale(locale.LC_NUMERIC, user_locale) - def writeParams(self, str filename='param.set', SCIP_Bool comments = True, SCIP_Bool onlychanged = True): + def writeParams(self, str filename='param.set', SCIP_Bool comments = True, SCIP_Bool onlychanged = True, SCIP_Bool verbose = True): """ Write parameter settings to an external file. @@ -9627,7 +9627,6 @@ cdef class Model: cdef SCIP_VAR* var cdef SCIP_Real lb, ub, solval cdef SCIP_BASESTAT basis_status - cdef int i for i in range(ncols): col_i = SCIPcolGetLPPos(cols[i]) var = SCIPcolGetVar(cols[i]) @@ -9722,7 +9721,6 @@ cdef class Model: cdef int nnzrs = 0 cdef SCIP_Real lhs, rhs, cst - cdef int i for i in range(nrows): # lhs <= activity + cst <= rhs From ead336570b2a2e500b5653685d3f15d8449ca8ff Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Thu, 16 Jan 2025 16:27:37 +0100 Subject: [PATCH 7/9] Removed PY from PY_SCIP_EVENTTYPE, etc in docstrings --- src/pyscipopt/scip.pxi | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index bd4ead83f..0dd6bc3a4 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2906,7 +2906,7 @@ cdef class Model: Parameters ---------- heurname : string, name of the heuristic - heurtiming : PY_SCIP_HEURTIMING + heurtiming : SCIP_HEURTIMING positions in the node solving loop where heuristic should be executed """ cdef SCIP_HEUR* _heur @@ -2926,7 +2926,7 @@ cdef class Model: Returns ------- - PY_SCIP_HEURTIMING + SCIP_HEURTIMING positions in the node solving loop where heuristic should be executed """ cdef SCIP_HEUR* _heur @@ -6551,7 +6551,7 @@ cdef class Model: the Benders' decomposition to which the subproblem belongs to solution : Solution or None, optional the master problem solution that is used for the set up, if None, then the LP solution is used - checktype : PY_SCIP_BENDERSENFOTYPE + checktype : SCIP_BENDERSENFOTYPE the type of solution check that prompted the solving of the Benders' subproblems, either PY_SCIP_BENDERSENFOTYPE: LP, RELAX, PSEUDO or CHECK. Default is LP. @@ -6867,10 +6867,10 @@ cdef class Model: should propagation method be delayed, if other propagators found reductions? (Default value = False) needscons : bool, optional should the constraint handler be skipped, if no constraints are available? (Default value = True) - proptiming : PY_SCIP_PROPTIMING + proptiming : SCIP_PROPTIMING positions in the node solving loop where propagation method of constraint handlers should be executed (Default value = SCIP_PROPTIMING.BEFORELP) - presoltiming : PY_SCIP_PRESOLTIMING + presoltiming : SCIP_PRESOLTIMING timing mask of the constraint handler's presolving method (Default value = SCIP_PRESOLTIMING.MEDIUM) """ @@ -7029,7 +7029,7 @@ cdef class Model: priority of the presolver (>= 0: before, < 0: after constraint handlers) maxrounds : int maximal number of presolving rounds the presolver participates in (-1: no limit) - timing : PY_SCIP_PRESOLTIMING, optional + timing : SCIP_PRESOLTIMING, optional timing mask of presolver (Default value = SCIP_PRESOLTIMING_FAST) """ @@ -7128,7 +7128,7 @@ cdef class Model: maximal number of presolving rounds the propagator participates in (-1: no limit) proptiming : SCIP_PROPTIMING positions in the node solving loop where propagation method of constraint handlers should be executed - presoltiming : PY_SCIP_PRESOLTIMING, optional + presoltiming : SCIP_PRESOLTIMING, optional timing mask of the constraint handler's presolving method (Default value = SCIP_PRESOLTIMING_FAST) priority : int, optional priority of the propagator (Default value = 1) @@ -7173,7 +7173,7 @@ cdef class Model: frequency offset for calling heuristic (Default value = 0) maxdepth : int, optional maximal depth level to call heuristic at (Default value = -1) - timingmask : PY_SCIP_HEURTIMING, optional + timingmask : SCIP_HEURTIMING, optional positions in the node solving loop where heuristic should be executed (Default value = SCIP_HEURTIMING_BEFORENODE) usessubscip : bool, optional @@ -7510,7 +7510,7 @@ cdef class Model: return Node.create(downchild), Node.create(eqchild), Node.create(upchild) - def calcNodeselPriority(self, Variable variable, int branchdir, SCIP_Real targetvalue): + def calcNodeselPriority(self, Variable variable, SCIP_BRANCHDIR branchdir, SCIP_Real targetvalue): """ calculates the node selection priority for moving the given variable's LP value to the given target value; @@ -7520,7 +7520,7 @@ cdef class Model: ---------- variable : Variable variable on which the branching is applied - branchdir : PY_SCIP_BRANCHDIR + branchdir : SCIP_BRANCHDIR type of branching that was performed targetvalue : float new value of the variable in the child node @@ -8731,7 +8731,7 @@ cdef class Model: Parameters ---------- - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -8751,7 +8751,7 @@ cdef class Model: Parameters ---------- - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -8772,7 +8772,7 @@ cdef class Model: Parameters ---------- var : Variable - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -8791,7 +8791,7 @@ cdef class Model: Parameters ---------- var : Variable - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -8810,7 +8810,7 @@ cdef class Model: Parameters ---------- row : Row - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -8829,7 +8829,7 @@ cdef class Model: Parameters ---------- row : Row - eventtype : PY_SCIP_EVENTTYPE + eventtype : SCIP_EVENTTYPE eventhdlr : Eventhdlr """ @@ -9190,13 +9190,13 @@ cdef class Model: """Reset parameter settings to their default values.""" PY_SCIP_CALL(SCIPresetParams(self._scip)) - def setEmphasis(self, paraemphasis, SCIP_Bool quiet = True): + def setEmphasis(self, SCIP_PARAMEMPHASIS paraemphasis, SCIP_Bool quiet = True): """ Set emphasis settings Parameters ---------- - paraemphasis : PY_SCIP_PARAMEMPHASIS + paraemphasis : SCIP_PARAMEMPHASIS emphasis to set quiet : bool, optional hide output? (Default value = True) From 79c1eefa38a1d06721507406c87c32ccfa1b1bb5 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Fri, 17 Jan 2025 10:42:38 +0100 Subject: [PATCH 8/9] fix some of the comments --- src/pyscipopt/conshdlr.pxi | 2 +- src/pyscipopt/cutsel.pxi | 2 +- tests/test_gomory.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pyscipopt/conshdlr.pxi b/src/pyscipopt/conshdlr.pxi index 8ef4ff81f..8e48040b9 100644 --- a/src/pyscipopt/conshdlr.pxi +++ b/src/pyscipopt/conshdlr.pxi @@ -169,8 +169,8 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil: PyConshdlr = getPyConshdlr(conshdlr) - cdef int i cdef constraints = [] + cdef int i for i in range(nconss): constraints.append(getPyCons(conss[i])) PyConshdlr.consinit(constraints) diff --git a/src/pyscipopt/cutsel.pxi b/src/pyscipopt/cutsel.pxi index 59a3953fb..6ed5871fe 100644 --- a/src/pyscipopt/cutsel.pxi +++ b/src/pyscipopt/cutsel.pxi @@ -74,9 +74,9 @@ cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cu int* nselectedcuts, SCIP_RESULT* result) noexcept with gil: cdef SCIP_CUTSELDATA* cutseldata cdef SCIP_ROW* scip_row + cdef int i cutseldata = SCIPcutselGetData(cutsel) PyCutsel = cutseldata - cdef int i # translate cuts to python pycuts = [Row.create(cuts[i]) for i in range(ncuts)] diff --git a/tests/test_gomory.py b/tests/test_gomory.py index 6e319b17e..b95537045 100644 --- a/tests/test_gomory.py +++ b/tests/test_gomory.py @@ -330,7 +330,7 @@ def test_CKS(): # add variables x1 = s.addVar("x1", vtype='I') x2 = s.addVar("x2", vtype='I') - y = s.addVar("y", obj=-1, vtype='C') + y = s.addVar("y", obj=-1, vtype='C') # add constraint s.addCons(-x1 + y <= 0) From 941b4720b0264cf2207c5313cf60758001a01117 Mon Sep 17 00:00:00 2001 From: Joao-Dionisio Date: Sat, 18 Jan 2025 16:24:22 +0100 Subject: [PATCH 9/9] bugs for dominik --- src/pyscipopt/lp.pxi | 4 +- src/pyscipopt/scip.pxi | 194 ++++++++++++++++++++--------------------- 2 files changed, 99 insertions(+), 99 deletions(-) diff --git a/src/pyscipopt/lp.pxi b/src/pyscipopt/lp.pxi index a388c8be1..45fc2d171 100644 --- a/src/pyscipopt/lp.pxi +++ b/src/pyscipopt/lp.pxi @@ -46,7 +46,7 @@ cdef class LP: """ return SCIPlpiInfinity(self.lpi) - def isInfinity(self, SCIP_Real val): + def isInfinity(self, float val): """Checks if a given value is equal to the infinity value of the LP. Keyword arguments: @@ -54,7 +54,7 @@ cdef class LP: """ return SCIPlpiIsInfinity(self.lpi, val) - def addCol(self, entries, SCIP_Real obj = 0.0, lb: Union[SCIP_Real, None] = 0.0, ub: Union[SCIP_Real, None] = None): + def addCol(self, entries, float obj = 0.0, lb: Union[float, None] = 0.0, ub: Union[float, None] = None): """Adds a single column to the LP. Keyword arguments: diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 0dd6bc3a4..6b41476c4 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -2376,88 +2376,88 @@ cdef class Model: """ return SCIPfeastol(self._scip) - def feasFrac(self, SCIP_Real value): + def feasFrac(self, float value): """ Returns fractional part of value, i.e. x - floor(x) in feasible tolerance: x - floor(x+feastol). Parameters ---------- - value : float + value : float Returns ------- - float + float """ return SCIPfeasFrac(self._scip, value) - def frac(self, SCIP_Real value): + def frac(self, float value): """ Returns fractional part of value, i.e. x - floor(x) in epsilon tolerance: x - floor(x+eps). Parameters ---------- - value : float + value : float Returns ------- - float + float """ return SCIPfrac(self._scip, value) - def feasFloor(self, SCIP_Real value): + def feasFloor(self, float value): """ Rounds value + feasibility tolerance down to the next integer. Parameters ---------- - value : float + value : float Returns ------- - float + float """ return SCIPfeasFloor(self._scip, value) - def feasCeil(self, SCIP_Real value): + def feasCeil(self, float value): """ Rounds value - feasibility tolerance up to the next integer. Parameters ---------- - value : float + value : float Returns ------- - float + float """ return SCIPfeasCeil(self._scip, value) - def feasRound(self, SCIP_Real value): + def feasRound(self, float value): """ Rounds value to the nearest integer in feasibility tolerance. Parameters ---------- - value : float + value : float Returns ------- - float + float """ return SCIPfeasRound(self._scip, value) - def isZero(self, SCIP_Real value): + def isZero(self, float value): """ Returns whether abs(value) < eps. Parameters ---------- - value : float + value : float Returns ------- @@ -2466,13 +2466,13 @@ cdef class Model: """ return SCIPisZero(self._scip, value) - def isFeasZero(self, SCIP_Real value): + def isFeasZero(self, float value): """ Returns whether abs(value) < feastol. Parameters ---------- - value : float + value : float Returns ------- @@ -2481,13 +2481,13 @@ cdef class Model: """ return SCIPisFeasZero(self._scip, value) - def isInfinity(self, SCIP_Real value): + def isInfinity(self, float value): """ Returns whether value is SCIP's infinity. Parameters ---------- - value : float + value : float Returns ------- @@ -2496,13 +2496,13 @@ cdef class Model: """ return SCIPisInfinity(self._scip, value) - def isFeasNegative(self, SCIP_Real value): + def isFeasNegative(self, float value): """ Returns whether value < -feastol. Parameters ---------- - value : float + value : float Returns ------- @@ -2511,13 +2511,13 @@ cdef class Model: """ return SCIPisFeasNegative(self._scip, value) - def isFeasIntegral(self, SCIP_Real value): + def isFeasIntegral(self, float value): """ Returns whether value is integral within the LP feasibility bounds. Parameters ---------- - value : float + value : float Returns ------- @@ -2526,14 +2526,14 @@ cdef class Model: """ return SCIPisFeasIntegral(self._scip, value) - def isEQ(self, SCIP_Real val1, SCIP_Real val2): + def isEQ(self, float val1, float val2): """ Checks, if values are in range of epsilon. Parameters ---------- - val1 : float - val2 : float + val1 : float + val2 : float Returns ------- @@ -2542,14 +2542,14 @@ cdef class Model: """ return SCIPisEQ(self._scip, val1, val2) - def isFeasEQ(self, SCIP_Real val1, SCIP_Real val2): + def isFeasEQ(self, float val1, float val2): """ Checks, if relative difference of values is in range of feasibility tolerance. Parameters ---------- - val1 : float - val2 : float + val1 : float + val2 : float Returns ------- @@ -2558,14 +2558,14 @@ cdef class Model: """ return SCIPisFeasEQ(self._scip, val1, val2) - def isLE(self, SCIP_Real val1, SCIP_Real val2): + def isLE(self, float val1, float val2): """ Returns whether val1 <= val2 + eps. Parameters ---------- - val1 : float - val2 : float + val1 : float + val2 : float Returns ------- @@ -2574,14 +2574,14 @@ cdef class Model: """ return SCIPisLE(self._scip, val1, val2) - def isLT(self, SCIP_Real val1, SCIP_Real val2): + def isLT(self, float val1, float val2): """ Returns whether val1 < val2 - eps. Parameters ---------- - val1 : float - val2 : float + val1 : float + val2 : float Returns ------- @@ -2590,14 +2590,14 @@ cdef class Model: """ return SCIPisLT(self._scip, val1, val2) - def isGE(self, SCIP_Real val1, SCIP_Real val2): + def isGE(self, float val1, float val2): """ Returns whether val1 >= val2 - eps. Parameters ---------- - val1 : float - val2 : float + val1 : float + val2 : float Returns ------- @@ -2606,13 +2606,13 @@ cdef class Model: """ return SCIPisGE(self._scip, val1, val2) - def isGT(self, SCIP_Real val1, SCIP_Real val2): + def isGT(self, float val1, float val2): """ Returns whether val1 > val2 + eps. Parameters ---------- - val1 : float + val1 : float val2 : foat Returns @@ -2633,7 +2633,7 @@ cdef class Model: Returns ------- - float + SCIP_Real """ cdef SCIP_LPI* lpi @@ -2683,7 +2683,7 @@ cdef class Model: """Set the objective sense to maximization.""" PY_SCIP_CALL(SCIPsetObjsense(self._scip, SCIP_OBJSENSE_MAXIMIZE)) - def setObjlimit(self, SCIP_Real objlimit): + def setObjlimit(self, float objlimit): """ Set a limit on the objective function. Only solutions with objective value better than this limit are accepted. @@ -2707,7 +2707,7 @@ cdef class Model: """ return SCIPgetObjlimit(self._scip) - def setObjective(self, expr: Union[Expr, SCIP_Real], str sense = 'minimize', SCIP_Bool clear = True): + def setObjective(self, expr: Union[Expr, float], str sense = 'minimize', SCIP_Bool clear = True): """ Establish the objective function as a linear expression. @@ -2780,7 +2780,7 @@ cdef class Model: objective.normalize() return objective - def addObjoffset(self, SCIP_Real offset, SCIP_Bool solutions = False): + def addObjoffset(self, float offset, SCIP_Bool solutions = False): """ Add constant offset to objective. @@ -3024,7 +3024,7 @@ cdef class Model: # Variable Functions - def addVar(self, str name='', str vtype='C', lb: Union[SCIP_Real, None]=0.0, ub: Union[SCIP_Real, None]=None, SCIP_Real obj=0.0, SCIP_Bool pricedVar=False, SCIP_Real pricedVarScore=1.0): + def addVar(self, str name='', str vtype='C', lb: Union[float, None]=0.0, ub: Union[float, None]=None, float obj=0.0, SCIP_Bool pricedVar=False, float pricedVarScore=1.0): """ Create a new variable. Default variable is non-negative and continuous. @@ -3131,7 +3131,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPaddVarLocks(self._scip, var.scip_var, nlocksdown, nlocksup)) - def fixVar(self, Variable var, SCIP_Real val): + def fixVar(self, Variable var, float val): """ Fixes the variable var to the value val if possible. @@ -3176,7 +3176,7 @@ cdef class Model: PY_SCIP_CALL(SCIPdelVar(self._scip, var.scip_var, &deleted)) return deleted - def tightenVarLb(self, Variable var, lb: Union[SCIP_Real, None], SCIP_Bool force=False): + def tightenVarLb(self, Variable var, lb: Union[float, None], SCIP_Bool force=False): """ Tighten the lower bound in preprocessing or current node, if the bound is tighter. @@ -3202,7 +3202,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarLb(self._scip, var.scip_var, lb, force, &infeasible, &tightened)) return infeasible, tightened - def tightenVarUb(self, Variable var, ub: Union[SCIP_Real, None], SCIP_Bool force=False): + def tightenVarUb(self, Variable var, ub: Union[float, None], SCIP_Bool force=False): """ Tighten the upper bound in preprocessing or current node, if the bound is tighter. @@ -3228,7 +3228,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarUb(self._scip, var.scip_var, ub, force, &infeasible, &tightened)) return infeasible, tightened - def tightenVarUbGlobal(self, Variable var, ub: Union[SCIP_Real, None], SCIP_Bool force=False): + def tightenVarUbGlobal(self, Variable var, ub: Union[float, None], SCIP_Bool force=False): """ Tighten the global upper bound, if the bound is tighter. @@ -3254,7 +3254,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarUbGlobal(self._scip, var.scip_var, ub, force, &infeasible, &tightened)) return infeasible, tightened - def tightenVarLbGlobal(self, Variable var, lb: Union[SCIP_Real, None], SCIP_Bool force=False): + def tightenVarLbGlobal(self, Variable var, lb: Union[float, None], SCIP_Bool force=False): """Tighten the global lower bound, if the bound is tighter. Parameters @@ -3279,7 +3279,7 @@ cdef class Model: PY_SCIP_CALL(SCIPtightenVarLbGlobal(self._scip, var.scip_var, lb, force, &infeasible, &tightened)) return infeasible, tightened - def chgVarLb(self, Variable var, lb: Union[SCIP_Real, None]): + def chgVarLb(self, Variable var, lb: Union[float, None]): """ Changes the lower bound of the specified variable. @@ -3295,7 +3295,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLb(self._scip, var.scip_var, lb)) - def chgVarUb(self, Variable var, ub: Union[SCIP_Real, None]): + def chgVarUb(self, Variable var, ub: Union[float, None]): """Changes the upper bound of the specified variable. Parameters @@ -3310,7 +3310,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUb(self._scip, var.scip_var, ub)) - def chgVarLbGlobal(self, Variable var, lb: Union[SCIP_Real, None]): + def chgVarLbGlobal(self, Variable var, lb: Union[float, None]): """Changes the global lower bound of the specified variable. Parameters @@ -3325,7 +3325,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbGlobal(self._scip, var.scip_var, lb)) - def chgVarUbGlobal(self, Variable var, ub: Union[SCIP_Real, None]): + def chgVarUbGlobal(self, Variable var, ub: Union[float, None]): """Changes the global upper bound of the specified variable. Parameters @@ -3340,7 +3340,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUbGlobal(self._scip, var.scip_var, ub)) - def chgVarLbNode(self, Node node, Variable var, lb: Union[SCIP_Real, None]): + def chgVarLbNode(self, Node node, Variable var, lb: Union[float, None]): """Changes the lower bound of the specified variable at the given node. Parameters @@ -3358,7 +3358,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbNode(self._scip, node.scip_node, var.scip_var, lb)) - def chgVarUbNode(self, Node node, Variable var, ub: Union[SCIP_Real, None]): + def chgVarUbNode(self, Node node, Variable var, ub: Union[float, None]): """Changes the upper bound of the specified variable at the given node. Parameters @@ -3527,7 +3527,7 @@ cdef class Model: var_dict[var.name] = self.getVal(var) return var_dict - def updateNodeLowerbound(self, Node node, lb: Union[SCIP_Real, None]): + def updateNodeLowerbound(self, Node node, lb: Union[float, None]): """ If given value is larger than the node's lower bound (in transformed problem), sets the node's lower bound to the new value. @@ -3866,7 +3866,7 @@ cdef class Model: #TODO: documentation!! # LP Row Methods - def createEmptyRowSepa(self, Sepa sepa, str name="row", lhs: Union[SCIP_Real, None] = 0.0, rhs: Union[SCIP_Real, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): + def createEmptyRowSepa(self, Sepa sepa, str name="row", lhs: Union[float, None] = 0.0, rhs: Union[float, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): """ Creates and captures an LP row without any coefficients from a separator. @@ -3900,7 +3900,7 @@ cdef class Model: PyRow = Row.create(row) return PyRow - def createEmptyRowUnspec(self, str name="row", lhs: Union[SCIP_Real, None] = 0.0, rhs: Union[SCIP_Real, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): + def createEmptyRowUnspec(self, str name="row", lhs: Union[float, None] = 0.0, rhs: Union[float, None] = None, SCIP_Bool local = True, SCIP_Bool modifiable = False, SCIP_Bool removable = True): """ Creates and captures an LP row without any coefficients from an unspecified source. @@ -4001,7 +4001,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPflushRowExtensions(self._scip, row.scip_row)) - def addVarToRow(self, Row row not None, Variable var not None, SCIP_Real value): + def addVarToRow(self, Row row not None, Variable var not None, float value): """ Resolves variable to columns and adds them with the coefficient to the row. @@ -4686,10 +4686,10 @@ cdef class Model: return pycons - def addConss(self, conss: list[Union[Constraint, ExprCons]], name: Union[list[str],str] = '', initial: Union[list[SCIP_Bool], SCIP_Bool] = True, separate: Union[list[SCIP_Bool], SCIP_Bool] = True, - enforce: Union[list[SCIP_Bool], SCIP_Bool] = True, check: Union[list[SCIP_Bool], SCIP_Bool] = True, propagate: Union[list[SCIP_Bool], SCIP_Bool] = True, local: Union[list[SCIP_Bool], SCIP_Bool] = False, - modifiable: Union[list[SCIP_Bool], SCIP_Bool] = False, dynamic: Union[list[SCIP_Bool], SCIP_Bool] = False, removable: Union[list[SCIP_Bool], SCIP_Bool] = False, - stickingatnode: Union[list[SCIP_Bool], SCIP_Bool] = False): + def addConss(self, conss: list[Union[Constraint, ExprCons]], name: Union[list[str],str] = '', initial: Union[list[bool], bool] = True, separate: Union[list[bool], bool] = True, + enforce: Union[list[bool], bool] = True, check: Union[list[bool], bool] = True, propagate: Union[list[bool], bool] = True, local: Union[list[bool], bool] = False, + modifiable: Union[list[bool], bool] = False, dynamic: Union[list[bool], bool] = False, removable: Union[list[bool], bool] = False, + stickingatnode: Union[list[bool], bool] = False): """Adds multiple linear or quadratic constraints. Each of the constraints is added to the model using Model.addCons(). @@ -4942,7 +4942,7 @@ cdef class Model: """ return PY_SCIP_CALL(SCIPprintCons(self._scip, constraint.scip_cons, NULL)) - def addExprNonlinear(self, Constraint cons, expr: Union[Expr, GenExpr], SCIP_Real coef): + def addExprNonlinear(self, Constraint cons, expr: Union[Expr, GenExpr], float coef): """ Add coef*expr to nonlinear constraint. @@ -4965,7 +4965,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddExprNonlinear(self._scip, cons.scip_cons, scip_expr, coef)) self.delCons(temp_cons) - def addConsCoeff(self, Constraint cons, Variable var, SCIP_Real coeff): + def addConsCoeff(self, Constraint cons, Variable var, float coeff): """ Add coefficient to the linear constraint (if non-zero). @@ -5019,7 +5019,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddConsLocal(self._scip, cons.scip_cons, NULL)) Py_INCREF(cons) - def addConsSOS1(self, list[Variable] vars, list[SCIP_Real] weights=None, str name="SOS1cons", + def addConsSOS1(self, list[Variable] vars, list[float] weights=None, str name="SOS1cons", SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): @@ -5095,7 +5095,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddCons(self._scip, scip_cons)) return Constraint.create(scip_cons) - def addConsSOS2(self, list[Variable] vars, list[SCIP_Real] weights=None, str name="SOS2cons", + def addConsSOS2(self, list[Variable] vars, list[float] weights=None, str name="SOS2cons", SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): @@ -5346,7 +5346,7 @@ cdef class Model: return pyCons - def addConsCardinality(self, list[Variable] consvars, int cardval, list[Varible] indvars=None, list[SCIP_Real] weights=None, str name="CardinalityCons", + def addConsCardinality(self, list[Variable] consvars, int cardval, list[Varible] indvars=None, list[float] weights=None, str name="CardinalityCons", SCIP_Bool initial=True, SCIP_Bool separate=True, SCIP_Bool enforce=True, SCIP_Bool check=True, SCIP_Bool propagate=True, SCIP_Bool local=False, SCIP_Bool dynamic=False, SCIP_Bool removable=False, SCIP_Bool stickingatnode=False): @@ -5545,7 +5545,7 @@ cdef class Model: PY_SCIP_CALL(SCIPaddCons(self._scip, cons.scip_cons)) Py_INCREF(cons) - def addVarSOS1(self, Constraint cons, Variable var, SCIP_Real weight): + def addVarSOS1(self, Constraint cons, Variable var, float weight): """ Add variable to SOS1 constraint. @@ -5575,7 +5575,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPappendVarSOS1(self._scip, cons.scip_cons, var.scip_var)) - def addVarSOS2(self, Constraint cons, Variable var, SCIP_Real weight): + def addVarSOS2(self, Constraint cons, Variable var, float weight): """ Add variable to SOS2 constraint. @@ -5653,7 +5653,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPsetConsChecked(self._scip, cons.scip_cons, newCheck)) - def chgRhs(self, Constraint cons, rhs: Union[SCIP_Real, None]): + def chgRhs(self, Constraint cons, rhs: Union[float, None]): """ Change right-hand side value of a constraint. @@ -5677,7 +5677,7 @@ cdef class Model: else: raise Warning("method cannot be called for constraints of type " + constype) - def chgLhs(self, Constraint cons, lhs: Union[SCIP_Real, None]): + def chgLhs(self, Constraint cons, lhs: Union[float, None]): """ Change left-hand side value of a constraint. @@ -5745,7 +5745,7 @@ cdef class Model: else: raise Warning("method cannot be called for constraints of type " + constype) - def chgCoefLinear(self, Constraint cons, Variable var, SCIP_Real value): + def chgCoefLinear(self, Constraint cons, Variable var, float value): """ Changes coefficient of variable in linear constraint; deletes the variable if coefficient is zero; adds variable if not yet contained in the constraint @@ -5781,7 +5781,7 @@ cdef class Model: PY_SCIP_CALL( SCIPdelCoefLinear(self._scip, cons.scip_cons, var.scip_var) ) - def addCoefLinear(self, Constraint cons, Variable var, SCIP_Real value): + def addCoefLinear(self, Constraint cons, Variable var, float value): """ Adds coefficient to linear constraint (if it is not zero) @@ -6102,7 +6102,7 @@ cdef class Model: return (bilinterms, quadterms, linterms) - def setRelaxSolVal(self, Variable var, SCIP_Real val): + def setRelaxSolVal(self, Variable var, float val): """ Sets the value of the given variable in the global relaxation solution. @@ -6888,7 +6888,7 @@ cdef class Model: conshdlr.name = name Py_INCREF(conshdlr) - def copyLargeNeighborhoodSearch(self, list[Variable] to_fix, list[SCIP_Real] fix_vals) -> Model: + def copyLargeNeighborhoodSearch(self, list[Variable] to_fix, list[float] fix_vals) -> Model: """ Creates a configured copy of the transformed problem and applies provided fixings intended for LNS heuristics. @@ -7040,7 +7040,7 @@ cdef class Model: presol.model = weakref.proxy(self) Py_INCREF(presol) - def includeSepa(self, Sepa sepa, str name, str desc, int priority=0, int freq=10, SCIP_Real maxbounddist=1.0, SCIP_Bool usessubscip=False, SCIP_Bool delay=False): + def includeSepa(self, Sepa sepa, str name, str desc, int priority=0, int freq=10, float maxbounddist=1.0, SCIP_Bool usessubscip=False, SCIP_Bool delay=False): """ Include a separator @@ -7246,7 +7246,7 @@ cdef class Model: cutsel.model = weakref.proxy(self) Py_INCREF(cutsel) - def includeBranchrule(self, Branchrule branchrule, str name, str desc, int priority, int maxdepth, SCIP_Real maxbounddist): + def includeBranchrule(self, Branchrule branchrule, str name, str desc, int priority, int maxdepth, float maxbounddist): """ Include a branching rule. @@ -7481,7 +7481,7 @@ cdef class Model: return Node.create(downchild), Node.create(eqchild), Node.create(upchild) - def branchVarVal(self, Variable variable, SCIP_Real value): + def branchVarVal(self, Variable variable, float value): """ Branches on variable using a value which separates the domain of the variable. @@ -7510,7 +7510,7 @@ cdef class Model: return Node.create(downchild), Node.create(eqchild), Node.create(upchild) - def calcNodeselPriority(self, Variable variable, SCIP_BRANCHDIR branchdir, SCIP_Real targetvalue): + def calcNodeselPriority(self, Variable variable, SCIP_BRANCHDIR branchdir, float targetvalue): """ calculates the node selection priority for moving the given variable's LP value to the given target value; @@ -7533,7 +7533,7 @@ cdef class Model: """ return SCIPcalcNodeselPriority(self._scip, variable.scip_var, branchdir, targetvalue) - def calcChildEstimate(self, Variable variable, SCIP_Real targetvalue): + def calcChildEstimate(self, Variable variable, float targetvalue): """ Calculates an estimate for the objective of the best feasible solution contained in the subtree after applying the given branching; @@ -7554,7 +7554,7 @@ cdef class Model: """ return SCIPcalcChildEstimate(self._scip, variable.scip_var, targetvalue) - def createChild(self, SCIP_Real nodeselprio, SCIP_Real estimate): + def createChild(self, float nodeselprio, float estimate): """ Create a child node of the focus node. @@ -7587,7 +7587,7 @@ cdef class Model: """Quits probing and resets bounds and constraints to the focus node's environment.""" PY_SCIP_CALL(SCIPendDive(self._scip)) - def chgVarObjDive(self, Variable var, SCIP_Real newobj): + def chgVarObjDive(self, Variable var, float newobj): """ Changes (column) variable's objective value in current dive. @@ -7599,7 +7599,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPchgVarObjDive(self._scip, var.scip_var, newobj)) - def chgVarLbDive(self, Variable var, SCIP_Real newbound): + def chgVarLbDive(self, Variable var, float newbound): """ Changes variable's current lb in current dive. @@ -7611,7 +7611,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPchgVarLbDive(self._scip, var.scip_var, newbound)) - def chgVarUbDive(self, Variable var, SCIP_Real newbound): + def chgVarUbDive(self, Variable var, float newbound): """ Changes variable's current ub in current dive. @@ -7653,7 +7653,7 @@ cdef class Model: """ return SCIPgetVarUbDive(self._scip, var.scip_var) - def chgRowLhsDive(self, Row row, SCIP_Real newlhs): + def chgRowLhsDive(self, Row row, float newlhs): """ Changes row lhs in current dive, change will be undone after diving ends, for permanent changes use SCIPchgRowLhs(). @@ -7666,7 +7666,7 @@ cdef class Model: """ PY_SCIP_CALL(SCIPchgRowLhsDive(self._scip, row.scip_row, newlhs)) - def chgRowRhsDive(self, Row row, SCIP_Real newrhs): + def chgRowRhsDive(self, Row row, float newrhs): """ Changes row rhs in current dive, change will be undone after diving ends. For permanent changes use SCIPchgRowRhs(). @@ -7757,7 +7757,7 @@ cdef class Model: """Returns the current probing depth.""" return SCIPgetProbingDepth(self._scip) - def chgVarObjProbing(self, Variable var, SCIP_Real newobj): + def chgVarObjProbing(self, Variable var, float newobj): """Changes (column) variable's objective value during probing mode.""" PY_SCIP_CALL( SCIPchgVarObjProbing(self._scip, var.scip_var, newobj) ) @@ -7777,7 +7777,7 @@ cdef class Model: lb = -SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarLbProbing(self._scip, var.scip_var, lb)) - def chgVarUbProbing(self, Variable var, SCIP_Real ub): + def chgVarUbProbing(self, Variable var, float ub): """ Changes the variable upper bound during probing mode. @@ -7793,7 +7793,7 @@ cdef class Model: ub = SCIPinfinity(self._scip) PY_SCIP_CALL(SCIPchgVarUbProbing(self._scip, var.scip_var, ub)) - def fixVarProbing(self, Variable var, SCIP_Real fixedval): + def fixVarProbing(self, Variable var, float fixedval): """ Fixes a variable at the current probing node. @@ -8201,7 +8201,7 @@ cdef class Model: return solution - def setSolVal(self, Solution solution, Variable var, SCIP_Real val): + def setSolVal(self, Solution solution, Variable var, float val): """ Set a variable in a solution. @@ -8972,7 +8972,7 @@ cdef class Model: n = str_conversion(name) PY_SCIP_CALL(SCIPsetLongintParam(self._scip, n, value)) - def setRealParam(self, str name, SCIP_Real value): + def setRealParam(self, str name, float value): """ Set a real-valued parameter. @@ -9477,7 +9477,7 @@ cdef class Model: return down, up, downvalid, upvalid, downinf, upinf, downconflict, upconflict, lperror - def updateVarPseudocost(self, Variable var, SCIP_Real valdelta, SCIP_Real objdelta, SCIP_Real weight): + def updateVarPseudocost(self, Variable var, float valdelta, float objdelta, float weight): """ Updates the pseudo costs of the given variable and the global pseudo costs after a change of valdelta in the variable's solution value and resulting change of objdelta in the LP's objective value. @@ -9499,7 +9499,7 @@ cdef class Model: PY_SCIP_CALL(SCIPupdateVarPseudocost(self._scip, var.scip_var, valdelta, objdelta, weight)) - def getBranchScoreMultiple(self, Variable var, list[SCIP_Real] gains): + def getBranchScoreMultiple(self, Variable var, list[float] gains): """ Calculates the branching score out of the gain predictions for a branching with arbitrarily many children.