Skip to content

Commit

Permalink
Revert "Typed loop variables"
Browse files Browse the repository at this point in the history
This reverts commit d07a684.
  • Loading branch information
Joao-Dionisio committed Jan 24, 2025
1 parent 5cefe5c commit c473fd7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 123 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/pyscipopt/benders.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Benders>bendersdata
Expand Down
16 changes: 0 additions & 16 deletions src/pyscipopt/conshdlr.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/pyscipopt/cutsel.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 1 addition & 23 deletions src/pyscipopt/lp.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <SCIP_Real*> malloc(nnonz * sizeof(SCIP_Real))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 = <SCIP_Real*> malloc(ncols * sizeof(SCIP_Real))
PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, c_primalsol, NULL, NULL, NULL))
Expand All @@ -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 = <SCIP_Real*> malloc(nrows * sizeof(SCIP_Real))
PY_SCIP_CALL(SCIPlpiGetSol(self.lpi, NULL, NULL, c_dualsol, NULL, NULL))
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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 = <SCIP_Real*> malloc(ncols * sizeof(SCIP_Real))
Expand All @@ -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 = <int*> malloc(nrows * sizeof(int))

Expand Down
1 change: 0 additions & 1 deletion src/pyscipopt/reader.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit c473fd7

Please sign in to comment.