MC++
mcfilib.hpp
1 // Copyright (C) 2009-2013 Benoit Chachuat, Imperial College London.
2 // All Rights Reserved.
3 
4 #ifndef MC__MCFILIB_HPP
5 #define MC__MCFILIB_HPP
6 
7 #include "mcop.hpp"
8 #include "mcfunc.hpp"
9 #include "interval/interval.hpp"
10 namespace mc
11 {
13 template <> struct Op< filib::interval<double> >
14 {
15  typedef filib::interval<double> T;
16  static T point( const double c ) { return T(c); }
17  static T zeroone() { return T(0.,1.); }
18  static void I(T& x, const T& y) { x = y; }
19  static double l(const T& x) { return filib::inf(x); }
20  static double u(const T& x) { return filib::sup(x); }
21  static double abs (const T& x) { return filib::mag(x); }
22  static double mid (const T& x) { return filib::mid(x); }
23  static double diam(const T& x) { return filib::diam(x); }
24  static T inv (const T& x) { return T(1.)/x; }
25  static T sqr (const T& x) { return filib::sqr(x); }
26  static T sqrt(const T& x) { return filib::sqrt(x); }
27  static T log (const T& x) { return filib::log(x); }
28  static T xlog(const T& x) { return filib::log(x)*x; }
29  static T fabs(const T& x) { return filib::abs(x); }
30  static T exp (const T& x) { return filib::exp(x); }
31  static T sin (const T& x) { return filib::sin(x); }
32  static T cos (const T& x) { return filib::cos(x); }
33  static T tan (const T& x) { return filib::tan(x); }
34  static T asin(const T& x) { return filib::asin(x); }
35  static T acos(const T& x) { return filib::acos(x); }
36  static T atan(const T& x) { return filib::atan(x); }
37  static T hull(const T& x, const T& y) { return x.hull(y); }
38  static T min (const T& x, const T& y) { return x.imin(y); }
39  static T max (const T& x, const T& y) { return x.imax(y); }
40  static T arh (const T& x, const double k) { return filib::exp(-x/k); }
41  template <typename X> static T pow(const X& x, const int n) { return filib::power(x,n); }
42  template <typename X, typename Y> static T pow(const X& x, const Y& y) { return filib::pow(x,y); }
43  static T monomial (const unsigned int n, const T* x, const int* k) { return n? filib::power(x[0], k[0]) * monomial(n-1, x+1, k+1): 1.; }
44  static bool inter(T& xIy, const T& x, const T& y) { xIy = x.intersect(y); return true; }
45  static bool eq(const T& x, const T& y) { return x.seq(y); }
46  static bool ne(const T& x, const T& y) { return x.sne(y); }
47  static bool lt(const T& x, const T& y) { return x.slt(y); }
48  static bool le(const T& x, const T& y) { return x.sle(y); }
49  static bool gt(const T& x, const T& y) { return x.sgt(y); }
50  static bool ge(const T& x, const T& y) { return x.sge(y); }
51 };
52 
54 template <> struct Op< filib::interval<double,filib::native_switched,filib::i_mode_extended> >
55 {
56  typedef filib::interval<double,filib::native_switched,filib::i_mode_extended> T;
57  static T point( const double c ) { return T(c); }
58  static T zeroone() { return T(0.,1.); }
59  static void I(T& x, const T& y) { x = y; }
60  static double l(const T& x) { return filib::inf(x); }
61  static double u(const T& x) { return filib::sup(x); }
62  static double abs (const T& x) { return filib::mag(x); }
63  static double mid (const T& x) { return filib::mid(x); }
64  static double diam(const T& x) { return filib::diam(x); }
65  static T inv (const T& x) { return T(1.)/x; }
66  static T sqr (const T& x) { return filib::sqr(x); }
67  static T sqrt(const T& x) { return filib::sqrt(x); }
68  static T log (const T& x) { return filib::log(x); }
69  static T xlog(const T& x) { return filib::log(x)*x; }
70  static T fabs(const T& x) { return filib::abs(x); }
71  static T exp (const T& x) { return filib::exp(x); }
72  static T sin (const T& x) { return filib::sin(x); }
73  static T cos (const T& x) { return filib::cos(x); }
74  static T tan (const T& x) { return filib::tan(x); }
75  static T asin(const T& x) { return filib::asin(x); }
76  static T acos(const T& x) { return filib::acos(x); }
77  static T atan(const T& x) { return filib::atan(x); }
78  static T hull(const T& x, const T& y) { return x.hull(y); }
79  static T min (const T& x, const T& y) { return x.imin(y); }
80  static T max (const T& x, const T& y) { return x.imax(y); }
81  static T arh (const T& x, const double k) { return filib::exp(-x/k); }
82  template <typename X> static T pow(const X& x, const int n) { return filib::power(x,n); }
83  template <typename X, typename Y> static T pow(const X& x, const Y& y) { return filib::pow(x,y); }
84  static T monomial (const unsigned int n, const T* x, const int* k) { return n? filib::power(x[0], k[0]) * monomial(n-1, x+1, k+1): 1.; }
85  static bool inter(T& xIy, const T& x, const T& y) { xIy = x.intersect(y); return !xIy.isEmpty(); }
86  static bool eq(const T& x, const T& y) { return x.seq(y); }
87  static bool ne(const T& x, const T& y) { return x.sne(y); }
88  static bool lt(const T& x, const T& y) { return x.slt(y); }
89  static bool le(const T& x, const T& y) { return x.sle(y); }
90  static bool gt(const T& x, const T& y) { return x.sgt(y); }
91  static bool ge(const T& x, const T& y) { return x.sge(y); }
92 };
93 
94 } // namespace mc
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