Generated on Tue May 22 09:39:37 2018 for Gecode by doxygen 1.6.3

cartesian-heart.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Vincent Barichard <Vincent.Barichard@univ-angers.fr>
00005  *
00006  *  Copyright:
00007  *     Vincent Barichard, 2012
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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     // Post equation
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 // STATISTICS: example-any