descartes-folium.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Vincent Barichard <Vincent.Barichard@univ-angers.fr>
*
* Copyright:
* Vincent Barichard, 2012
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/driver.hh>
#include <gecode/minimodel.hh>
#include <gecode/float.hh>
using namespace Gecode;
class DescartesFolium : public FloatMaximizeScript {
protected:
FloatVarArray f;
double step;
public:
DescartesFolium(const Options& opt)
: FloatMaximizeScript(opt), f(*this,3,-20,20) {
if (opt.trace() != 0)
trace(*this, f, opt.trace());
// Post equation
FloatVar p = f[0];
FloatVar x = f[1];
FloatVar y = f[2];
rel(*this, 3*p/(1+pow(p,3)) == x);
rel(*this, 3*sqr(p)/(1+pow(p,3)) == y);
rel(*this, pow(x,3) + pow(y,3) == 3 * x * y);
rel(*this, x == FloatVal(-1,2));
branch(*this,p,FLOAT_VAL_SPLIT_MIN());
}
DescartesFolium(DescartesFolium& p)
: FloatMaximizeScript(p) {
f.update(*this, p.f);
}
virtual Space* copy(void) {
return new DescartesFolium(*this);
}
virtual FloatVar cost(void) const {
return f[0];
}
virtual void print(std::ostream& os) const {
os << "XY " << f[1].med() << " " << f[2].med()
<< std::endl;
}
};
int main(int argc, char* argv[]) {
Options opt("DescartesFolium");
opt.solutions(0);
opt.step(0.1);
opt.parse(argc,argv);
FloatMaximizeScript::run<DescartesFolium,BAB,Options>(opt);
return 0;
}
// STATISTICS: example-any
DescartesFolium::main
int main(int argc, char *argv[])
Main-function.
Definition descartes-folium.cpp:117
DescartesFolium::DescartesFolium
DescartesFolium(DescartesFolium &p)
Constructor for cloning p.
Definition descartes-folium.cpp:94
DescartesFolium::f
FloatVarArray f
The numbers.
Definition descartes-folium.cpp:71
DescartesFolium::DescartesFolium
DescartesFolium(const Options &opt)
Actual model.
Definition descartes-folium.cpp:76
DescartesFolium::cost
virtual FloatVar cost(void) const
Cost function.
Definition descartes-folium.cpp:103
DescartesFolium::step
double step
Minimum distance between two solutions.
Definition descartes-folium.cpp:73
DescartesFolium::copy
virtual Space * copy(void)
Copy during cloning.
Definition descartes-folium.cpp:99
DescartesFolium::print
virtual void print(std::ostream &os) const
Print solution coordinates.
Definition descartes-folium.cpp:107
Gecode::Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > >::run
static void run(const Options &opt, Script *s=NULL)
Gecode::FloatVal
Float value type.
Definition float.hh:334
Gecode::FloatVarArray
Float variable array.
Definition float.hh:1030
Gecode::FloatVar
Float variables.
Definition float.hh:870
Gecode::Options
Options for scripts
Definition driver.hh:366
Gecode::Space
Computation spaces.
Definition core.hpp:1742
Test::Options::parse
void parse(int argc, char *argv[])
Parse commandline arguments.
Definition test.cpp:120
driver.hh
float.hh
Gecode::FloatMaximizeScript
Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > > FloatMaximizeScript
Base-class for scripts for finding solution of highest float cost.
Definition driver.hh:842
Gecode::trace
GECODE_FLOAT_EXPORT void trace(Home home, const FloatVarArgs &x, TraceFilter tf, int te=(TE_INIT|TE_PRUNE|TE_FIX|TE_FAIL|TE_DONE), FloatTracer &t=StdFloatTracer::def)
Create a tracer for float variables.
Definition trace.cpp:39
Gecode::branch
void branch(Home home, const FloatVarArgs &x, FloatVarBranch vars, FloatValBranch vals, FloatBranchFilter bf=nullptr, FloatVarValPrint vvp=nullptr)
Branch over x with variable selection vars and value selection vals.
Definition branch.cpp:39
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::sqr
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:95
Gecode::pow
void pow(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition arithmetic.cpp:109
Gecode::FLOAT_VAL_SPLIT_MIN
FloatValBranch FLOAT_VAL_SPLIT_MIN(void)
Select values not greater than mean of smallest and largest value.
Definition val.hpp:55