descartes-folium.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
00072 class DescartesFolium : public FloatMaximizeScript {
00073 protected:
00075 FloatVarArray f;
00077 double step;
00078 public:
00080 DescartesFolium(const Options& opt)
00081 : FloatMaximizeScript(opt), f(*this,3,-20,20) {
00082
00083 if (opt.trace() != 0)
00084 trace(*this, f, opt.trace());
00085
00086
00087 FloatVar p = f[0];
00088 FloatVar x = f[1];
00089 FloatVar y = f[2];
00090 rel(*this, 3*p/(1+pow(p,3)) == x);
00091 rel(*this, 3*sqr(p)/(1+pow(p,3)) == y);
00092 rel(*this, pow(x,3) + pow(y,3) == 3 * x * y);
00093 rel(*this, x == FloatVal(-1,2));
00094
00095 branch(*this,p,FLOAT_VAL_SPLIT_MIN());
00096 }
00098 DescartesFolium(bool share, DescartesFolium& p)
00099 : FloatMaximizeScript(share,p) {
00100 f.update(*this,share,p.f);
00101 }
00103 virtual Space* copy(bool share) {
00104 return new DescartesFolium(share,*this);
00105 }
00107 virtual FloatVar cost(void) const {
00108 return f[0];
00109 }
00111 virtual void print(std::ostream& os) const {
00112 os << "XY " << f[1].med() << " " << f[2].med()
00113 << std::endl;
00114 }
00115
00116 };
00117
00121 int main(int argc, char* argv[]) {
00122 Options opt("DescartesFolium");
00123 opt.solutions(0);
00124 opt.step(0.1);
00125 opt.parse(argc,argv);
00126 FloatMaximizeScript::run<DescartesFolium,BAB,Options>(opt);
00127 return 0;
00128 }
00129
00130