diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b7155cc..72dd6bf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ ## Unreleased ### Added -- Added cdef to loop variables for slight speedup - Added wrappers for setting and getting heuristic timing - Added transformed option to getVarDict, updated test - Added categorical data example diff --git a/src/pyscipopt/benders.pxi b/src/pyscipopt/benders.pxi index ea042435..66a394d8 100644 --- a/src/pyscipopt/benders.pxi +++ b/src/pyscipopt/benders.pxi @@ -175,7 +175,6 @@ cdef SCIP_RETCODE PyBendersSolvesub (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol, SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint, SCIP_Bool infeasible, SCIP_Bool* merged) noexcept with gil: - cdef int i cdef SCIP_BENDERSDATA* bendersdata bendersdata = SCIPbendersGetData(benders) PyBenders = bendersdata diff --git a/src/pyscipopt/conshdlr.pxi b/src/pyscipopt/conshdlr.pxi index 4b8e1594..20717780 100644 --- a/src/pyscipopt/conshdlr.pxi +++ b/src/pyscipopt/conshdlr.pxi @@ -169,7 +169,6 @@ 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])) @@ -179,7 +178,6 @@ 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) @@ -188,7 +186,6 @@ 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) @@ -197,7 +194,6 @@ 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) @@ -206,7 +202,6 @@ 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) @@ -215,7 +210,6 @@ 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) @@ -252,7 +246,6 @@ 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) @@ -262,7 +255,6 @@ 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) @@ -273,7 +265,6 @@ 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) @@ -285,7 +276,6 @@ 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) @@ -295,7 +285,6 @@ 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) @@ -307,7 +296,6 @@ 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) @@ -318,7 +306,6 @@ 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) @@ -330,7 +317,6 @@ 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) @@ -344,7 +330,6 @@ 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 @@ -418,7 +403,6 @@ 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 ea723962..d259fb28 100644 --- a/src/pyscipopt/cutsel.pxi +++ b/src/pyscipopt/cutsel.pxi @@ -72,7 +72,6 @@ cdef SCIP_RETCODE PyCutselExitsol (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept wit cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts, int ncuts, SCIP_ROW** forcedcuts, int nforcedcuts, SCIP_Bool root, int maxnselectedcuts, int* nselectedcuts, SCIP_RESULT* result) noexcept with gil: - cdef int i cdef SCIP_CUTSELDATA* cutseldata cdef SCIP_ROW* scip_row cutseldata = SCIPcutselGetData(cutsel) diff --git a/src/pyscipopt/lp.pxi b/src/pyscipopt/lp.pxi index 11bebc02..04f6fde3 100644 --- a/src/pyscipopt/lp.pxi +++ b/src/pyscipopt/lp.pxi @@ -63,7 +63,6 @@ cdef class LP: lb -- lower bound (default 0.0) ub -- upper bound (default infinity) """ - cdef int i nnonz = len(entries) cdef SCIP_Real* c_coefs = malloc(nnonz * sizeof(SCIP_Real)) @@ -96,8 +95,7 @@ cdef class LP: lbs -- lower bounds (default 0.0) ubs -- upper bounds (default infinity) """ - cdef int i - + ncols = len(entrieslist) nnonz = sum(len(entries) for entries in entrieslist) @@ -160,8 +158,6 @@ cdef class LP: lhs -- left-hand side of the row (default 0.0) rhs -- right-hand side of the row (default infinity) """ - cdef int i - beg = 0 nnonz = len(entries) @@ -192,8 +188,6 @@ cdef class LP: lhss -- left-hand side of the row (default 0.0) rhss -- right-hand side of the row (default infinity) """ - cdef int i - nrows = len(entrieslist) nnonz = sum(len(entries) for entries in entrieslist) @@ -238,8 +232,6 @@ 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: @@ -269,8 +261,6 @@ 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: @@ -373,8 +363,6 @@ 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)) @@ -391,8 +379,6 @@ 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)) @@ -409,8 +395,6 @@ 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() @@ -425,8 +409,6 @@ 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() @@ -447,8 +429,6 @@ 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)) @@ -463,8 +443,6 @@ 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/reader.pxi b/src/pyscipopt/reader.pxi index b8f51fff..2c45585d 100644 --- a/src/pyscipopt/reader.pxi +++ b/src/pyscipopt/reader.pxi @@ -45,7 +45,6 @@ cdef SCIP_RETCODE PyReaderWrite (SCIP* scip, SCIP_READER* reader, FILE* file, SCIP_VAR** fixedvars, int nfixedvars, int startnvars, SCIP_CONS** conss, int nconss, int maxnconss, int startnconss, SCIP_Bool genericnames, SCIP_RESULT* result) noexcept with gil: - cdef int i cdef SCIP_READERDATA* readerdata readerdata = SCIPreaderGetData(reader) cdef int fd = fileno(file) diff --git a/src/pyscipopt/scip.pxi b/src/pyscipopt/scip.pxi index 2b5ad69b..f1eea037 100644 --- a/src/pyscipopt/scip.pxi +++ b/src/pyscipopt/scip.pxi @@ -806,7 +806,6 @@ cdef class Row: list of Column """ - cdef int i cdef SCIP_COL** cols = SCIProwGetCols(self.scip_row) return [Column.create(cols[i]) for i in range(self.getNNonz())] @@ -819,7 +818,6 @@ cdef class Row: list of int """ - cdef int i cdef SCIP_Real* vals = SCIProwGetVals(self.scip_row) return [vals[i] for i in range(self.getNNonz())] @@ -905,7 +903,6 @@ 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): @@ -984,7 +981,6 @@ 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 @@ -1003,7 +999,6 @@ cdef class Solution: def __repr__(self): cdef SCIP_VAR* scip_var - cdef int i vals = {} self._checkStage("SCIPgetSolVal") @@ -1180,7 +1175,6 @@ cdef class DomainChanges: list of BoundChange """ - cdef int i nboundchgs = SCIPdomchgGetNBoundchgs(self.scip_domchg) return [BoundChange.create(SCIPdomchgGetBoundchg(self.scip_domchg, i)) for i in range(nboundchgs)] @@ -1286,7 +1280,6 @@ cdef class Node: """ cdef int addedconsssize = SCIPnodeGetNAddedConss(self.scip_node) - cdef int i if addedconsssize == 0: return [] cdef SCIP_CONS** addedconss = malloc(addedconsssize * sizeof(SCIP_CONS*)) @@ -1362,7 +1355,6 @@ cdef class Node: list of int """ - cdef int i cdef int nbranchvars = self.getNParentBranchings() if nbranchvars == 0: return None @@ -2725,8 +2717,6 @@ 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(expr, Expr): @@ -3418,7 +3408,6 @@ cdef class Model: cdef SCIP_VAR** _vars cdef SCIP_VAR* _var cdef int _nvars - cdef int i vars = [] if transformed: @@ -3644,7 +3633,6 @@ 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)) @@ -3711,7 +3699,6 @@ cdef class Model: """ 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)] @@ -3727,7 +3714,6 @@ cdef class Model: """ 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)] @@ -3766,7 +3752,6 @@ cdef class Model: """ 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)] @@ -3790,8 +3775,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)] free(coefs) @@ -3814,8 +3798,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)] free(coefs) @@ -4266,9 +4249,6 @@ cdef class Model: cdef int nvars = len(terms.items()) - cdef int i - cdef SCIP_Real coeff - vars_array = malloc(nvars * sizeof(SCIP_VAR*)) coeffs_array = malloc(nvars * sizeof(SCIP_Real)) @@ -4362,9 +4342,6 @@ cdef class Model: cdef SCIP_EXPR** monomials cdef int* idxs cdef SCIP_CONS* scip_cons - cdef int i - cdef int idx - cdef int j terms = cons.expr.terms @@ -4433,8 +4410,6 @@ cdef class Model: cdef SCIP_EXPR** scipexprs cdef SCIP_CONS* scip_cons cdef int nchildren - cdef int i - cdef int c # get arrays from python's expression tree expr = cons.expr @@ -4730,9 +4705,6 @@ cdef class Model: The created and added Constraint objects. """ - cdef int idx - cdef int i - def ensure_iterable(elem, length): if isinstance(elem, Iterable): return elem @@ -4805,8 +4777,6 @@ cdef class Model: The created disjunction constraint """ - cdef int i - def ensure_iterable(elem, length): if isinstance(elem, Iterable): return elem @@ -4908,7 +4878,6 @@ cdef class Model: list of Variable """ - cdef int i cdef SCIP_Bool success cdef int _nvars @@ -5076,7 +5045,6 @@ 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)) @@ -5137,7 +5105,6 @@ 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)) @@ -5197,7 +5164,6 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons - cdef int idx nvars = len(vars) @@ -5259,7 +5225,6 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons - cdef int idx nvars = len(vars) @@ -5321,7 +5286,6 @@ cdef class Model: """ cdef SCIP_CONS* scip_cons - cdef int idx nvars = len(vars) @@ -5391,7 +5355,6 @@ 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)) @@ -5466,8 +5429,6 @@ 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") @@ -5927,7 +5888,6 @@ cdef class Model: """ cdef SCIP_NLROW** nlrows - cdef int i nlrows = SCIPgetNLPNlRows(self._scip) return [NLRow.create(nlrows[i]) for i in range(self.getNNlRows())] @@ -6039,7 +5999,6 @@ cdef class Model: """ cdef SCIP_EXPR* expr - cdef int termidx # linear terms cdef SCIP_EXPR** _linexprs @@ -6124,8 +6083,6 @@ cdef class Model: """ cdef SCIP_CONS** _conss cdef int _nconss - cdef int i - conss = [] if transformed: @@ -6195,7 +6152,6 @@ 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': @@ -6389,7 +6345,6 @@ cdef class Model: """ cdef SCIP** subprobs cdef SCIP_BENDERS* benders - cdef int idx # checking whether subproblems is a dictionary if isinstance(subproblems, dict): @@ -6429,8 +6384,6 @@ cdef class Model: cdef SCIP_Bool _infeasible cdef int nbenders cdef int nsubproblems - cdef int i - cdef int j solvecip = True @@ -6452,8 +6405,6 @@ cdef class Model: cdef SCIP_BENDERS** _benders cdef int nbenders cdef int nsubproblems - cdef int i - cdef int j nbenders = SCIPgetNActiveBenders(self._scip) _benders = SCIPgetBenders(self._scip) @@ -6899,9 +6850,7 @@ cdef class Model: model : Model A model containing the created copy """ - cdef SCIP_Real val - cdef int i - + orig_vars = SCIPgetVars(self._scip) vars = malloc(len(to_fix) * sizeof(SCIP_VAR*)) vals = malloc(len(fix_vals) * sizeof(SCIP_Real)) @@ -6947,7 +6896,6 @@ cdef class Model: solution : Solution The corresponding solution in the main model """ - cdef int i cdef SCIP_SOL* real_sol cdef SCIP_SOL* subscip_sol @@ -7415,7 +7363,6 @@ cdef class Model: cdef int nlpcands cdef int npriolpcands cdef int nfracimplvars - cdef int i cdef SCIP_VAR** lpcands cdef SCIP_Real* lpcandssol @@ -7444,7 +7391,6 @@ cdef class Model: """ cdef int npseudocands cdef int npriopseudocands - cdef int i cdef SCIP_VAR** pseudocands @@ -8383,7 +8329,6 @@ cdef class Model: """ cdef SCIP_SOL** _sols cdef SCIP_SOL* _sol - cdef int i _sols = SCIPgetSols(self._scip) nsols = SCIPgetNSols(self._scip) sols = [] @@ -8570,7 +8515,6 @@ cdef class Model: """ assert SCIPhasPrimalRay(self._scip), "The problem does not have a primal ray." - cdef int i cdef int _nvars = SCIPgetNVars(self._scip) cdef SCIP_VAR ** _vars = SCIPgetVars(self._scip) @@ -8656,8 +8600,6 @@ cdef class Model: def _getStageNames(self): """Gets names of stages.""" - cdef str name - for name in dir(PY_SCIP_STAGE): attr = getattr(PY_SCIP_STAGE, name) if isinstance(attr, int): @@ -9105,7 +9047,6 @@ cdef class Model: """ cdef SCIP_PARAM** params - cdef int i params = SCIPgetParams(self._scip) result = {} @@ -9124,7 +9065,6 @@ cdef class Model: dict mapping parameter names to their values. """ - cdef str name for name, value in params.items(): self.setParam(name, value) @@ -9295,8 +9235,6 @@ cdef class Model: """ cdef SCIP_OBJSENSE objsense - cdef int i - cdef SCIP_Real coef if sense == "minimize": objsense = SCIP_OBJSENSE_MINIMIZE @@ -9519,7 +9457,7 @@ cdef class Model: float """ - cdef int i + assert isinstance(gains, list) nchildren = len(gains) @@ -9612,7 +9550,7 @@ cdef class Model: "basis_zero": 15, "best_incumbent_val": 16, "avg_incumbent_val": 17, "age": 18} if prev_col_features is None: - col_features = [[0 for i in range(n_col_features)] for j in range(ncols)] + col_features = [[0 for _ in range(n_col_features)] for _ in range(ncols)] else: assert len(prev_col_features) > 0, "Previous column features is empty" col_features = prev_col_features @@ -9620,7 +9558,7 @@ cdef class Model: if not suppress_warnings: raise Warning(f"The number of columns has changed. Previous column data being ignored") else: - col_features = [[0 for i in range(n_col_features)] for j in range(ncols)] + col_features = [[0 for _ in range(n_col_features)] for _ in range(ncols)] prev_col_features = None if len(prev_col_features[0]) != n_col_features: raise Warning(f"Dimension mismatch in provided previous features and new features:" @@ -9708,7 +9646,7 @@ cdef class Model: "basis_lower": 10, "basis_basic": 11, "basis_upper": 12, "basis_zero": 13} if prev_row_features is None: - row_features = [[0 for i in range(n_row_features)] for j in range(nrows)] + row_features = [[0 for _ in range(n_row_features)] for _ in range(nrows)] else: assert len(prev_row_features) > 0, "Previous row features is empty" row_features = prev_row_features @@ -9716,7 +9654,7 @@ cdef class Model: if not suppress_warnings: raise Warning(f"The number of rows has changed. Previous row data being ignored") else: - row_features = [[0 for i in range(n_row_features)] for j in range(nrows)] + row_features = [[0 for _ in range(n_row_features)] for _ in range(nrows)] prev_row_features = None if len(prev_row_features[0]) != n_row_features: raise Warning(f"Dimension mismatch in provided previous features and new features:" @@ -9783,7 +9721,7 @@ cdef class Model: n_edge_features = 3 edge_feature_map = {"col_idx": 0, "row_idx": 1, "coef": 2} if prev_edge_features is None: - edge_features = [[0 for i in range(n_edge_features)] for j in range(nnzrs)] + edge_features = [[0 for _ in range(n_edge_features)] for _ in range(nnzrs)] j = 0 for i in range(nrows): # coefficient indexes and values @@ -9801,7 +9739,7 @@ cdef class Model: if not suppress_warnings: raise Warning(f"The number of coefficients in the LP has changed. Previous edge data being ignored") else: - edge_features = [[0 for i in range(3)] for j in range(nnzrs)] + edge_features = [[0 for _ in range(3)] for _ in range(nnzrs)] prev_edge_features = None if len(prev_edge_features[0]) != 3: raise Warning(f"Dimension mismatch in provided previous features and new features:" @@ -9970,11 +9908,6 @@ def readStatistics(filename): Statistics """ - cdef int i - cdef str line - cdef str var_type - cdef str con_type - result = {} file = open(filename) data = file.readlines() diff --git a/tests/test_event.py b/tests/test_event.py index ec5103a6..1cd4c59d 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -82,7 +82,8 @@ def test_event(): s.addCons(quicksum(x[i] for i in range(100) if i%j==0) >= random.randint(10,100)) s.optimize() - + + def test_event_handler_callback(): m = Model() @@ -99,5 +100,4 @@ def callback(model, event): m.optimize() - assert number_of_calls == 2 -test_event_handler_callback() \ No newline at end of file + assert number_of_calls == 2 \ No newline at end of file