cartesian-heart.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <gecode/driver.hh>
00039
00040 #include <gecode/minimodel.hh>
00041 #include <gecode/float.hh>
00042
00043 using namespace Gecode;
00044
00067 class CartesianHeart : public Script {
00068 protected:
00070 FloatVarArray f;
00072 FloatNum step;
00073 public:
00075 CartesianHeart(const Options& opt)
00076 : Script(opt), f(*this,2,-20,20), step(opt.step()) {
00077 int q = 2;
00078 FloatNum p = 0.5;
00079
00080 rel(*this, sqr(f[0]) + 2*sqr(f[1]-p*nroot(abs(f[0]),q)) == 1);
00081 branch(*this, f[0], FLOAT_VAL_SPLIT_MIN());
00082 branch(*this, f[1], FLOAT_VAL_SPLIT_MIN());
00083 }
00085 CartesianHeart(bool share, CartesianHeart& p)
00086 : Script(share,p), step(p.step) {
00087 f.update(*this,share,p.f);
00088 }
00090 virtual Space* copy(bool share) {
00091 return new CartesianHeart(share,*this);
00092 }
00094 virtual void constrain(const Space& _b) {
00095 const CartesianHeart& b = static_cast<const CartesianHeart&>(_b);
00096 rel(*this,
00097 (f[0] >= (b.f[0].max()+step)) ||
00098 (f[1] >= (b.f[1].max()+step)) ||
00099 (f[1] <= (b.f[1].min()-step)));
00100 }
00102 virtual void print(std::ostream& os) const {
00103 os << "XY " << f[0].med() << " " << f[1].med()
00104 << std::endl;
00105 }
00106
00107 };
00108
00112 int main(int argc, char* argv[]) {
00113 Options opt("CartesianHeart");
00114 opt.solutions(0);
00115 opt.step(0.01);
00116 opt.parse(argc,argv);
00117 Script::run<CartesianHeart,BAB,Options>(opt);
00118 return 0;
00119 }
00120
00121