Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type to loop variables only #947

Merged
merged 12 commits into from
Feb 1, 2025
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased
### Added
- Added cdef type declaration of 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
4 changes: 2 additions & 2 deletions src/pyscipopt/benders.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ 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 SCIP_BENDERSDATA* bendersdata
bendersdata = SCIPbendersGetData(benders)
cdef SCIP_BENDERSDATA* bendersdata = SCIPbendersGetData(benders)
cdef int i
DominikKamp marked this conversation as resolved.
Show resolved Hide resolved
PyBenders = <Benders>bendersdata
if sol == NULL:
solution = None
Expand Down
48 changes: 32 additions & 16 deletions src/pyscipopt/conshdlr.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -168,48 +168,54 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with
return SCIP_OKAY

cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consinit(constraints)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consexit(constraints)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consinitpre(constraints)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consexitpre(constraints)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consinitsol(constraints)
return SCIP_OKAY

cdef SCIP_RETCODE PyConsExitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool restart) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consexitsol(constraints, restart)
Expand Down Expand Up @@ -244,17 +250,19 @@ cdef SCIP_RETCODE PyConsTrans (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* s
return SCIP_OKAY

cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool* infeasible) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.consinitlp(constraints)
infeasible[0] = result_dict.get("infeasible", infeasible[0])
return SCIP_OKAY

cdef SCIP_RETCODE PyConsSepalp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.conssepalp(constraints, nusefulconss)
Expand All @@ -263,8 +271,9 @@ cdef SCIP_RETCODE PyConsSepalp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**

cdef SCIP_RETCODE PyConsSepasol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss,
SCIP_SOL* sol, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
solution = Solution.create(scip, sol)
Expand All @@ -274,17 +283,19 @@ cdef SCIP_RETCODE PyConsSepasol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*

cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss,
SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.consenfolp(constraints, nusefulconss, solinfeasible)
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
return SCIP_OKAY

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:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
solution = Solution.create(scip, sol)
Expand All @@ -294,8 +305,9 @@ cdef SCIP_RETCODE PyConsEnforelax (SCIP* scip, SCIP_SOL* sol, SCIP_CONSHDLR* con

cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss,
SCIP_Bool solinfeasible, SCIP_Bool objinfeasible, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.consenfops(constraints, nusefulconss, solinfeasible, objinfeasible)
Expand All @@ -304,8 +316,9 @@ cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**

cdef SCIP_RETCODE PyConsCheck (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_SOL* sol, SCIP_Bool checkintegrality,
SCIP_Bool checklprows, SCIP_Bool printreason, SCIP_Bool completely, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
solution = Solution.create(scip, sol)
Expand All @@ -315,8 +328,9 @@ cdef SCIP_RETCODE PyConsCheck (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**

cdef SCIP_RETCODE PyConsProp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, int nmarkedconss,
SCIP_PROPTIMING proptiming, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, proptiming)
Expand All @@ -328,8 +342,9 @@ cdef SCIP_RETCODE PyConsPresol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
int nnewdelconss, int nnewaddconss, int nnewupgdconss, int nnewchgcoefs, int nnewchgsides,
int* nfixedvars, int* naggrvars, int* nchgvartypes, int* nchgbds, int* naddholes,
int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
# dictionary for input/output parameters
Expand Down Expand Up @@ -401,8 +416,9 @@ cdef SCIP_RETCODE PyConsDisable (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
return SCIP_OKAY

cdef SCIP_RETCODE PyConsDelvars (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
cdef int i
PyConshdlr = getPyConshdlr(conshdlr)
cdef constraints = []
constraints = []
for i in range(nconss):
constraints.append(getPyCons(conss[i]))
PyConshdlr.consdelvars(constraints)
Expand Down
5 changes: 3 additions & 2 deletions src/pyscipopt/cutsel.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ 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 SCIP_CUTSELDATA* cutseldata
cdef SCIP_CUTSELDATA* cutseldata = SCIPcutselGetData(cutsel)
cdef SCIP_ROW* scip_row
cutseldata = SCIPcutselGetData(cutsel)
cdef int i

PyCutsel = <Cutsel>cutseldata

# translate cuts to python
Expand Down
Loading