cartesian-heart.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 CartesianHeart : public Script {
protected:
FloatVarArray f;
FloatNum step;
public:
CartesianHeart(const Options& opt)
: Script(opt), f(*this,2,-20,20), step(opt.step()) {
int q = 2;
FloatNum p = 0.5;
// Post equation
rel(*this, sqr(f[0]) + 2*sqr(f[1]-p*nroot(abs(f[0]),q)) == 1);
branch(*this, f[0], FLOAT_VAL_SPLIT_MIN());
branch(*this, f[1], FLOAT_VAL_SPLIT_MIN());
}
CartesianHeart(CartesianHeart& p)
: Script(p), step(p.step) {
f.update(*this, p.f);
}
virtual Space* copy(void) {
return new CartesianHeart(*this);
}
virtual void constrain(const Space& _b) {
const CartesianHeart& b = static_cast<const CartesianHeart&>(_b);
rel(*this,
(f[0] >= (b.f[0].max()+step)) ||
(f[1] >= (b.f[1].max()+step)) ||
(f[1] <= (b.f[1].min()-step)));
}
virtual void print(std::ostream& os) const {
os << "XY " << f[0].med() << " " << f[1].med()
<< std::endl;
}
};
int main(int argc, char* argv[]) {
Options opt("CartesianHeart");
opt.solutions(0);
opt.step(0.01);
opt.parse(argc,argv);
Script::run<CartesianHeart,BAB,Options>(opt);
return 0;
}
// STATISTICS: example-any
CartesianHeart::copy
virtual Space * copy(void)
Copy during cloning.
Definition cartesian-heart.cpp:86
CartesianHeart::main
int main(int argc, char *argv[])
Main-function.
Definition cartesian-heart.cpp:108
CartesianHeart::CartesianHeart
CartesianHeart(const Options &opt)
Actual model.
Definition cartesian-heart.cpp:71
CartesianHeart::CartesianHeart
CartesianHeart(CartesianHeart &p)
Constructor for cloning p.
Definition cartesian-heart.cpp:81
CartesianHeart::print
virtual void print(std::ostream &os) const
Print solution coordinates.
Definition cartesian-heart.cpp:98
CartesianHeart::step
FloatNum step
Minimum distance between two solutions.
Definition cartesian-heart.cpp:68
CartesianHeart::constrain
virtual void constrain(const Space &_b)
Add constraints to current model to get next solution (not too close).
Definition cartesian-heart.cpp:90
CartesianHeart::f
FloatVarArray f
The numbers.
Definition cartesian-heart.cpp:66
Gecode::Driver::ScriptBase< Driver::IgnoreStepOption< Space > >::run
static void run(const Options &opt, Script *s=NULL)
Gecode::FloatVal::max
friend FloatVal max(const FloatVal &x, const FloatVal &y)
Definition val.hpp:386
Gecode::FloatVal::min
friend FloatVal min(const FloatVal &x, const FloatVal &y)
Definition val.hpp:398
Gecode::FloatVarArray
Float variable array.
Definition float.hh:1030
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::Script
Driver::ScriptBase< Driver::IgnoreStepOption< Space > > Script
Base-class for scripts.
Definition driver.hh:801
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
Gecode::FloatNum
double FloatNum
Floating point number base type.
Definition float.hh:106
minimodel.hh
Gecode
Gecode toplevel namespace
Gecode::sqr
void sqr(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:95
Gecode::abs
void abs(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition arithmetic.cpp:41
Gecode::nroot
void nroot(Home home, FloatVar x0, int n, FloatVar x1)
Post propagator for for $n\geq 0$.
Definition arithmetic.cpp:118
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