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 FloatVar p = f[0];
00084 FloatVar x = f[1];
00085 FloatVar y = f[2];
00086 rel(*this, 3*p/(1+pow(p,3)) == x);
00087 rel(*this, 3*sqr(p)/(1+pow(p,3)) == y);
00088 rel(*this, pow(x,3) + pow(y,3) == 3 * x * y);
00089 rel(*this, x == FloatVal(-1,2));
00090
00091 branch(*this,p,FLOAT_VAL_SPLIT_MIN());
00092 }
00094 DescartesFolium(bool share, DescartesFolium& p)
00095 : FloatMaximizeScript(share,p) {
00096 f.update(*this,share,p.f);
00097 }
00099 virtual Space* copy(bool share) {
00100 return new DescartesFolium(share,*this);
00101 }
00103 virtual FloatVar cost(void) const {
00104 return f[0];
00105 }
00107 virtual void print(std::ostream& os) const {
00108 os << "XY " << f[1].med() << " " << f[2].med()
00109 << std::endl;
00110 }
00111
00112 };
00113
00117 int main(int argc, char* argv[]) {
00118 Options opt("DescartesFolium");
00119 opt.solutions(0);
00120 opt.step(0.1);
00121 opt.parse(argc,argv);
00122 FloatMaximizeScript::run<DescartesFolium,BAB,Options>(opt);
00123 return 0;
00124 }
00125
00126