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 expr_sum.h 26 * @ingroup EXPRHDLRS 27 * @brief sum expression handler 28 * @author Stefan Vigerske 29 * @author Benjamin Mueller 30 */ 31 32 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ 33 34 #ifndef __SCIP_EXPR_SUM_H__ 35 #define __SCIP_EXPR_SUM_H__ 36 37 38 #include "scip/scip.h" 39 #include "scip/type_expr.h" 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** creates the handler for sum expressions and includes it into SCIP 46 * 47 * @ingroup ExprhdlrIncludes 48 */ 49 SCIP_EXPORT 50 SCIP_RETCODE SCIPincludeExprhdlrSum( 51 SCIP* scip /**< SCIP data structure */ 52 ); 53 54 /**@addtogroup EXPRHDLRS 55 * 56 * @{ 57 * 58 * @name Sum expression 59 * 60 * This expression handler provides the sum function, that is, 61 * \f[ 62 * x \mapsto c + \sum_{i=1}^n a_i x_i 63 * \f] 64 * for some constant c and constant coefficients \f$a_i\f$. 65 * 66 * @{ 67 */ 68 69 /** creates a sum expression */ 70 SCIP_EXPORT 71 SCIP_RETCODE SCIPcreateExprSum( 72 SCIP* scip, /**< SCIP data structure */ 73 SCIP_EXPR** expr, /**< pointer where to store expression */ 74 int nchildren, /**< number of children */ 75 SCIP_EXPR** children, /**< children */ 76 SCIP_Real* coefficients, /**< array with coefficients for all children (or NULL if all 1.0) */ 77 SCIP_Real constant, /**< constant term of sum */ 78 SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), /**< function to call to create ownerdata */ 79 void* ownercreatedata /**< data to pass to ownercreate */ 80 ); 81 82 /** sets the constant of a summation expression */ 83 SCIP_EXPORT 84 void SCIPsetConstantExprSum( 85 SCIP_EXPR* expr, /**< sum expression */ 86 SCIP_Real constant /**< constant */ 87 ); 88 89 /** appends an expression to a sum expression */ 90 SCIP_EXPORT 91 SCIP_RETCODE SCIPappendExprSumExpr( 92 SCIP* scip, /**< SCIP data structure */ 93 SCIP_EXPR* expr, /**< sum expression */ 94 SCIP_EXPR* child, /**< expression to be appended */ 95 SCIP_Real childcoef /**< child's coefficient */ 96 ); 97 98 /** multiplies given sum expression by a constant */ 99 SCIP_EXPORT 100 void SCIPmultiplyByConstantExprSum( 101 SCIP_EXPR* expr, /**< sum expression */ 102 SCIP_Real constant /**< constant that multiplies sum expression */ 103 ); 104 105 /** constructs the expanded product of two sum expressions */ 106 SCIP_EXPORT 107 SCIP_RETCODE SCIPmultiplyBySumExprSum( 108 SCIP* scip, /**< SCIP data structure */ 109 SCIP_EXPR** product, /**< buffer where to store multiplied sums (expanded as sum) */ 110 SCIP_EXPR* factor1, /**< first sum */ 111 SCIP_EXPR* factor2, /**< second sum */ 112 SCIP_Bool simplify, /**< whether to simplify created terms and sum */ 113 SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), /**< function to call to create ownerdata */ 114 void* ownercreatedata /**< data to pass to ownercreate */ 115 ); 116 117 /** constructs the expanded power of a sum expression 118 * 119 * @attention The number of terms in the expansion grows exponential with the exponent. Be aware of what you wish for. 120 */ 121 SCIP_EXPORT 122 SCIP_RETCODE SCIPpowerExprSum( 123 SCIP* scip, /**< SCIP data structure */ 124 SCIP_EXPR** result, /**< buffer where to store expanded power of sum */ 125 SCIP_EXPR* base, /**< sum */ 126 int exponent, /**< exponent > 1 */ 127 SCIP_Bool simplify, /**< whether to simplify created terms and sum */ 128 SCIP_DECL_EXPR_OWNERCREATE((*ownercreate)), /**< function to call to create ownerdata */ 129 void* ownercreatedata /**< data to pass to ownercreate */ 130 ); 131 132 /** @} 133 * @} 134 */ 135 136 #ifdef __cplusplus 137 } 138 #endif 139 140 #endif /* __SCIP_EXPR_SUM_H__ */ 141