Scippy

SCIP

Solving Constraint Integer Programs

exprinterpret_none.c
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-2023 Zuse Institute Berlin (ZIB) */
7 /* */
8 /* Licensed under the Apache License, Version 2.0 (the "License"); */
9 /* you may not use this file except in compliance with the License. */
10 /* You may obtain a copy of the License at */
11 /* */
12 /* http://www.apache.org/licenses/LICENSE-2.0 */
13 /* */
14 /* Unless required by applicable law or agreed to in writing, software */
15 /* distributed under the License is distributed on an "AS IS" BASIS, */
16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17 /* See the License for the specific language governing permissions and */
18 /* limitations under the License. */
19 /* */
20 /* You should have received a copy of the Apache-2.0 license */
21 /* along with SCIP; see the file LICENSE. If not visit scipopt.org. */
22 /* */
23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 
25 /**@file exprinterpret_none.c
26  * @brief function definitions for nonexisting expression interpreter to resolve linking references
27  * @ingroup DEFPLUGINS_EXPRINT
28  * @author Stefan Vigerske
29  */
30 
31 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
32 
33 #include "scip/pub_message.h"
34 #include "scip/exprinterpret.h"
35 
36 /** gets name and version of expression interpreter */
37 const char* SCIPexprintGetName(
38  void
39  )
40 {
41  return "NONE";
42 } /*lint !e715*/
43 
44 /** gets descriptive text of expression interpreter */
45 const char* SCIPexprintGetDesc(
46  void
47  )
48 {
49  return "dummy expression interpreter which sole purpose it is to resolve linking symbols";
50 } /*lint !e715*/
51 
52 /** gets capabilities of expression interpreter (using bitflags) */
54  void
55  )
56 {
58 } /*lint !e715*/
59 
60 /** creates an expression interpreter object */
62  SCIP* scip, /**< SCIP data structure */
63  SCIP_EXPRINT** exprint /**< buffer to store pointer to expression interpreter */
64  )
65 {
66  *exprint = (SCIP_EXPRINT*)1u; /* some code checks that a non-NULL pointer is returned here, even though it may not point anywhere */
67 
68  return SCIP_OKAY;
69 } /*lint !e715*/
70 
71 /** frees an expression interpreter object */
73  SCIP* scip, /**< SCIP data structure */
74  SCIP_EXPRINT** exprint /**< expression interpreter that should be freed */
75  )
76 {
77  *exprint = NULL;
78 
79  return SCIP_OKAY;
80 } /*lint !e715*/
81 
82 /** compiles an expression and returns interpreter-specific data for expression
83  *
84  * can be called again with existing exprintdata if expression has been changed
85  *
86  * @attention *exprintdata needs to be initialized to NULL at first call
87  * @attention the expression is assumed to use varidx expressions instead of var expressions
88  */
90  SCIP* scip, /**< SCIP data structure */
91  SCIP_EXPRINT* exprint, /**< interpreter data structure */
92  SCIP_EXPR* expr, /**< expression */
93  SCIP_EXPRINTDATA** exprintdata /**< buffer to store pointer to compiled data */
94  )
95 {
96  return SCIP_OKAY;
97 } /*lint !e715*/
98 
99 /** frees interpreter data for expression */
101  SCIP* scip, /**< SCIP data structure */
102  SCIP_EXPRINT* exprint, /**< interpreter data structure */
103  SCIP_EXPR* expr, /**< expression */
104  SCIP_EXPRINTDATA** exprintdata /**< pointer to pointer to compiled data to be freed */
105  )
106 {
107  assert(exprintdata != NULL);
108  assert(*exprintdata == NULL);
109 
110  return SCIP_OKAY;
111 } /*lint !e715*/
112 
113 /** gives the capability to evaluate an expression by the expression interpreter
114  *
115  * In cases of user-given expressions, higher order derivatives may not be available for the user-expression,
116  * even if the expression interpreter could handle these. This method allows to recognize that, e.g., the
117  * Hessian for an expression is not available because it contains a user expression that does not provide
118  * Hessians.
119  */
121  SCIP* scip, /**< SCIP data structure */
122  SCIP_EXPRINT* exprint, /**< interpreter data structure */
123  SCIP_EXPR* expr, /**< expression */
124  SCIP_EXPRINTDATA* exprintdata /**< interpreter-specific data for expression */
125  )
126 {
128 } /*lint !e715*/
129 
130 /** evaluates an expression */
132  SCIP* scip, /**< SCIP data structure */
133  SCIP_EXPRINT* exprint, /**< interpreter data structure */
134  SCIP_EXPR* expr, /**< expression */
135  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
136  SCIP_Real* varvals, /**< values of variables */
137  SCIP_Real* val /**< buffer to store value of expression */
138  )
139 {
140  SCIPerrorMessage("No expression interpreter linked to SCIP, try recompiling with EXPRINT=cppad.\n");
141  return SCIP_PLUGINNOTFOUND;
142 } /*lint !e715*/
143 
144 /** computes value and gradient of an expression */
146  SCIP* scip, /**< SCIP data structure */
147  SCIP_EXPRINT* exprint, /**< interpreter data structure */
148  SCIP_EXPR* expr, /**< expression */
149  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
150  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
151  SCIP_Bool new_varvals, /**< have variable values changed since last call to a point evaluation routine? */
152  SCIP_Real* val, /**< buffer to store expression value */
153  SCIP_Real* gradient /**< buffer to store expression gradient */
154  )
155 {
156  SCIPerrorMessage("No expression interpreter linked to SCIP, try recompiling with EXPRINT=cppad.\n");
157  return SCIP_PLUGINNOTFOUND;
158 } /*lint !e715*/
159 
160 /** gives sparsity pattern of lower-triangular part of Hessian
161  *
162  * Since the AD code might need to do a forward sweep, variable values need to be passed in here.
163  *
164  * Result will have `(*colidxs)[i] <= (*rowidixs)[i]` for `i=0..*nnz`.
165  */
167  SCIP* scip, /**< SCIP data structure */
168  SCIP_EXPRINT* exprint, /**< interpreter data structure */
169  SCIP_EXPR* expr, /**< expression */
170  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
171  SCIP_Real* varvals, /**< values of variables */
172  int** rowidxs, /**< buffer to return array with row indices of Hessian elements */
173  int** colidxs, /**< buffer to return array with column indices of Hessian elements */
174  int* nnz /**< buffer to return length of arrays */
175  )
176 {
177  SCIPerrorMessage("No expression interpreter linked to SCIP, try recompiling with EXPRINT=cppad.\n");
178  return SCIP_PLUGINNOTFOUND;
179 } /*lint !e715*/
180 
181 /** computes value and Hessian of an expression
182  *
183  * Returned arrays `rowidxs` and `colidxs` and number of elements `nnz` are the same as given by SCIPexprintHessianSparsity().
184  * Returned array `hessianvals` will contain the corresponding Hessian elements.
185  */
187  SCIP* scip, /**< SCIP data structure */
188  SCIP_EXPRINT* exprint, /**< interpreter data structure */
189  SCIP_EXPR* expr, /**< expression */
190  SCIP_EXPRINTDATA* exprintdata, /**< interpreter-specific data for expression */
191  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
192  SCIP_Bool new_varvals, /**< have variable values changed since last call to an evaluation routine? */
193  SCIP_Real* val, /**< buffer to store function value */
194  int** rowidxs, /**< buffer to return array with row indices of Hessian elements */
195  int** colidxs, /**< buffer to return array with column indices of Hessian elements */
196  SCIP_Real** hessianvals, /**< buffer to return array with Hessian elements */
197  int* nnz /**< buffer to return length of arrays */
198  )
199 {
200  SCIPerrorMessage("No expression interpreter linked to SCIP, try recompiling with EXPRINT=cppad.\n");
201  return SCIP_PLUGINNOTFOUND;
202 } /*lint !e715*/
const char * SCIPexprintGetName(void)
methods to interpret (evaluate) an expression "fast"
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)
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:63
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
#define SCIPerrorMessage
Definition: pub_message.h:64
#define NULL
Definition: lpi_spx1.cpp:164
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:93
SCIP_RETCODE SCIPexprintFree(SCIP *scip, SCIP_EXPRINT **exprint)
struct SCIP_ExprInt SCIP_EXPRINT
#define SCIP_EXPRINTCAPABILITY_NONE
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)
public methods for message output
#define SCIP_Real
Definition: def.h:186
struct SCIP_ExprIntData SCIP_EXPRINTDATA