Scippy

SCIP

Solving Constraint Integer Programs

exprinterpret.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file exprinterpret.h
17  * @brief methods to interpret (evaluate) an expression "fast"
18  * @ingroup EXPRINTS
19  * @author Stefan Vigerske
20  *
21  * Realized similar to LPI: one implementation of an interpreter is linked in.
22  */
23 
24 /* @todo product Gradient times vector
25  @todo product Hessian times vector
26  @todo product Hessian of Lagrangian times vector?
27  @todo sparse Hessian of Lagrangian (sets of expressions)?
28 */
29 
30 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
31 
32 #ifndef __SCIP_EXPRINTERPRET_H__
33 #define __SCIP_EXPRINTERPRET_H__
34 
35 #include "scip/def.h"
37 #include "scip/type_scip.h"
38 #include "scip/type_expr.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /**@addtogroup EXPRINTS
45  * @{
46  */
47 
48 /** gets name and version of expression interpreter */
49 SCIP_EXPORT
50 const char* SCIPexprintGetName(void);
51 
52 /** gets descriptive text of expression interpreter */
53 SCIP_EXPORT
54 const char* SCIPexprintGetDesc(void);
55 
56 /** gets capabilities of expression interpreter (using bitflags) */
57 SCIP_EXPORT
59 
60 /** creates an expression interpreter object */
61 SCIP_EXPORT
63  SCIP* scip, /**< SCIP data structure */
64  SCIP_EXPRINT** exprint /**< buffer to store pointer to expression interpreter */
65  );
66 
67 /** frees an expression interpreter object */
68 SCIP_EXPORT
70  SCIP* scip, /**< SCIP data structure */
71  SCIP_EXPRINT** exprint /**< expression interpreter that should be freed */
72  );
73 
74 /** compiles an expression and returns interpreter-specific data for expression
75  *
76  * can be called again with existing exprintdata if expression has been changed
77  *
78  * @attention *exprintdata needs to be initialized to NULL at first call
79  * @attention the expression is assumed to use varidx expressions instead of var expressions
80  */
81 SCIP_EXPORT
83  SCIP* scip, /**< SCIP data structure */
84  SCIP_EXPRINT* exprint, /**< interpreter data structure */
85  SCIP_EXPR* expr, /**< expression */
86  SCIP_EXPRINTDATA** exprintdata /**< buffer to store pointer to compiled data */
87  );
88 
89 /** frees interpreter data for expression */
90 SCIP_EXPORT
92  SCIP* scip, /**< SCIP data structure */
93  SCIP_EXPRINT* exprint, /**< interpreter data structure */
94  SCIP_EXPR* expr, /**< expression */
95  SCIP_EXPRINTDATA** exprintdata /**< pointer to pointer to compiled data to be freed */
96  );
97 
98 /** gives the capability to evaluate an expression by the expression interpreter
99  *
100  * In cases of user-given expressions, higher order derivatives may not be available for the user-expression,
101  * even if the expression interpreter could handle these. This method allows to recognize that, e.g., the
102  * Hessian for an expression is not available because it contains a user expression that does not provide
103  * Hessians.
104  */
105 SCIP_EXPORT
107  SCIP* scip, /**< SCIP data structure */
108  SCIP_EXPRINT* exprint, /**< interpreter data structure */
109  SCIP_EXPR* expr, /**< expression */
110  SCIP_EXPRINTDATA* exprintdata /**< interpreter-specific data for expression */
111  );
112 
113 /** evaluates an expression */
114 SCIP_EXPORT
116  SCIP* scip, /**< SCIP data structure */
117  SCIP_EXPRINT* exprint, /**< interpreter data structure */
118  SCIP_EXPR* expr, /**< expression */
119  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
120  SCIP_Real* varvals, /**< values of variables */
121  SCIP_Real* val /**< buffer to store value of expression */
122  );
123 
124 /** computes value and gradient of an expression */
125 SCIP_EXPORT
127  SCIP* scip, /**< SCIP data structure */
128  SCIP_EXPRINT* exprint, /**< interpreter data structure */
129  SCIP_EXPR* expr, /**< expression */
130  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
131  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
132  SCIP_Bool new_varvals, /**< have variable values changed since last call to a point evaluation routine? */
133  SCIP_Real* val, /**< buffer to store expression value */
134  SCIP_Real* gradient /**< buffer to store expression gradient */
135  );
136 
137 /** gives sparsity pattern of lower-triangular part of Hessian
138  *
139  * Since the AD code might need to do a forward sweep, variable values need to be passed in here.
140  *
141  * Result will have `(*colidxs)[i] <= (*rowidixs)[i]` for `i=0..*nnz`.
142  */
143 SCIP_EXPORT
145  SCIP* scip, /**< SCIP data structure */
146  SCIP_EXPRINT* exprint, /**< interpreter data structure */
147  SCIP_EXPR* expr, /**< expression */
148  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
149  SCIP_Real* varvals, /**< values of variables */
150  int** rowidxs, /**< buffer to return array with row indices of Hessian elements */
151  int** colidxs, /**< buffer to return array with column indices of Hessian elements */
152  int* nnz /**< buffer to return length of arrays */
153  );
154 
155 /** computes value and Hessian of an expression
156  *
157  * Returned arrays `rowidxs` and `colidxs` and number of elements `nnz` are the same as given by SCIPexprintHessianSparsity().
158  * Returned array `hessianvals` will contain the corresponding Hessian elements.
159  */
160 SCIP_EXPORT
162  SCIP* scip, /**< SCIP data structure */
163  SCIP_EXPRINT* exprint, /**< interpreter data structure */
164  SCIP_EXPR* expr, /**< expression */
165  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
166  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
167  SCIP_Bool new_varvals, /**< have variable values changed since last call to an evaluation routine? */
168  SCIP_Real* val, /**< buffer to store function value */
169  int** rowidxs, /**< buffer to return array with row indices of Hessian elements */
170  int** colidxs, /**< buffer to return array with column indices of Hessian elements */
171  SCIP_Real** hessianvals, /**< buffer to return array with Hessian elements */
172  int* nnz /**< buffer to return length of arrays */
173  );
174 
175 /** @} */
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
181 #endif /* __SCIP_EXPRINTERPRET_H__ */
const char * SCIPexprintGetName(void)
SCIP_RETCODE SCIPexprintCompile(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA **exprintdata)
SCIP_RETCODE SCIPexprintFreeData(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA **exprintdata)
type definitions for expression interpreter
SCIP_RETCODE SCIPexprintHessianSparsity(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA *exprintdata, SCIP_Real *varvals, int **rowidxs, int **colidxs, int *nnz)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:54
const char * SCIPexprintGetDesc(void)
SCIP_RETCODE SCIPexprintGrad(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA *exprintdata, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *gradient)
unsigned int SCIP_EXPRINTCAPABILITY
type definitions for SCIP&#39;s main datastructure
SCIP_RETCODE SCIPexprintCreate(SCIP *scip, SCIP_EXPRINT **exprint)
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
SCIP_RETCODE SCIPexprintEval(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA *exprintdata, SCIP_Real *varvals, SCIP_Real *val)
SCIP_EXPRINTCAPABILITY SCIPexprintGetExprCapability(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA *exprintdata)
#define SCIP_Bool
Definition: def.h:84
SCIP_RETCODE SCIPexprintFree(SCIP *scip, SCIP_EXPRINT **exprint)
struct SCIP_ExprInt SCIP_EXPRINT
SCIP_RETCODE SCIPexprintHessian(SCIP *scip, SCIP_EXPRINT *exprint, SCIP_EXPR *expr, SCIP_EXPRINTDATA *exprintdata, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, int **rowidxs, int **colidxs, SCIP_Real **hessianvals, int *nnz)
type and macro definitions related to algebraic expressions
#define SCIP_Real
Definition: def.h:177
common defines and data types used in all packages of SCIP
struct SCIP_ExprIntData SCIP_EXPRINTDATA