MC++
mcop.hpp
1 // Copyright (C) 2009-2014 Benoit Chachuat, Imperial College London.
2 // All Rights Reserved.
3 
4 #ifndef MC__MCOP_HPP
5 #define MC__MCOP_HPP
6 
7 #include <stdexcept>
8 
9 namespace mc
10 {
12 template <typename T>
13 struct Op
14 {
15  static T point( const double c ) { return T(c); } // { throw std::runtime_error("mc::Op<T>::point -- Function not overloaded"); }
16  static T zeroone() { return T(0,1); }
17  static void I(T& x, const T& y) { x = y; }
18  static double l(const T& x) { return x.l(); }
19  static double u(const T& x) { return x.u(); }
20  static double abs (const T& x) { return abs(x); }
21  static double mid (const T& x) { return mid(x); }
22  static double diam(const T& x) { return diam(x); }
23  static T inv (const T& x) { return inv(x); }
24  static T sqr (const T& x) { return sqr(x); }
25  static T sqrt(const T& x) { return sqrt(x); }
26  static T log (const T& x) { return log(x); }
27  static T xlog(const T& x) { return xlog(x); }
28  static T fabs(const T& x) { return fabs(x); }
29  static T exp (const T& x) { return exp(x); }
30  static T sin (const T& x) { return sin(x); }
31  static T cos (const T& x) { return cos(x); }
32  static T tan (const T& x) { return tan(x); }
33  static T asin(const T& x) { return asin(x); }
34  static T acos(const T& x) { return acos(x); }
35  static T atan(const T& x) { return atan(x); }
36  static T erf (const T& x) { return erf(x); }
37  static T erfc(const T& x) { return erfc(x); }
38  static T fstep(const T& x) { return fstep(x); }
39  static T bstep(const T& x) { return bstep(x); }
40  static T hull(const T& x, const T& y) { return hull(x,y); }
41  static T min (const T& x, const T& y) { return min(x,y); }
42  static T max (const T& x, const T& y) { return max(x,y); }
43  static T arh (const T& x, const double k) { return arh(x,k); }
44  template <typename X, typename Y> static T pow(const X& x, const Y& y) { return pow(x,y); }
45  static T monomial (const unsigned int n, const T* x, const int* k) { return monomial(n,x,k); }
46  static bool inter(T& xIy, const T& x, const T& y) { return inter(xIy,x,y); }
47  static bool eq(const T& x, const T& y) { return x==y; }
48  static bool ne(const T& x, const T& y) { return x!=y; }
49  static bool lt(const T& x, const T& y) { return x<y; }
50  static bool le(const T& x, const T& y) { return x<=y; }
51  static bool gt(const T& x, const T& y) { return x>y; }
52  static bool ge(const T& x, const T& y) { return x>=y; }
53 };
54 }
55 
56 #include <cmath>
57 #include "mcfunc.hpp"
58 
59 namespace mc
60 {
62 template <>
63 struct Op<double>
64 {
65  typedef double T;
66  static T inv (const T& x) { return 1./x; }
67  static T sqr (const T& x) { return x*x; }
68  static T sqrt(const T& x) { return std::sqrt(x); }
69  static T log (const T& x) { return std::log(x); }
70  static T xlog(const T& x) { return mc::xlog(x); }
71  static T fabs(const T& x) { return std::fabs(x); }
72  static T exp (const T& x) { return std::exp(x); }
73  static T sin (const T& x) { return std::sin(x); }
74  static T cos (const T& x) { return std::cos(x); }
75  static T tan (const T& x) { return std::tan(x); }
76  static T asin(const T& x) { return std::asin(x); }
77  static T acos(const T& x) { return std::acos(x); }
78  static T atan(const T& x) { return std::atan(x); }
79  static T erf (const T& x) { return ::erf(x); }
80  static T erfc(const T& x) { return ::erfc(x); }
81  static T fstep(const T& x) { return fstep(x); }
82  static T bstep(const T& x) { return bstep(x); }
83  static T min (const T& x, const T& y) { return min(x,y); }
84  static T max (const T& x, const T& y) { return max(x,y); }
85  static T arh (const T& x, const double k) { return arh(x,k); }
86  template <typename X, typename Y> static T pow(const X& x, const Y& y) { return std::pow(x,y); }
87  static T monomial (const unsigned int n, const T* x, const int* k) { return mc::monomial(n,x,k); }
88  static bool eq(const T& x, const T& y) { return x==y; }
89  static bool ne(const T& x, const T& y) { return x!=y; }
90  static bool lt(const T& x, const T& y) { return x<y; }
91  static bool le(const T& x, const T& y) { return x<=y; }
92  static bool gt(const T& x, const T& y) { return x>y; }
93  static bool ge(const T& x, const T& y) { return x>=y; }
94 };
95 }
96 #endif
C++ structure to allow usage of various template parameters in the types mc::McCormick, mc::TModel, mc::TVar, and mc::SpecBnd of MC++ _ Specialization of this structure is required for the template parameters can be found in the header files defining the types mc::McCormick, mc::TModel, mc::TVar, and mc::SpecBnd.
Definition: mcop.hpp:13