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 Script {
00082 protected:
00084 FloatVarArray f;
00086 FloatNum step;
00087 public:
00089 GoldenSpiral(const Options&)
00090 : f(*this,4,-20,20), step(0.1) {
00091
00092 FloatVar theta = f[0];
00093 FloatVar r = f[3];
00094 FloatVar x = f[1];
00095 FloatVar y = f[2];
00096 rel(*this, theta >= 0);
00097 rel(*this, r >= 0);
00098 rel(*this, r*cos(theta) == x);
00099 rel(*this, r*sin(theta) == y);
00100 rel(*this, exp(0.30649*theta) == r);
00101
00102 branch(*this,theta,FLOAT_VAL_SPLIT_MIN());
00103 }
00105 GoldenSpiral(bool share, GoldenSpiral& p)
00106 : Script(share,p), step(p.step) {
00107 f.update(*this,share,p.f);
00108 }
00110 virtual Space* copy(bool share) {
00111 return new GoldenSpiral(share,*this);
00112 }
00114 virtual void constrain(const Space& _b) {
00115 const GoldenSpiral& b = static_cast<const GoldenSpiral&>(_b);
00116 rel(*this, f[0] >= (b.f[0].max()+step));
00117 }
00119 virtual void print(std::ostream& os) const {
00120 os << "XY " << f[1].med() << " " << f[2].med()
00121 << std::endl;
00122 }
00123
00124 };
00125
00129 int main(int argc, char* argv[]) {
00130 Options opt("GoldenSpiral");
00131 opt.parse(argc,argv);
00132 opt.solutions(0);
00133 Script::run<GoldenSpiral,BAB,Options>(opt);
00134 return 0;
00135 }
00136
00137