Couenne  0.5.7
CouenneExprOp.hpp
Go to the documentation of this file.
1 /* $Id: CouenneExprOp.hpp 490 2011-01-14 16:07:12Z pbelotti $
2  *
3  * Name: exprOp.hpp
4  * Author: Pietro Belotti
5  * Purpose: definition of the n-ary expression class
6  *
7  * (C) Carnegie-Mellon University, 2006-08.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #ifndef COUENNE_EXPROP_HPP
12 #define COUENNE_EXPROP_HPP
13 
14 #include <iostream>
15 
16 #include "CouenneExpression.hpp"
17 #include "CouenneTypes.hpp"
18 
19 namespace Couenne {
20 
21 #define MAX_ARG_LINE 10
22 
23 class CouenneProblem;
24 class Domain;
25 
30 
31 class exprOp: public expression {
32 
33  protected:
34 
36  int nargs_;
37 
38  public:
39 
41  virtual inline enum nodeType Type () const
42  {return N_ARY;}
43 
45  exprOp (expression **arglist, int nargs): //< non-leaf expression, with argument list
46  arglist_ (arglist),
47  nargs_ (nargs)
48  {}
49 
51  exprOp (expression *arg0, expression *arg1): //< two arguments
52  arglist_ (new expression * [2]),
53  nargs_ (2)
54  {arglist_ [0] = arg0; arglist_ [1] = arg1;}
55 
57  virtual ~exprOp ();
58 
61  exprOp (const exprOp &e, Domain *d = NULL):
62  arglist_ (new expression * [e.nArgs ()]),
63  nargs_ (e.nArgs ()) {}
64 
66  inline expression **ArgList () const
67  {return arglist_;}
68 
70  virtual inline void ArgList (expression **al)
71  {arglist_ = al;}
72 
74  inline int nArgs () const
75  {return nargs_;}
76 
78  virtual void print (std::ostream &out = std::cout,
79  bool = false) const;
80 
82  virtual enum pos printPos () const
83  {return INSIDE;}
84 
86  virtual std::string printOp () const
87  {return "??";}
88 
91  virtual int DepList (std::set <int> &deplist, enum dig_type type = ORIG_ONLY);
92 
94  virtual expression *simplify ();
95 
97  expression **clonearglist (Domain *d = NULL) const {
98  if (nargs_) {
99  expression **al = new expression * [nargs_];
100  for (register int i=0; i<nargs_; i++)
101  al [i] = arglist_ [i] -> clone (d);
102  return al;
103  } else return NULL;
104  }
105 
108 
110  virtual inline int Linearity ()
111  {return NONLINEAR;}
112 
114  virtual exprAux *standardize (CouenneProblem *, bool addAux = true);
115 
117  virtual inline enum expr_type code ()
118  {return COU_EXPROP;}
119 
121  virtual bool isInteger ();
122 
124  virtual int compare (exprOp &);
125 
127  virtual int rank ();
128 
131  virtual void fillDepSet (std::set <DepNode *, compNode> *dep, DepGraph *g) {
132  for (int i=nargs_; i--;)
133  arglist_ [i] -> fillDepSet (dep, g);
134  }
135 
137  virtual void replace (exprVar *, exprVar *);
138 
140  virtual void realign (const CouenneProblem *p);
141 };
142 
143 }
144 
145 #endif
virtual expression * clone(Domain *d=NULL) const
Cloning method.
virtual exprAux * standardize(CouenneProblem *, bool addAux=true)
generate auxiliary variable
variable-type operator
expression ** arglist_
argument list is an array of pointers to other expressions
int nArgs() const
return number of arguments
virtual enum pos printPos() const
print position (PRE, INSIDE, POST)
virtual enum expr_type code()
return code to classify type of expression
pos
position where the operator should be printed when printing the expression
virtual enum nodeType Type() const
Node type.
virtual void ArgList(expression **al)
set arglist (used in deleting nodes without deleting children)
expr_type
code returned by the method expression::code()
Number Number * g
virtual ~exprOp()
Destructor.
int nargs_
number of arguments (cardinality of arglist)
general n-ary operator-type expression: requires argument list.
double CouNumber
main number type in Couenne
virtual std::string printOp() const
print operator
virtual bool isInteger()
is this expression integer?
virtual int DepList(std::set< int > &deplist, enum dig_type type=ORIG_ONLY)
fill in the set with all indices of variables appearing in the expression
virtual int rank()
used in rank-based branching variable choice
Class for MINLP problems with symbolic information.
expression ** clonearglist(Domain *d=NULL) const
clone argument list (for use with clone method)
dig_type
type of digging when filling the dependence list
Define a dynamic point+bounds, with a way to save and restore previous points+bounds through a LIFO s...
nodeType
type of a node in an expression tree
exprOp(const exprOp &e, Domain *d=NULL)
Copy constructor: only allocate space for argument list, which will be copied with clonearglist()
virtual void fillDepSet(std::set< DepNode *, compNode > *dep, DepGraph *g)
fill in dependence structure update dependence set with index of this variable
Expression base class.
virtual void realign(const CouenneProblem *p)
empty function to redirect variables to proper variable vector
exprOp(expression **arglist, int nargs)
Constructor.
int shrink_arglist(CouNumber, CouNumber)
compress argument list
virtual expression * simplify()
simplification
expression ** ArgList() const
return argument list
Dependence graph.
virtual void replace(exprVar *, exprVar *)
replace variable with other
virtual int Linearity()
get a measure of "how linear" the expression is (see CouenneTypes.h)
virtual int compare(exprOp &)
compare with other generic exprOp
Auxiliary variable.
exprOp(expression *arg0, expression *arg1)
Constructor with two arguments (for convenience)
general include file for different compilers
virtual void print(std::ostream &out=std::cout, bool=false) const
I/O.