@@ -2057,6 +2057,15 @@ cdef class Model:
20572057 def freeTransform (self ):
20582058 """ Frees all solution process data including presolving and
20592059 transformed problem, only original problem is kept."""
2060+ if self .getStage not in [SCIP_STAGE_INIT,
2061+ SCIP_STAGE_PROBLEM,
2062+ SCIP_STAGE_TRANSFORMED,
2063+ SCIP_STAGE_PRESOLVING,
2064+ SCIP_STAGE_PRESOLVED,
2065+ SCIP_STAGE_SOLVING,
2066+ SCIP_STAGE_SOLVED]:
2067+ raise Warning (" method cannot be called in stage %i ." % self .getStage)
2068+
20602069 self ._modelvars = {
20612070 var: value
20622071 for var, value in self ._modelvars.items()
@@ -4131,6 +4140,46 @@ cdef class Model:
41314140 free(coeffs_array)
41324141 return PyCons
41334142
4143+ def _createConsBasicLinear (self , ExprCons lincons , **kwargs ):
4144+ """
4145+ The function for creating a basic linear constraint, but not adding it to the Model.
4146+
4147+ Parameters
4148+ ----------
4149+ lincons : ExprCons
4150+ kwargs : dict, optional
4151+
4152+ Returns
4153+ -------
4154+ Constraint
4155+
4156+ """
4157+ assert isinstance (lincons, ExprCons), " given constraint is not ExprCons but %s " % lincons.__class__ .__name__
4158+
4159+ assert lincons.expr.degree() <= 1 , " given constraint is not linear, degree == %d " % lincons.expr.degree()
4160+ terms = lincons.expr.terms
4161+
4162+ cdef SCIP_CONS* scip_cons
4163+
4164+ cdef int nvars = len (terms.items())
4165+
4166+ vars_array = < SCIP_VAR** > malloc(nvars * sizeof(SCIP_VAR* ))
4167+ coeffs_array = < SCIP_Real* > malloc(nvars * sizeof(SCIP_Real))
4168+
4169+ for i, (key, coeff) in enumerate (terms.items()):
4170+ vars_array[i] = < SCIP_VAR* > (< Variable> key[0 ]).scip_var
4171+ coeffs_array[i] = < SCIP_Real> coeff
4172+
4173+ PY_SCIP_CALL(SCIPcreateConsBasicLinear(
4174+ self ._scip, & scip_cons, str_conversion(kwargs[' name' ]), nvars, vars_array, coeffs_array,
4175+ kwargs[' lhs' ], kwargs[' rhs' ]))
4176+
4177+ PyCons = Constraint.create(scip_cons)
4178+
4179+ free(vars_array)
4180+ free(coeffs_array)
4181+ return PyCons
4182+
41344183 def _createConsQuadratic (self , ExprCons quadcons , **kwargs ):
41354184 """
41364185 The function for creating a quadratic constraint, but not adding it to the Model.
@@ -6173,8 +6222,20 @@ cdef class Model:
61736222 PY_SCIP_CALL(SCIPsolveConcurrent(self ._scip))
61746223 self ._bestSol = Solution.create(self ._scip, SCIPgetBestSol(self ._scip))
61756224
6225+ def transformProb (self ):
6226+ """ Transform the problem"""
6227+ if self .getStage() in [SCIP_STAGE_INIT, SCIP_STAGE_TRANSFORMING]:
6228+ raise Warning (" method cannot be called in stage %i ." % self .getStage)
6229+
6230+ PY_SCIP_CALL(SCIPtransformProb(self ._scip))
6231+
61766232 def presolve (self ):
61776233 """ Presolve the problem."""
6234+ if self .getStage() not in [SCIP_STAGE_PROBLEM, SCIP_STAGE_TRANSFORMED,\
6235+ SCIP_STAGE_PRESOLVING, SCIP_STAGE_PRESOLVED, \
6236+ SCIP_STAGE_SOLVED]:
6237+ raise Warning (" method cannot be called in stage %i ." % self .getStage)
6238+
61786239 PY_SCIP_CALL(SCIPpresolve(self ._scip))
61796240 self ._bestSol = Solution.create(self ._scip, SCIPgetBestSol(self ._scip))
61806241
@@ -8977,6 +9038,16 @@ cdef class Model:
89779038
89789039 def freeReoptSolve (self ):
89799040 """ Frees all solution process data and prepares for reoptimization."""
9041+
9042+ if self .getStage not in [SCIP_STAGE_INIT,
9043+ SCIP_STAGE_PROBLEM,
9044+ SCIP_STAGE_TRANSFORMED,
9045+ SCIP_STAGE_PRESOLVING,
9046+ SCIP_STAGE_PRESOLVED,
9047+ SCIP_STAGE_SOLVING,
9048+ SCIP_STAGE_SOLVED]:
9049+ raise Warning (" method cannot be called in stage %i ." % self .getStage)
9050+
89809051 PY_SCIP_CALL(SCIPfreeReoptSolve(self ._scip))
89819052
89829053 def chgReoptObjective (self , coeffs , sense = ' minimize' ):
0 commit comments