00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vector>
00019
00020 #include "BoundsCheck.h"
00021 #include <Sym.h>
00022 #include <FunDef.h>
00023 #include <sstream>
00024
00025 using namespace std;
00026
00027 class IntervalBoundsCheckImpl {
00028 public :
00029 vector<Interval> bounds;
00030 };
00031
00032 IntervalBoundsCheck::IntervalBoundsCheck(const vector<double>& mins, const vector<double>& maxes) {
00033 pimpl = new IntervalBoundsCheckImpl;
00034 vector<Interval>& b = pimpl->bounds;
00035
00036 b.resize( mins.size());
00037
00038 for (unsigned i = 0; i < b.size(); ++i) {
00039 b[i] = Interval(mins[i], maxes[i]);
00040 }
00041
00042 }
00043
00044 IntervalBoundsCheck::~IntervalBoundsCheck() { delete pimpl; }
00045 IntervalBoundsCheck::IntervalBoundsCheck(const IntervalBoundsCheck& that) { pimpl = new IntervalBoundsCheckImpl(*that.pimpl); }
00046 IntervalBoundsCheck& IntervalBoundsCheck::operator=(const IntervalBoundsCheck& that) { *pimpl = *that.pimpl; return *this; }
00047
00048 bool IntervalBoundsCheck::in_bounds(const Sym& sym) const {
00049 Interval bounds;
00050
00051 try {
00052 bounds = eval(sym, pimpl->bounds);
00053 if (!valid(bounds)) return false;
00054 } catch (interval_error) {
00055 return false;
00056 }
00057 return true;
00058 }
00059
00060 std::string IntervalBoundsCheck::get_bounds(const Sym& sym) const {
00061
00062 try {
00063 Interval bounds = eval(sym, pimpl->bounds);
00064 if (!valid(bounds)) return "err";
00065 ostringstream os;
00066 os << bounds;
00067 return os.str();
00068 } catch (interval_error) {
00069 return "err";
00070 }
00071 }
00072
00073
00074 std::pair<double, double> IntervalBoundsCheck::calc_bounds(const Sym& sym) const {
00075
00076 Interval bounds = eval(sym, pimpl->bounds);
00077 return make_pair(bounds.lower(), bounds.upper());
00078 }
00079
00080