archimedean-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
00071 class ArchimedeanSpiral : public FloatMaximizeScript {
00072 protected:
00074 FloatVarArray f;
00075 public:
00077 ArchimedeanSpiral(const Options& opt)
00078 : FloatMaximizeScript(opt), f(*this,4,-20,20) {
00079
00080 FloatVar theta = f[0];
00081 FloatVar r = f[3];
00082 FloatVar x = f[1];
00083 FloatVar y = f[2];
00084
00085 rel(*this, theta >= 0);
00086 rel(*this, theta <= 6*FloatVal::pi());
00087 rel(*this, r >= 0);
00088 rel(*this, r*cos(theta) == x);
00089 rel(*this, r*sin(theta) == y);
00090 rel(*this, r == theta);
00091
00092 branch(*this,f[0],FLOAT_VAL_SPLIT_MIN());
00093 }
00095 ArchimedeanSpiral(bool share, ArchimedeanSpiral& p)
00096 : FloatMaximizeScript(share,p) {
00097 f.update(*this,share,p.f);
00098 }
00100 virtual Space* copy(bool share) {
00101 return new ArchimedeanSpiral(share,*this);
00102 }
00104 virtual FloatVar cost(void) const {
00105 return f[0];
00106 }
00108 virtual void print(std::ostream& os) const {
00109 os << "XY " << f[1].med() << " " << f[2].med()
00110 << std::endl;
00111 }
00112
00113 };
00114
00118 int main(int argc, char* argv[]) {
00119 Options opt("ArchimedeanSpiral");
00120 opt.solutions(0);
00121 opt.step(0.1);
00122 opt.parse(argc,argv);
00123 FloatMaximizeScript::run<ArchimedeanSpiral,BAB,Options>(opt);
00124 return 0;
00125 }
00126
00127