PySCIPOpt  5.1.1
Python Interface for the SCIP Optimization Suite
expr.pxi File Reference

In this file we implemenet the handling of expressions. More...

Go to the source code of this file.

Classes

class  Constant
 
class  Expr
 
class  ExprCons
 
class  GenExpr
 
class  Op
 
class  PowExpr
 
class  ProdExpr
 
class  SumExpr
 
class  Term
 
class  UnaryExpr
 
class  VarExpr
 

Namespaces

 pyscipopt.expr
 

Functions

def buildGenExprObj (expr)
 
def cos (expr)
 
def exp (expr)
 
def expr_to_array (expr, nodes)
 
def expr_to_nodes (expr)
 
def log (expr)
 
def quickprod (termlist)
 
def quicksum (termlist)
 
def sin (expr)
 
def sqrt (expr)
 
def value_to_array (val, nodes)
 

Variables

 CONST = Term()
 
 Operator = Op()
 

Detailed Description

In this file we implemenet the handling of expressions.

 We have two types of expressions: Expr and GenExpr.
 The Expr can only handle polynomial expressions.
 In addition, one can recover easily information from them.
 A polynomial is a dictionary between `terms` and coefficients.
 A `term` is a tuple of variables
 For examples, 2*x*x*y*z - 1.3 x*y*y + 1 is stored as a
 {Term(x,x,y,z) : 2, Term(x,y,y) : -1.3, Term() : 1}
 Addition of common terms and expansion of exponents occur automatically.
 Given the way `Expr`s are stored, it is easy to access the terms: e.g.
 expr = 2*x*x*y*z - 1.3 x*y*y + 1
 expr[Term(x,x,y,z)] returns 1.3
 expr[Term(x)] returns 0.0
 On the other hand, when dealing with expressions more general than polynomials,
 that is, absolute values, exp, log, sqrt or any general exponent, we use GenExpr.
 GenExpr stores expression trees in a rudimentary way.
 Basically, it stores the operator and the list of children.
 We have different types of general expressions that in addition
 to the operation and list of children stores
 SumExpr: coefficients and constant
 ProdExpr: constant
 Constant: constant
 VarExpr: variable
 PowExpr: exponent
 UnaryExpr: nothing
 We do not provide any way of accessing the internal information of the expression tree,
 nor we simplify common terms or do any other type of simplification.
 The `GenExpr` is pass as is to SCIP and SCIP will do what it see fits during presolving.
 TODO: All this is very complicated, so we might wanna unify Expr and GenExpr.
 Maybe when consexpr is released it makes sense to revisit this.
 TODO: We have to think about the operations that we define: __isub__, __add__, etc
 and when to copy expressions and when to not copy them.
 For example: when creating a ExprCons from an Expr expr, we store the expression expr
 and then we normalize. When doing the normalization, we do
 ```
 c = self.expr[CONST]
 self.expr -= c
 ```
 which should, in princple, modify the expr. However, since we do not implement __isub__, __sub__
 gets called (I guess) and so a copy is returned.
 Modifying the expression directly would be a bug, given that the expression might be re-used by the user. 

Definition in file expr.pxi.