Generated on Tue Apr 18 10:21:29 2017 for Gecode by doxygen 1.6.3

descartes-folium.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  *  Last modified:
00010  *     $Date: 2016-05-24 10:22:30 +0200 (Tue, 24 May 2016) $ by $Author: schulte $
00011  *     $Revision: 15079 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 
00072 class DescartesFolium : public FloatMaximizeScript {
00073 protected:
00075   FloatVarArray f;
00077   double step;
00078 public:
00080   DescartesFolium(const Options& opt)
00081     : FloatMaximizeScript(opt), f(*this,3,-20,20) {
00082 
00083     if (opt.trace() != 0)
00084       trace(*this, f, opt.trace());
00085 
00086     // Post equation
00087     FloatVar p = f[0];
00088     FloatVar x = f[1];
00089     FloatVar y = f[2];
00090     rel(*this, 3*p/(1+pow(p,3)) == x);
00091     rel(*this, 3*sqr(p)/(1+pow(p,3)) == y);
00092     rel(*this, pow(x,3) + pow(y,3)  == 3 * x * y);
00093     rel(*this, x == FloatVal(-1,2));
00094 
00095     branch(*this,p,FLOAT_VAL_SPLIT_MIN());
00096   }
00098   DescartesFolium(bool share, DescartesFolium& p)
00099     : FloatMaximizeScript(share,p) {
00100     f.update(*this,share,p.f);
00101   }
00103   virtual Space* copy(bool share) {
00104     return new DescartesFolium(share,*this);
00105   }
00107   virtual FloatVar cost(void) const {
00108     return f[0];
00109   }
00111   virtual void print(std::ostream& os) const {
00112     os << "XY " << f[1].med() << " " << f[2].med()
00113        << std::endl;
00114   }
00115 
00116 };
00117 
00121 int main(int argc, char* argv[]) {
00122   Options opt("DescartesFolium");
00123   opt.solutions(0);
00124   opt.step(0.1);
00125   opt.parse(argc,argv);
00126   FloatMaximizeScript::run<DescartesFolium,BAB,Options>(opt);
00127   return 0;
00128 }
00129 
00130 // STATISTICS: example-any