Skip to content

Commit 12a76e9

Browse files
Add type to loop variables only (#947)
* add missing type * Typed loop variables * remove forgotten stuff * Update CHANGELOG.md Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com> * Dominik's comments * Also on conshdlr, even though it looks ugly * fixing some more stuff * Update src/pyscipopt/reader.pxi Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com> * added some consistency to variable names * Remove additional lines * Reorder variable declarations * Reformat variable declarations --------- Co-authored-by: DominikKamp <130753997+DominikKamp@users.noreply.github.com> Co-authored-by: Dominik Kamp <dominik.kamp@uni-bayreuth.de>
1 parent c473fd7 commit 12a76e9

File tree

8 files changed

+341
-248
lines changed

8 files changed

+341
-248
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44
### Added
5+
- Added cdef type declaration of loop variables for slight speedup
56
- Added wrappers for setting and getting heuristic timing
67
- Added transformed option to getVarDict, updated test
78
- Added categorical data example

src/pyscipopt/benders.pxi

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ cdef SCIP_RETCODE PyBendersSolvesub (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL
175175
cdef SCIP_RETCODE PyBendersPostsolve (SCIP* scip, SCIP_BENDERS* benders, SCIP_SOL* sol,
176176
SCIP_BENDERSENFOTYPE type, int* mergecands, int npriomergecands, int nmergecands, SCIP_Bool checkint,
177177
SCIP_Bool infeasible, SCIP_Bool* merged) noexcept with gil:
178-
cdef SCIP_BENDERSDATA* bendersdata
179-
bendersdata = SCIPbendersGetData(benders)
178+
cdef SCIP_BENDERSDATA* bendersdata = SCIPbendersGetData(benders)
179+
cdef int i
180180
PyBenders = <Benders>bendersdata
181181
if sol == NULL:
182182
solution = None

src/pyscipopt/conshdlr.pxi

+32-16
Original file line numberDiff line numberDiff line change
@@ -168,48 +168,54 @@ cdef SCIP_RETCODE PyConsFree (SCIP* scip, SCIP_CONSHDLR* conshdlr) noexcept with
168168
return SCIP_OKAY
169169

170170
cdef SCIP_RETCODE PyConsInit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
171+
cdef int i
171172
PyConshdlr = getPyConshdlr(conshdlr)
172-
cdef constraints = []
173+
constraints = []
173174
for i in range(nconss):
174175
constraints.append(getPyCons(conss[i]))
175176
PyConshdlr.consinit(constraints)
176177
return SCIP_OKAY
177178

178179
cdef SCIP_RETCODE PyConsExit (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
180+
cdef int i
179181
PyConshdlr = getPyConshdlr(conshdlr)
180-
cdef constraints = []
182+
constraints = []
181183
for i in range(nconss):
182184
constraints.append(getPyCons(conss[i]))
183185
PyConshdlr.consexit(constraints)
184186
return SCIP_OKAY
185187

186188
cdef SCIP_RETCODE PyConsInitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
189+
cdef int i
187190
PyConshdlr = getPyConshdlr(conshdlr)
188-
cdef constraints = []
191+
constraints = []
189192
for i in range(nconss):
190193
constraints.append(getPyCons(conss[i]))
191194
PyConshdlr.consinitpre(constraints)
192195
return SCIP_OKAY
193196

194197
cdef SCIP_RETCODE PyConsExitpre (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
198+
cdef int i
195199
PyConshdlr = getPyConshdlr(conshdlr)
196-
cdef constraints = []
200+
constraints = []
197201
for i in range(nconss):
198202
constraints.append(getPyCons(conss[i]))
199203
PyConshdlr.consexitpre(constraints)
200204
return SCIP_OKAY
201205

202206
cdef SCIP_RETCODE PyConsInitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
207+
cdef int i
203208
PyConshdlr = getPyConshdlr(conshdlr)
204-
cdef constraints = []
209+
constraints = []
205210
for i in range(nconss):
206211
constraints.append(getPyCons(conss[i]))
207212
PyConshdlr.consinitsol(constraints)
208213
return SCIP_OKAY
209214

210215
cdef SCIP_RETCODE PyConsExitsol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool restart) noexcept with gil:
216+
cdef int i
211217
PyConshdlr = getPyConshdlr(conshdlr)
212-
cdef constraints = []
218+
constraints = []
213219
for i in range(nconss):
214220
constraints.append(getPyCons(conss[i]))
215221
PyConshdlr.consexitsol(constraints, restart)
@@ -244,17 +250,19 @@ cdef SCIP_RETCODE PyConsTrans (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS* s
244250
return SCIP_OKAY
245251

246252
cdef SCIP_RETCODE PyConsInitlp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, SCIP_Bool* infeasible) noexcept with gil:
253+
cdef int i
247254
PyConshdlr = getPyConshdlr(conshdlr)
248-
cdef constraints = []
255+
constraints = []
249256
for i in range(nconss):
250257
constraints.append(getPyCons(conss[i]))
251258
result_dict = PyConshdlr.consinitlp(constraints)
252259
infeasible[0] = result_dict.get("infeasible", infeasible[0])
253260
return SCIP_OKAY
254261

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

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

275284
cdef SCIP_RETCODE PyConsEnfolp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss,
276285
SCIP_Bool solinfeasible, SCIP_RESULT* result) noexcept with gil:
286+
cdef int i
277287
PyConshdlr = getPyConshdlr(conshdlr)
278-
cdef constraints = []
288+
constraints = []
279289
for i in range(nconss):
280290
constraints.append(getPyCons(conss[i]))
281291
result_dict = PyConshdlr.consenfolp(constraints, nusefulconss, solinfeasible)
282292
result[0] = result_dict.get("result", <SCIP_RESULT>result[0])
283293
return SCIP_OKAY
284294

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

295306
cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss,
296307
SCIP_Bool solinfeasible, SCIP_Bool objinfeasible, SCIP_RESULT* result) noexcept with gil:
308+
cdef int i
297309
PyConshdlr = getPyConshdlr(conshdlr)
298-
cdef constraints = []
310+
constraints = []
299311
for i in range(nconss):
300312
constraints.append(getPyCons(conss[i]))
301313
result_dict = PyConshdlr.consenfops(constraints, nusefulconss, solinfeasible, objinfeasible)
@@ -304,8 +316,9 @@ cdef SCIP_RETCODE PyConsEnfops (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
304316

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

316329
cdef SCIP_RETCODE PyConsProp (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss, int nusefulconss, int nmarkedconss,
317330
SCIP_PROPTIMING proptiming, SCIP_RESULT* result) noexcept with gil:
331+
cdef int i
318332
PyConshdlr = getPyConshdlr(conshdlr)
319-
cdef constraints = []
333+
constraints = []
320334
for i in range(nconss):
321335
constraints.append(getPyCons(conss[i]))
322336
result_dict = PyConshdlr.consprop(constraints, nusefulconss, nmarkedconss, proptiming)
@@ -328,8 +342,9 @@ cdef SCIP_RETCODE PyConsPresol (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS**
328342
int nnewdelconss, int nnewaddconss, int nnewupgdconss, int nnewchgcoefs, int nnewchgsides,
329343
int* nfixedvars, int* naggrvars, int* nchgvartypes, int* nchgbds, int* naddholes,
330344
int* ndelconss, int* naddconss, int* nupgdconss, int* nchgcoefs, int* nchgsides, SCIP_RESULT* result) noexcept with gil:
345+
cdef int i
331346
PyConshdlr = getPyConshdlr(conshdlr)
332-
cdef constraints = []
347+
constraints = []
333348
for i in range(nconss):
334349
constraints.append(getPyCons(conss[i]))
335350
# dictionary for input/output parameters
@@ -401,8 +416,9 @@ cdef SCIP_RETCODE PyConsDisable (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS*
401416
return SCIP_OKAY
402417

403418
cdef SCIP_RETCODE PyConsDelvars (SCIP* scip, SCIP_CONSHDLR* conshdlr, SCIP_CONS** conss, int nconss) noexcept with gil:
419+
cdef int i
404420
PyConshdlr = getPyConshdlr(conshdlr)
405-
cdef constraints = []
421+
constraints = []
406422
for i in range(nconss):
407423
constraints.append(getPyCons(conss[i]))
408424
PyConshdlr.consdelvars(constraints)

src/pyscipopt/cutsel.pxi

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ cdef SCIP_RETCODE PyCutselExitsol (SCIP* scip, SCIP_CUTSEL* cutsel) noexcept wit
7272
cdef SCIP_RETCODE PyCutselSelect (SCIP* scip, SCIP_CUTSEL* cutsel, SCIP_ROW** cuts, int ncuts,
7373
SCIP_ROW** forcedcuts, int nforcedcuts, SCIP_Bool root, int maxnselectedcuts,
7474
int* nselectedcuts, SCIP_RESULT* result) noexcept with gil:
75-
cdef SCIP_CUTSELDATA* cutseldata
75+
cdef SCIP_CUTSELDATA* cutseldata = SCIPcutselGetData(cutsel)
7676
cdef SCIP_ROW* scip_row
77-
cutseldata = SCIPcutselGetData(cutsel)
77+
cdef int i
78+
7879
PyCutsel = <Cutsel>cutseldata
7980

8081
# translate cuts to python

0 commit comments

Comments
 (0)