@@ -5274,22 +5274,16 @@ cdef class Model:
52745274 terms = cons.expr.terms
52755275
52765276 # collect variables
5277- variables = {var.ptr(): var for term in terms for var in term}
5278- variables = list (variables.values())
5279- varindex = {var.ptr(): i for (i, var) in enumerate (variables)}
5277+ variables = {i: [var for var in term] for i, term in enumerate (terms)}
52805278
52815279 # create monomials for terms
52825280 monomials = < SCIP_EXPR** > malloc(len (terms) * sizeof(SCIP_EXPR* ))
52835281 termcoefs = < SCIP_Real* > malloc(len (terms) * sizeof(SCIP_Real))
52845282 for i, (term, coef) in enumerate (terms.items()):
5285- termvars = < SCIP_VAR** > malloc(len (term) * sizeof(SCIP_VAR* ))
5286- for j, var in enumerate (term):
5287- wrapper = _VarArray(var)
5288- termvars[j] = wrapper.ptr[0 ]
5283+ wrapper = _VarArray(variables[i])
52895284
5290- PY_SCIP_CALL( SCIPcreateExprMonomial(self ._scip, & monomials[i], < int > len (term), termvars , NULL , NULL , NULL ) )
5285+ PY_SCIP_CALL( SCIPcreateExprMonomial(self ._scip, & monomials[i], wrapper.size, wrapper.ptr , NULL , NULL , NULL ) )
52915286 termcoefs[i] = < SCIP_Real> coef
5292- free(termvars)
52935287
52945288 # create polynomial from monomials
52955289 PY_SCIP_CALL( SCIPcreateExprSum(self ._scip, & expr, < int > len (terms), monomials, termcoefs, 0.0 , NULL , NULL ))
@@ -6134,7 +6128,6 @@ cdef class Model:
61346128
61356129 cdef int nvars = len (vars )
61366130 cdef int i
6137- cdef SCIP_VAR** vars_array = < SCIP_VAR** > malloc(nvars * sizeof(SCIP_VAR* ))
61386131 cdef SCIP_Longint* weights_array = < SCIP_Longint* > malloc(nvars * sizeof(SCIP_Real))
61396132 cdef SCIP_CONS* scip_cons
61406133 cdef _VarArray wrapper
@@ -6153,7 +6146,6 @@ cdef class Model:
61536146 capacity, initial, separate, enforce, check, propagate, local, modifiable,
61546147 dynamic, removable, stickingatnode))
61556148
6156- free(vars_array)
61576149 free(weights_array)
61586150
61596151 PY_SCIP_CALL(SCIPaddCons(self ._scip, scip_cons))
0 commit comments