Detailed Description
implementation of NLPI oracle
Definition in file nlpioracle.c.
#include "scip/scip.h"
#include "scip/nlpioracle.h"
#include "scip/exprinterpret.h"
#include "scip/expr_pow.h"
#include "scip/expr_varidx.h"
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | SCIP_NlpiOracleCons |
struct | SCIP_NlpiOracle |
Typedefs | |
NLPI Oracle data structures | |
typedef struct SCIP_NlpiOracleCons | SCIP_NLPIORACLECONS |
Typedef Documentation
◆ SCIP_NLPIORACLECONS
typedef struct SCIP_NlpiOracleCons SCIP_NLPIORACLECONS |
Definition at line 61 of file nlpioracle.c.
Function Documentation
◆ ensureVarsSize()
|
static |
ensures that those arrays in oracle that store information on variables have at least a given length
- Parameters
-
scip SCIP data structure oracle NLPIORACLE data structure minsize minimal required size
Definition at line 102 of file nlpioracle.c.
References NULL, SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), SCIPreallocBlockMemoryArray, SCIP_NlpiOracle::varlbs, SCIP_NlpiOracle::varlincount, SCIP_NlpiOracle::varnames, SCIP_NlpiOracle::varnlcount, SCIP_NlpiOracle::varssize, and SCIP_NlpiOracle::varubs.
Referenced by SCIPnlpiOracleAddVars().
◆ ensureConssSize()
|
static |
ensures that constraints array in oracle has at least a given length
- Parameters
-
scip SCIP data structure oracle NLPIORACLE data structure minsize minimal required size
Definition at line 135 of file nlpioracle.c.
References SCIP_NlpiOracle::conss, SCIP_NlpiOracle::consssize, NULL, SCIP_CALL, SCIP_OKAY, and SCIPensureBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints().
◆ ensureConsLinSize()
|
static |
ensures that arrays for linear part in a oracle constraints have at least a given length
- Parameters
-
scip SCIP data structure cons oracle constraint minsize minimal required size
Definition at line 151 of file nlpioracle.c.
References SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::linsize, NULL, SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), and SCIPreallocBlockMemoryArray.
Referenced by SCIPnlpiOracleChgLinearCoefs().
◆ ensureIntArraySize()
|
static |
ensures that a given array of integers has at least a given length
- Parameters
-
scip SCIP data structure intarray array of integers len length of array (modified if reallocated) minsize minimal required array length
Definition at line 177 of file nlpioracle.c.
References NULL, SCIP_CALL, SCIP_OKAY, and SCIPensureBlockMemoryArray.
Referenced by hessLagSparsitySetNzFlagForExpr(), and SCIPnlpiOracleGetJacobianSparsity().
◆ invalidateJacobiSparsity()
|
static |
Invalidates the sparsity pattern of the Jacobian. Should be called when constraints are added or deleted.
- Parameters
-
scip SCIP data structure oracle pointer to store NLPIORACLE data structure
Definition at line 197 of file nlpioracle.c.
References SCIP_NlpiOracle::jaccols, SCIP_NlpiOracle::jacoffsets, SCIP_NlpiOracle::nconss, NULL, SCIPdebugMessage, and SCIPfreeBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleChgExpr(), SCIPnlpiOracleChgLinearCoefs(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleDelVarSet(), and SCIPnlpiOracleFree().
◆ invalidateHessianLagSparsity()
|
static |
Invalidates the sparsity pattern of the Hessian of the Lagragian. Should be called when the objective is set or constraints are added or deleted.
- Parameters
-
scip SCIP data structure oracle pointer to store NLPIORACLE data structure
Definition at line 221 of file nlpioracle.c.
References SCIP_NlpiOracle::heslagcols, SCIP_NlpiOracle::heslagoffsets, NULL, SCIP_NlpiOracle::nvars, SCIPdebugMessage, and SCIPfreeBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleAddVars(), SCIPnlpiOracleChgExpr(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleDelVarSet(), SCIPnlpiOracleFree(), and SCIPnlpiOracleSetObjective().
◆ updateVariableCounts()
|
static |
increases or decreases variable counts in oracle w.r.t. linear and nonlinear appearance
- Parameters
-
scip SCIP data structure oracle oracle data structure factor whether to add (factor=1) or remove (factor=-1) variable counts nlinidxs number of linear indices linidxs indices of variables in linear part expr expression
Definition at line 243 of file nlpioracle.c.
References FALSE, NULL, SCIP_CALL, SCIP_EXPRITER_DFS, SCIP_OKAY, SCIPcreateExpriter(), SCIPexpriterGetNext(), SCIPexpriterInit(), SCIPexpriterIsEnd(), SCIPfreeExpriter(), SCIPgetIndexExprVaridx(), SCIPisExprVaridx(), SCIP_NlpiOracle::varlincount, and SCIP_NlpiOracle::varnlcount.
Referenced by createConstraint(), freeConstraint(), SCIPnlpiOracleChgExpr(), SCIPnlpiOracleChgLinearCoefs(), and SCIPnlpiOracleDelConsSet().
◆ sortLinearCoefficients()
|
static |
sorts a linear term, merges duplicate entries and removes entries with coefficient 0.0
- Parameters
-
nidxs number of variables idxs indices of variables coefs coefficients of variables
Definition at line 288 of file nlpioracle.c.
References NULL, and SCIPsortIntReal().
Referenced by createConstraint(), and SCIPnlpiOracleChgLinearCoefs().
◆ createConstraint()
|
static |
creates a NLPI constraint from given constraint data
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure cons buffer where to store pointer to constraint nlinidxs length of linear part linidxs indices of linear part, or NULL if nlinidxs == 0 lincoefs coefficients of linear part, or NULL if nlinidxs == 0 expr expression, or NULL lhs left-hand-side of constraint rhs right-hand-side of constraint name name of constraint, or NULL
Definition at line 337 of file nlpioracle.c.
References EPSEQ, EPSLE, SCIP_NlpiOracle::exprinterpreter, NULL, SCIP_CALL, SCIP_DEFAULT_EPSILON, SCIP_OKAY, SCIPallocClearBlockMemory, SCIPcaptureExpr(), SCIPduplicateBlockMemoryArray, SCIPexprintCompile(), sortLinearCoefficients(), and updateVariableCounts().
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleCreate(), and SCIPnlpiOracleSetObjective().
◆ freeConstraint()
|
static |
frees a constraint
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure cons pointer to constraint that should be freed updatevarcount whether the update variable counts (typically TRUE)
Definition at line 400 of file nlpioracle.c.
References SCIP_NlpiOracle::exprinterpreter, NULL, SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, SCIPexprintFreeData(), SCIPfreeBlockMemory, SCIPfreeBlockMemoryArrayNull, SCIPreleaseExpr(), and updateVariableCounts().
Referenced by freeConstraints(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleFree(), and SCIPnlpiOracleSetObjective().
◆ freeConstraints()
|
static |
frees all constraints
- Attention
- This omits updating the variable counts in the oracle.
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure
Definition at line 444 of file nlpioracle.c.
References SCIP_NlpiOracle::conss, SCIP_NlpiOracle::consssize, FALSE, freeConstraint(), SCIP_NlpiOracle::nconss, NULL, SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, and SCIPfreeBlockMemoryArrayNull.
Referenced by SCIPnlpiOracleDelConsSet(), and SCIPnlpiOracleFree().
◆ moveVariable()
|
static |
moves one variable The place where it moves to need to be empty (all NULL) but allocated. Note that this function does not update the variable indices in the constraints!
- Parameters
-
scip SCIP data structure oracle pointer to store NLPIORACLE data structure fromidx index of variable to move toidx index of place where to move variable to
Definition at line 473 of file nlpioracle.c.
References NULL, SCIP_OKAY, SCIPdebugMessage, SCIPinfinity(), SCIP_NlpiOracle::varlbs, SCIP_NlpiOracle::varlincount, SCIP_NlpiOracle::varnames, SCIP_NlpiOracle::varnlcount, and SCIP_NlpiOracle::varubs.
Referenced by SCIPnlpiOracleDelVarSet().
◆ freeVariables()
|
static |
frees all variables
- Parameters
-
scip SCIP data structure oracle pointer to store NLPIORACLE data structure
Definition at line 512 of file nlpioracle.c.
References NULL, SCIP_NlpiOracle::nvars, SCIPdebugMessage, SCIPfreeBlockMemoryArray, SCIPfreeBlockMemoryArrayNull, SCIP_NlpiOracle::varlbs, SCIP_NlpiOracle::varlincount, SCIP_NlpiOracle::varnames, SCIP_NlpiOracle::varnlcount, SCIP_NlpiOracle::varssize, and SCIP_NlpiOracle::varubs.
Referenced by SCIPnlpiOracleDelVarSet(), and SCIPnlpiOracleFree().
◆ mapIndices()
|
static |
applies a mapping of indices to one array of indices
- Parameters
-
indexmap mapping from old variable indices to new indices nindices number of indices in indices1 and indices2 indices array of indices to adjust
Definition at line 546 of file nlpioracle.c.
References NULL.
Referenced by SCIPnlpiOracleDelVarSet().
◆ clearDeletedLinearElements()
|
static |
removes entries with index -1 (marked as deleted) from array of linear elements assumes that array is sorted by index, i.e., all -1 are at the beginning
- Parameters
-
linidxs variable indices coefs variable coefficients nidxs number of indices
Definition at line 566 of file nlpioracle.c.
References NULL, and SCIPdebugMessage.
Referenced by SCIPnlpiOracleDelVarSet().
◆ evalFunctionValue()
|
static |
computes the value of a function
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure cons oracle constraint x the point where to evaluate val pointer to store function value
Definition at line 604 of file nlpioracle.c.
References ABS, SCIP_NlpiOracleCons::expr, SCIP_NlpiOracleCons::exprintdata, SCIP_NlpiOracle::exprinterpreter, SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::nlinidxs, NULL, SCIP_NlpiOracle::nvars, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPdebugMessage, SCIPexprintEval(), SCIPisFinite, SCIPisInfinity(), and x.
Referenced by SCIPnlpiOracleEvalConstraintValue(), SCIPnlpiOracleEvalConstraintValues(), and SCIPnlpiOracleEvalObjectiveValue().
◆ evalFunctionGradient()
|
static |
computes the value and gradient of a function
- Returns
- SCIP_INVALIDDATA, if the function or its gradient could not be evaluated (domain error, etc.)
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure cons oracle constraint x the point where to evaluate isnewx has the point x changed since the last call to some evaluation function? val pointer to store function value grad pointer to store function gradient
Definition at line 657 of file nlpioracle.c.
References ABS, BMSclearMemoryArray, SCIP_NlpiOracleCons::expr, SCIP_NlpiOracleCons::exprintdata, SCIP_NlpiOracle::exprinterpreter, SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::nlinidxs, NULL, SCIP_NlpiOracle::nvars, SCIP_CALL, SCIP_INVALIDDATA, SCIP_OKAY, SCIP_Real, SCIPdebug, SCIPdebugMessage, SCIPdebugMsg, SCIPexprintGrad(), SCIPisFinite, SCIPisInfinity(), and x.
Referenced by SCIPnlpiOracleEvalConstraintGradient(), and SCIPnlpiOracleEvalObjectiveGradient().
◆ hessLagSparsitySetNzFlagForExpr()
|
static |
collects indices of nonzero entries in the lower-left part of the hessian matrix of an expression adds the indices to a given set of indices, avoiding duplicates
- Parameters
-
scip SCIP data structure oracle NLPI oracle colnz indices of nonzero entries for each column collen space allocated to store indices of nonzeros for each column colnnz number of nonzero entries for each column nzcount counter for total number of nonzeros; should be increased when nzflag is set to 1 the first time expr expression exprintdata expression interpreter data for expression dim dimension of matrix
Definition at line 731 of file nlpioracle.c.
References ensureIntArraySize(), SCIP_NlpiOracle::exprinterpreter, NULL, SCIP_NlpiOracle::nvars, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPallocBufferArray, SCIPdebugMessage, SCIPexprintHessianSparsity(), SCIPfreeBufferArray, SCIPsortedvecFindInt(), SCIPsortedvecInsertInt(), and x.
Referenced by SCIPnlpiOracleGetHessianLagSparsity().
◆ hessLagAddExpr()
|
static |
adds hessian of an expression into hessian structure
- Parameters
-
scip SCIP data structure oracle oracle weight weight of quadratic part x point for which hessian should be returned new_x whether point has been evaluated before expr expression exprintdata expression interpreter data for expression hesoffset row offsets in sparse matrix that is to be filled hescol column indices in sparse matrix that is to be filled values buffer for values of sparse matrix that is to be filled
Definition at line 791 of file nlpioracle.c.
References SCIP_NlpiOracle::exprinterpreter, FALSE, h, NULL, SCIP_CALL, SCIP_ERROR, SCIP_INVALIDDATA, SCIP_OKAY, SCIP_Real, SCIPdebugMessage, SCIPerrorMessage, SCIPexprintHessian(), SCIPisFinite, SCIPsortedvecFindInt(), and x.
Referenced by SCIPnlpiOracleEvalHessianLag().
◆ printName()
|
static |
prints a name, if available, makes sure it has not more than 64 characters, and adds a unique prefix if the longnames flag is set
- Parameters
-
buffer buffer to print to, has to be not NULL and should be at least 65 bytes name name, or NULL idx index of var or cons which the name corresponds to prefix a letter (typically 'x' or 'e') to distinguish variable and equation names, if names[idx] is not available suffix a suffer to add to the name, or NULL longnames whether prefixes for long names should be added
Definition at line 858 of file nlpioracle.c.
References NULL, and SCIPsnprintf().
Referenced by printFunction(), and SCIPnlpiOraclePrintProblemGams().
◆ printFunction()
|
static |
prints a function
- Parameters
-
scip SCIP data structure oracle pointer to NLPIORACLE data structure file file to print to, has to be not NULL cons constraint which function to print longvarnames whether variable names need to be shorten to 64 characters
Definition at line 893 of file nlpioracle.c.
References SCIP_NlpiOracleCons::expr, SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::nlinidxs, NULL, printName(), SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, SCIPinfoMessage(), SCIPprintExpr(), and SCIP_NlpiOracle::varnames.
Referenced by SCIPnlpiOraclePrintProblem(), and SCIPnlpiOraclePrintProblemGams().
◆ exprIsNonSmooth()
|
static |
returns whether an expression contains nonsmooth operands (min, max, abs, ...)
- Parameters
-
scip SCIP data structure expr expression nonsmooth buffer to store whether expression seems nonsmooth
Definition at line 930 of file nlpioracle.c.
References FALSE, NULL, SCIP_CALL, SCIP_EXPRITER_DFS, SCIP_OKAY, SCIPcreateExpriter(), SCIPexprGetHdlr(), SCIPexprhdlrGetName(), SCIPexpriterGetNext(), SCIPexpriterInit(), SCIPexpriterIsEnd(), SCIPfreeExpriter(), SCIPisExprSignpower(), and TRUE.
Referenced by SCIPnlpiOraclePrintProblemGams().