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 #include <gecode/driver.hh>
00035
00036 #include <gecode/minimodel.hh>
00037 #include <gecode/float.hh>
00038
00039 using namespace Gecode;
00040
00067 class ArchimedeanSpiral : public FloatMaximizeScript {
00068 protected:
00070 FloatVarArray f;
00071 public:
00073 ArchimedeanSpiral(const Options& opt)
00074 : FloatMaximizeScript(opt), f(*this,4,-20,20) {
00075
00076 FloatVar theta = f[0];
00077 FloatVar r = f[3];
00078 FloatVar x = f[1];
00079 FloatVar y = f[2];
00080
00081 rel(*this, theta >= 0);
00082 rel(*this, theta <= 6*FloatVal::pi());
00083 rel(*this, r >= 0);
00084 rel(*this, r*cos(theta) == x);
00085 rel(*this, r*sin(theta) == y);
00086 rel(*this, r == theta);
00087
00088 branch(*this,f[0],FLOAT_VAL_SPLIT_MIN());
00089 }
00091 ArchimedeanSpiral(ArchimedeanSpiral& p)
00092 : FloatMaximizeScript(p) {
00093 f.update(*this, p.f);
00094 }
00096 virtual Space* copy(void) {
00097 return new ArchimedeanSpiral(*this);
00098 }
00100 virtual FloatVar cost(void) const {
00101 return f[0];
00102 }
00104 virtual void print(std::ostream& os) const {
00105 os << "XY " << f[1].med() << " " << f[2].med()
00106 << std::endl;
00107 }
00108
00109 };
00110
00114 int main(int argc, char* argv[]) {
00115 Options opt("ArchimedeanSpiral");
00116 opt.solutions(0);
00117 opt.step(0.1);
00118 opt.parse(argc,argv);
00119 FloatMaximizeScript::run<ArchimedeanSpiral,BAB,Options>(opt);
00120 return 0;
00121 }
00122
00123