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 |
| typedef struct SCIP_NlpiOracleCons SCIP_NLPIORACLECONS |
Definition at line 61 of file nlpioracle.c.
|
static |
ensures that those arrays in oracle that store information on variables have at least a given length
| scip | SCIP data structure |
| oracle | NLPIORACLE data structure |
| minsize | minimal required size |
Definition at line 102 of file nlpioracle.c.
References assert(), 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().
|
static |
ensures that constraints array in oracle has at least a given length
| scip | SCIP data structure |
| oracle | NLPIORACLE data structure |
| minsize | minimal required size |
Definition at line 135 of file nlpioracle.c.
References assert(), SCIP_NlpiOracle::conss, SCIP_NlpiOracle::consssize, NULL, SCIP_CALL, SCIP_OKAY, and SCIPensureBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints().
|
static |
ensures that arrays for linear part in a oracle constraints have at least a given length
| scip | SCIP data structure |
| cons | oracle constraint |
| minsize | minimal required size |
Definition at line 151 of file nlpioracle.c.
References assert(), SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::linsize, NULL, SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), and SCIPreallocBlockMemoryArray.
Referenced by SCIPnlpiOracleChgLinearCoefs().
|
static |
ensures that a given array of integers has at least a given length
| 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 assert(), NULL, SCIP_CALL, SCIP_OKAY, and SCIPensureBlockMemoryArray.
Referenced by hessLagSparsitySetNzFlagForExpr(), and SCIPnlpiOracleGetJacobianSparsity().
|
static |
Invalidates the sparsity pattern of the Jacobian. Should be called when constraints are added or deleted.
| scip | SCIP data structure |
| oracle | pointer to store NLPIORACLE data structure |
Definition at line 197 of file nlpioracle.c.
References assert(), SCIP_NlpiOracle::jaccols, SCIP_NlpiOracle::jacoffsets, SCIP_NlpiOracle::nconss, NULL, SCIPdebugMessage, and SCIPfreeBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleChgExpr(), SCIPnlpiOracleChgLinearCoefs(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleDelVarSet(), and SCIPnlpiOracleFree().
|
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.
| scip | SCIP data structure |
| oracle | pointer to store NLPIORACLE data structure |
Definition at line 221 of file nlpioracle.c.
References assert(), SCIP_NlpiOracle::heslagcols, SCIP_NlpiOracle::heslagoffsets, NULL, SCIP_NlpiOracle::nvars, SCIPdebugMessage, and SCIPfreeBlockMemoryArray.
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleAddVars(), SCIPnlpiOracleChgExpr(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleDelVarSet(), SCIPnlpiOracleFree(), and SCIPnlpiOracleSetObjective().
|
static |
increases or decreases variable counts in oracle w.r.t. linear and nonlinear appearance
| 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 assert(), 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().
|
static |
sorts a linear term, merges duplicate entries and removes entries with coefficient 0.0
| nidxs | number of variables |
| idxs | indices of variables |
| coefs | coefficients of variables |
Definition at line 288 of file nlpioracle.c.
References assert(), NULL, SCIP_Real, and SCIPsortIntReal().
Referenced by createConstraint(), and SCIPnlpiOracleChgLinearCoefs().
|
static |
creates a NLPI constraint from given constraint data
| 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 assert(), EPSEQ, EPSLE, SCIP_NlpiOracle::exprinterpreter, NULL, SCIP_CALL, SCIP_DEFAULT_EPSILON, SCIP_OKAY, SCIP_Real, SCIPallocClearBlockMemory, SCIPcaptureExpr(), SCIPduplicateBlockMemoryArray, SCIPexprintCompile(), sortLinearCoefficients(), and updateVariableCounts().
Referenced by SCIPnlpiOracleAddConstraints(), SCIPnlpiOracleCreate(), and SCIPnlpiOracleSetObjective().
|
static |
frees a constraint
| 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 assert(), SCIP_NlpiOracle::exprinterpreter, NULL, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, SCIPexprintFreeData(), SCIPfreeBlockMemory, SCIPfreeBlockMemoryArrayNull, SCIPreleaseExpr(), and updateVariableCounts().
Referenced by freeConstraints(), SCIPnlpiOracleDelConsSet(), SCIPnlpiOracleFree(), and SCIPnlpiOracleSetObjective().
|
static |
frees all constraints
| scip | SCIP data structure |
| oracle | pointer to NLPIORACLE data structure |
Definition at line 444 of file nlpioracle.c.
References assert(), SCIP_NlpiOracle::conss, SCIP_NlpiOracle::consssize, FALSE, freeConstraint(), i, SCIP_NlpiOracle::nconss, NULL, SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, and SCIPfreeBlockMemoryArrayNull.
Referenced by SCIPnlpiOracleDelConsSet(), and SCIPnlpiOracleFree().
|
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!
| 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 assert(), NULL, nvars, SCIP_OKAY, SCIPdebugMessage, SCIPinfinity(), SCIP_NlpiOracle::varlbs, SCIP_NlpiOracle::varlincount, SCIP_NlpiOracle::varnames, SCIP_NlpiOracle::varnlcount, and SCIP_NlpiOracle::varubs.
Referenced by SCIPnlpiOracleDelVarSet().
|
static |
frees all variables
| scip | SCIP data structure |
| oracle | pointer to store NLPIORACLE data structure |
Definition at line 512 of file nlpioracle.c.
References assert(), i, 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().
|
static |
applies a mapping of indices to one array of indices
| 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 assert(), and NULL.
Referenced by SCIPnlpiOracleDelVarSet().
|
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
| linidxs | variable indices |
| coefs | variable coefficients |
| nidxs | number of indices |
Definition at line 566 of file nlpioracle.c.
References assert(), i, NULL, SCIP_Real, and SCIPdebugMessage.
Referenced by SCIPnlpiOracleDelVarSet().
|
static |
computes the value of a function
| 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, assert(), 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().
|
static |
computes the value and gradient of a function
| 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, assert(), BMSclearMemoryArray, SCIP_NlpiOracleCons::expr, SCIP_NlpiOracleCons::exprintdata, SCIP_NlpiOracle::exprinterpreter, i, SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::nlinidxs, NULL, SCIP_NlpiOracle::nvars, RESTRICT, SCIP_Bool, SCIP_CALL, SCIP_INVALIDDATA, SCIP_OKAY, SCIP_Real, SCIPdebug, SCIPdebugMessage, SCIPdebugMsg, SCIPexprintGrad(), SCIPisFinite, SCIPisInfinity(), and x.
Referenced by SCIPnlpiOracleEvalConstraintGradient(), and SCIPnlpiOracleEvalObjectiveGradient().
|
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
| 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 assert(), ensureIntArraySize(), SCIP_NlpiOracle::exprinterpreter, i, NULL, nvars, SCIP_NlpiOracle::nvars, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPallocBufferArray, SCIPdebugMessage, SCIPexprintHessianSparsity(), SCIPfreeBufferArray, SCIPsortedvecFindInt(), SCIPsortedvecInsertInt(), and x.
Referenced by SCIPnlpiOracleGetHessianLagSparsity().
|
static |
adds hessian of an expression into hessian structure
| 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 assert(), SCIP_NlpiOracle::exprinterpreter, FALSE, h, i, NULL, SCIP_Bool, SCIP_CALL, SCIP_ERROR, SCIP_INVALIDDATA, SCIP_OKAY, SCIP_Real, SCIPdebugMessage, SCIPerrorMessage, SCIPexprintHessian(), SCIPisFinite, SCIPsortedvecFindInt(), and x.
Referenced by SCIPnlpiOracleEvalHessianLag().
|
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
| 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 assert(), NULL, SCIP_Bool, and SCIPsnprintf().
Referenced by printFunction(), and SCIPnlpiOraclePrintProblemGams().
|
static |
prints a function
| 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 assert(), SCIP_NlpiOracleCons::expr, i, SCIP_NlpiOracleCons::lincoefs, SCIP_NlpiOracleCons::linidxs, SCIP_NlpiOracleCons::nlinidxs, NULL, printName(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPdebugMessage, SCIPinfoMessage(), SCIPprintExpr(), and SCIP_NlpiOracle::varnames.
Referenced by SCIPnlpiOraclePrintProblem(), and SCIPnlpiOraclePrintProblemGams().
|
static |
returns whether an expression contains nonsmooth operands (min, max, abs, ...)
| scip | SCIP data structure |
| expr | expression |
| nonsmooth | buffer to store whether expression seems nonsmooth |
Definition at line 930 of file nlpioracle.c.
References assert(), FALSE, NULL, SCIP_Bool, SCIP_CALL, SCIP_EXPRITER_DFS, SCIP_OKAY, SCIPcreateExpriter(), SCIPexprGetHdlr(), SCIPexprhdlrGetName(), SCIPexpriterGetNext(), SCIPexpriterInit(), SCIPexpriterIsEnd(), SCIPfreeExpriter(), SCIPisExprSignpower(), and TRUE.
Referenced by SCIPnlpiOraclePrintProblemGams().