PySCIPOpt
Python Interface to 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  Term
 
class  Expr
 
class  ExprCons
 
class  Op
 
class  GenExpr
 
class  SumExpr
 
class  ProdExpr
 
class  VarExpr
 
class  PowExpr
 
class  UnaryExpr
 
class  Constant
 

Functions

def buildGenExprObj (expr)
 
def quicksum (termlist)
 
def quickprod (termlist)
 
def exp (expr)
 
def log (expr)
 
def sqrt (expr)
 
def expr_to_nodes (expr)
 
def value_to_array (val, nodes)
 
def expr_to_array (expr, 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 Exprs 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

1 c = self.expr[CONST]
2 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.

Function Documentation

def pyscipopt.expr.buildGenExprObj (   expr)
helper function to generate an object of type GenExpr

Definition at line 115 of file expr.pxi.

def pyscipopt.expr.exp (   expr)
returns expression with exp-function

Definition at line 674 of file expr.pxi.

def pyscipopt.expr.expr_to_array (   expr,
  nodes 
)
adds expression to array

Definition at line 702 of file expr.pxi.

def pyscipopt.expr.expr_to_nodes (   expr)
transforms tree to an array of nodes. each node is an operator and the position of the 
children of that operator (i.e. the other nodes) in the array

Definition at line 684 of file expr.pxi.

def pyscipopt.expr.log (   expr)
returns expression with log-function

Definition at line 677 of file expr.pxi.

def pyscipopt.expr.quickprod (   termlist)
multiply linear expressions and constants by avoiding intermediate 
data structures and multiplying terms inplace

Definition at line 381 of file expr.pxi.

def pyscipopt.expr.quicksum (   termlist)
add linear expressions and constants much faster than Python's sum
by avoiding intermediate data structures and adding terms inplace

Definition at line 372 of file expr.pxi.

def pyscipopt.expr.sqrt (   expr)
returns expression with sqrt-function

Definition at line 680 of file expr.pxi.

def pyscipopt.expr.value_to_array (   val,
  nodes 
)
adds a given value to an array

Definition at line 692 of file expr.pxi.