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