Generated on Thu Apr 11 13:58:52 2019 for Gecode by doxygen 1.6.3

golden-spiral.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 
00077 class GoldenSpiral : public FloatMaximizeScript {
00078 protected:
00080   FloatVarArray f;
00081 public:
00083   GoldenSpiral(const Options& opt)
00084     : FloatMaximizeScript(opt), f(*this,4,-20,20) {
00085     // Post equation
00086     FloatVar theta = f[0];
00087     FloatVar r = f[3];
00088     FloatVar x = f[1];
00089     FloatVar y = f[2];
00090     rel(*this, theta >= 0);
00091     rel(*this, r >= 0);
00092     rel(*this, r*cos(theta) == x);
00093     rel(*this, r*sin(theta) == y);
00094     rel(*this, exp(0.30649*theta) == r);
00095 
00096     branch(*this,theta,FLOAT_VAL_SPLIT_MIN());
00097   }
00099   GoldenSpiral(GoldenSpiral& p)
00100     : FloatMaximizeScript(p) {
00101     f.update(*this, p.f);
00102   }
00104   virtual Space* copy(void) {
00105     return new GoldenSpiral(*this);
00106   }
00108   virtual FloatVar cost(void) const {
00109     return f[0];
00110   }
00112   virtual void print(std::ostream& os) const {
00113     os << "XY " << f[1].med() << " " << f[2].med()
00114        << std::endl;
00115   }
00116 
00117 };
00118 
00122 int main(int argc, char* argv[]) {
00123   Options opt("GoldenSpiral");
00124   opt.solutions(0);
00125   opt.step(0.1);
00126   opt.parse(argc,argv);
00127   FloatMaximizeScript::run<GoldenSpiral,BAB,Options>(opt);
00128   return 0;
00129 }
00130 
00131 // STATISTICS: example-any