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 #include <gecode/driver.hh>
00035
00036 #include <gecode/minimodel.hh>
00037 #include <gecode/float.hh>
00038
00039 using namespace Gecode;
00040
00063 class CartesianHeart : public Script {
00064 protected:
00066 FloatVarArray f;
00068 FloatNum step;
00069 public:
00071 CartesianHeart(const Options& opt)
00072 : Script(opt), f(*this,2,-20,20), step(opt.step()) {
00073 int q = 2;
00074 FloatNum p = 0.5;
00075
00076 rel(*this, sqr(f[0]) + 2*sqr(f[1]-p*nroot(abs(f[0]),q)) == 1);
00077 branch(*this, f[0], FLOAT_VAL_SPLIT_MIN());
00078 branch(*this, f[1], FLOAT_VAL_SPLIT_MIN());
00079 }
00081 CartesianHeart(CartesianHeart& p)
00082 : Script(p), step(p.step) {
00083 f.update(*this, p.f);
00084 }
00086 virtual Space* copy(void) {
00087 return new CartesianHeart(*this);
00088 }
00090 virtual void constrain(const Space& _b) {
00091 const CartesianHeart& b = static_cast<const CartesianHeart&>(_b);
00092 rel(*this,
00093 (f[0] >= (b.f[0].max()+step)) ||
00094 (f[1] >= (b.f[1].max()+step)) ||
00095 (f[1] <= (b.f[1].min()-step)));
00096 }
00098 virtual void print(std::ostream& os) const {
00099 os << "XY " << f[0].med() << " " << f[1].med()
00100 << std::endl;
00101 }
00102
00103 };
00104
00108 int main(int argc, char* argv[]) {
00109 Options opt("CartesianHeart");
00110 opt.solutions(0);
00111 opt.step(0.01);
00112 opt.parse(argc,argv);
00113 Script::run<CartesianHeart,BAB,Options>(opt);
00114 return 0;
00115 }
00116
00117