source: branches/Couenne/Couenne/src/expression/exprOp.h @ 534

Last change on this file since 534 was 534, checked in by pbelotti, 13 years ago

moved include files to make them doxygenable. Introduced three-way branching, with fixed intervals for now. Added check for small bound interval within all generateCuts()

File size: 3.5 KB
Line 
1/*
2 * Name:    exprOp.h
3 * Author:  Pietro Belotti
4 * Purpose: definition of the n-ary expression class
5 *
6 * (C) Pietro Belotti. This file is licensed under the Common Public License (CPL)
7 */
8
9#ifndef COUENNE_EXPROP_H
10#define COUENNE_EXPROP_H
11
12#include <iostream>
13
14#include <expression.h>
15#include <CouenneTypes.h>
16#include <exprUnary.h>
17
18
19/// general n-ary operator-type expression: requires argument
20/// list. All non-unary and non-leaf operators, i.e., sum,
21/// subtraction, multiplication, power, division, max, min, etc. are
22/// derived from this class.
23
24class exprOp: public expression {
25
26 protected:
27
28  expression **arglist_; //< argument list is an array of pointers to other expressions
29  int          nargs_;   //< number of arguments (cardinality of arglist)
30
31 public:
32
33  /// node type
34  virtual inline enum nodeType Type () 
35    {return N_ARY;}
36
37  /// Constructor
38  exprOp (expression **arglist, int nargs):  //< non-leaf expression, with argument list
39    arglist_ (arglist),
40    nargs_   (nargs)
41    {}
42
43  /// constructor with two arguments (for convenience)
44  exprOp (expression *arg0, expression *arg1):  //< two arguments
45    arglist_ (new expression * [2]),
46    nargs_   (2)
47    {arglist_ [0] = arg0; arglist_ [1] = arg1;}
48
49  /// destructor
50  ~exprOp ();
51
52  /// copy constructor
53  exprOp (const exprOp &e):
54    arglist_ (new expression * [e.nArgs ()]),
55    nargs_   (e.nArgs ()) {
56
57  }
58
59  /// cloning method
60  virtual expression *clone () const
61    {return new exprOp (*this);}
62
63  /// return argument list
64  inline expression **ArgList () const 
65    {return arglist_;}
66
67  /// return number of arguments
68  inline int nArgs () const 
69    {return nargs_;}
70
71  /// I/O
72  virtual void print (std::ostream &, const std::string &, enum pos) const;
73
74  /// function for the evaluation of the expression
75  virtual inline CouNumber operator () ();
76
77  /// dependence on variable set
78  virtual bool dependsOn (int *, int);
79
80  /// simplification
81  virtual expression *simplify ();
82
83  /// clone argument list (for use with clone method
84  expression **clonearglist () const {
85    if (nargs_) {
86      expression **al = new expression * [nargs_];
87      for (register int i=0; i<nargs_; i++)
88        al [i] = arglist_ [i] -> clone ();
89      return al;
90    } else return NULL;
91  }
92
93  /// compress argument list
94  int shrink_arglist (CouNumber, CouNumber);
95
96  /// get a measure of "how linear" the expression is (see CouenneTypes.h)
97  virtual inline int Linearity ()
98    {return NONLINEAR;}
99
100  /// generate auxiliary variable
101  exprAux *standardize (CouenneProblem *);
102
103  /// return an index to the variable's argument that is better fixed
104  /// in a branching rule for solving a nonconvexity gap
105  virtual expression *getFixVar ()
106    {printf ("### Warning: called empty exprOp::getFixVar()\n"); return arglist_ [0];}
107
108  /// return code to classify type of expression
109  virtual enum expr_type code ()
110    {return COU_EXPROP;}
111
112  /// compare with other generic exprOp
113  virtual int compare (exprOp &);
114
115  /// used in rank-based branching variable choice
116  virtual int rank (CouenneProblem *);
117};
118
119
120/// expression evaluation -- n-ary operator (non-variable, non-constant)
121
122inline CouNumber exprOp::operator () () {
123
124  /// Fetch argument list and compute it "recursively" (the operator()
125  /// of the elements in the list is called) to fill in the vector
126  /// containing the numerical value of the argument list.
127
128  register expression **al = arglist_;
129
130  for (register int i = nargs_; i--;) 
131    *++sp = (**al++) ();
132
133  return 0;
134}
135
136#endif
Note: See TracBrowser for help on using the repository browser.