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-2014 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 email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file exprinterpret.h
17  * @brief methods to interpret (evaluate) an expression tree "fast"
18  * @author Stefan Vigerske
19  * @author Thorsten Gellermann
20  * Realized similar to LPI: one implementation of an interpreter is linked in.
21  */
22 
23 /* @todo product Gradient times vector
24  @todo product Hessian times vector
25  @todo product Hessian of Lagrangian times vector
26  @todo sparse Hessian of expression tree
27  @todo sparse Hessian of Lagrangian (sets of expression trees and quadratic parts)?
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"
36 #include "blockmemshell/memory.h"
37 #include "nlpi/type_expr.h"
39 #include "scip/intervalarith.h"
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /** gets name and version of expression interpreter */
46 extern
47 const char* SCIPexprintGetName(void);
48 
49 /** gets descriptive text of expression interpreter */
50 extern
51 const char* SCIPexprintGetDesc(void);
52 
53 /** gets capabilities of expression interpreter (using bitflags) */
54 extern
56 
57 /** creates an expression interpreter object */
58 extern
60  BMS_BLKMEM* blkmem, /**< block memory data structure */
61  SCIP_EXPRINT** exprint /**< buffer to store pointer to expression interpreter */
62  );
63 
64 /** frees an expression interpreter object */
65 extern
67  SCIP_EXPRINT** exprint /**< expression interpreter that should be freed */
68  );
69 
70 /** compiles an expression tree and stores compiled data in expression tree */
71 extern
73  SCIP_EXPRINT* exprint, /**< interpreter data structure */
74  SCIP_EXPRTREE* tree /**< expression tree */
75  );
76 
77 /** frees interpreter data */
78 extern
80  SCIP_EXPRINTDATA** interpreterdata /**< interpreter data that should freed */
81  );
82 
83 /** notify expression interpreter that a new parameterization is used
84  * this probably causes retaping by AD algorithms
85  */
86 extern
88  SCIP_EXPRINT* exprint, /**< interpreter data structure */
89  SCIP_EXPRTREE* tree /**< expression tree */
90  );
91 
92 /** evaluates an expression tree */
93 extern
95  SCIP_EXPRINT* exprint, /**< interpreter data structure */
96  SCIP_EXPRTREE* tree, /**< expression tree */
97  SCIP_Real* varvals, /**< values of variables */
98  SCIP_Real* val /**< buffer to store value of expression */
99  );
100 
101 /** evaluates an expression tree on intervals */
102 extern
104  SCIP_EXPRINT* exprint, /**< interpreter data structure */
105  SCIP_EXPRTREE* tree, /**< expression tree */
106  SCIP_Real infinity, /**< value for infinity */
107  SCIP_INTERVAL* varvals, /**< interval values of variables */
108  SCIP_INTERVAL* val /**< buffer to store interval value of expression */
109  );
110 
111 /** computes value and gradient of an expression tree */
112 extern
114  SCIP_EXPRINT* exprint, /**< interpreter data structure */
115  SCIP_EXPRTREE* tree, /**< expression tree */
116  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
117  SCIP_Bool new_varvals, /**< have variable values changed since last call to a point evaluation routine? */
118  SCIP_Real* val, /**< buffer to store expression value */
119  SCIP_Real* gradient /**< buffer to store expression gradient, need to have length at least SCIPexprtreeGetNVars(tree) */
120  );
121 
122 /** computes interval value and interval gradient of an expression tree */
123 extern
125  SCIP_EXPRINT* exprint, /**< interpreter data structure */
126  SCIP_EXPRTREE* tree, /**< expression tree */
127  SCIP_Real infinity, /**< value for infinity */
128  SCIP_INTERVAL* varvals, /**< interval values of variables, can be NULL if new_varvals is FALSE */
129  SCIP_Bool new_varvals, /**< have variable interval values changed since last call to an interval evaluation routine? */
130  SCIP_INTERVAL* val, /**< buffer to store expression interval value */
131  SCIP_INTERVAL* gradient /**< buffer to store expression interval gradient, need to have length at least SCIPexprtreeGetNVars(tree) */
132  );
133 
134 /** gives sparsity pattern of hessian
135  *
136  * NOTE: this function might be replaced later by something nicer.
137  * Since the AD code might need to do a forward sweep, you should pass variable values in here.
138  */
139 extern
141  SCIP_EXPRINT* exprint, /**< interpreter data structure */
142  SCIP_EXPRTREE* tree, /**< expression tree */
143  SCIP_Real* varvals, /**< values of variables */
144  SCIP_Bool* sparsity /**< buffer to store sparsity pattern of Hessian, sparsity[i+n*j] indicates whether entry (i,j) is nonzero in the hessian */
145  );
146 
147 /** computes value and dense hessian of an expression tree
148  *
149  * The full hessian is computed (lower left and upper right triangle).
150  */
151 extern
153  SCIP_EXPRINT* exprint, /**< interpreter data structure */
154  SCIP_EXPRTREE* tree, /**< expression tree */
155  SCIP_Real* varvals, /**< values of variables, can be NULL if new_varvals is FALSE */
156  SCIP_Bool new_varvals, /**< have variable values changed since last call to an evaluation routine? */
157  SCIP_Real* val, /**< buffer to store function value */
158  SCIP_Real* hessian /**< buffer to store hessian values, need to have size at least n*n */
159  );
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 #endif /* __SCIP_EXPRINTERPRET_H__ */
SCIP_RETCODE SCIPexprintNewParametrization(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
SCIP_RETCODE SCIPexprintCompile(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree)
SCIP_RETCODE SCIPexprintEvalInt(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real infinity, SCIP_INTERVAL *varvals, SCIP_INTERVAL *val)
type definitions for expression interpreter
SCIP_RETCODE SCIPexprintFreeData(SCIP_EXPRINTDATA **interpreterdata)
SCIP_EXPRINTCAPABILITY SCIPexprintGetCapability(void)
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
unsigned int SCIP_EXPRINTCAPABILITY
SCIP_RETCODE SCIPexprintCreate(BMS_BLKMEM *blkmem, SCIP_EXPRINT **exprint)
SCIP_RETCODE SCIPexprintGradInt(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real infinity, SCIP_INTERVAL *varvals, SCIP_Bool new_varvals, SCIP_INTERVAL *val, SCIP_INTERVAL *gradient)
SCIP_RETCODE SCIPexprintHessianDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *hessian)
struct SCIP_ExprTree SCIP_EXPRTREE
Definition: type_expr.h:91
#define SCIP_Bool
Definition: def.h:49
struct SCIP_ExprInt SCIP_EXPRINT
type definitions for expressions and expression trees
#define SCIP_Real
Definition: def.h:123
const char * SCIPexprintGetName(void)
SCIP_RETCODE SCIPexprintHessianSparsityDense(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool *sparsity)
common defines and data types used in all packages of SCIP
const char * SCIPexprintGetDesc(void)
struct SCIP_ExprIntData SCIP_EXPRINTDATA
SCIP_RETCODE SCIPexprintGrad(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Bool new_varvals, SCIP_Real *val, SCIP_Real *gradient)
SCIP_RETCODE SCIPexprintEval(SCIP_EXPRINT *exprint, SCIP_EXPRTREE *tree, SCIP_Real *varvals, SCIP_Real *val)
SCIP_RETCODE SCIPexprintFree(SCIP_EXPRINT **exprint)