source: branches/Couenne/Couenne/src/include/exprUnary.h @ 472

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

fixed minor bug in linearize.cpp. Changed assumption in BabPtr_ -> bestObj()

File size: 2.7 KB
Line 
1/*
2 * Name:    exprUnary.h
3 * Author:  Pietro Belotti
4 * Purpose: definition of the class for univariate functions
5 *
6 * (C) Pietro Belotti. This file is licensed under the Common Public License (CPL)
7 */
8
9#ifndef COUENNE_EXPRUNARY_H
10#define COUENNE_EXPRUNARY_H
11
12#include <iostream>
13
14#include <expression.h>
15#include <CouenneTypes.h>
16#include <exprOp.h>
17
18/// zero function (used by default by exprUnary)
19inline CouNumber zero_fun (CouNumber x) 
20{return 0;}
21
22
23//
24// univariate operator-type expression: requires single argument. All
25// unary functions are derived from this base class, which has a lot
26// of common methods that need not be re-implemented by any univariate
27// class.
28//
29
30class exprUnary: public expression {
31
32 protected:
33
34  expression *argument_; //< single argument taken by this expression
35
36 public:
37
38  /// node type
39  virtual inline enum nodeType Type () 
40    {return UNARY;}
41
42  /// Constructor
43  exprUnary  (expression *argument): 
44    argument_ (argument)        //< non-leaf expression, with argument list
45   {}
46
47  /// the operator itself (e.g. sin, log...)
48  virtual inline unary_function F () 
49    {return zero_fun;}
50
51  /// Destructor
52  ~exprUnary () 
53    {if (argument_) delete argument_;}
54
55  /// return number of arguments
56  inline int nArgs () const
57    {return 1;}
58
59  /// return argument (when applicable, i.e., with univariate functions)
60  virtual inline expression *Argument () const
61    {return argument_;}
62
63  /// return pointer to argument (when applicable, i.e., with univariate functions)
64  virtual inline expression **ArgPtr () 
65    {return &argument_;}
66
67  // I/O
68  virtual void print (std::ostream &, const std::string &, enum pos) const;
69
70  // compute value of unary operator
71  virtual inline CouNumber operator () ()
72    {return (currValue_ = (F ()) ((*argument_) ()));}
73
74  // dependence on variable set
75  bool inline dependsOn (int *list, int n) 
76    {return argument_ -> dependsOn (list, n);}
77
78  // simplification
79  expression *simplify ();
80
81  // get a measure of "how linear" the expression is (see CouenneTypes.h)
82  // for general univariate functions, return nonlinear.
83  virtual inline int Linearity ()
84    {return NONLINEAR;}
85
86  // reduce expression in standard form, creating additional aux
87  // variables (and constraints)
88  virtual exprAux *standardize (CouenneProblem *);
89
90  // return an index to the variable's argument that is better fixed
91  // in a branching rule for solving a nonconvexity gap
92  virtual expression *getFixVar () 
93    {return argument_;}
94
95  /// type of operator
96  virtual enum expr_type code () 
97    {return COU_EXPRUNARY;}
98
99  /// compare two unary functions
100  virtual int compare (exprUnary &); 
101
102  /// used in rank-based branching variable choice
103  virtual int rank (CouenneProblem *p)
104    {return (1 + argument_ -> rank (p));} 
105};
106
107#endif
Note: See TracBrowser for help on using the repository browser.