archimedean-spiral.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 ArchimedeanSpiral : public FloatMaximizeScript {
protected:
FloatVarArray f;
public:
ArchimedeanSpiral(const Options& opt)
: FloatMaximizeScript(opt), f(*this,4,-20,20) {
// Post equation
FloatVar theta = f[0];
FloatVar r = f[3];
FloatVar x = f[1];
FloatVar y = f[2];
rel(*this, theta >= 0);
rel(*this, theta <= 6*FloatVal::pi());
rel(*this, r >= 0);
rel(*this, r*cos(theta) == x);
rel(*this, r*sin(theta) == y);
rel(*this, r == theta);
branch(*this,f[0],FLOAT_VAL_SPLIT_MIN());
}
ArchimedeanSpiral(ArchimedeanSpiral& p)
: FloatMaximizeScript(p) {
f.update(*this, p.f);
}
virtual Space* copy(void) {
return new ArchimedeanSpiral(*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("ArchimedeanSpiral");
opt.solutions(0);
opt.step(0.1);
opt.parse(argc,argv);
FloatMaximizeScript::run<ArchimedeanSpiral,BAB,Options>(opt);
return 0;
}
// STATISTICS: example-any
ArchimedeanSpiral::ArchimedeanSpiral
ArchimedeanSpiral(ArchimedeanSpiral &p)
Constructor for cloning p.
Definition archimedean-spiral.cpp:91
ArchimedeanSpiral::main
int main(int argc, char *argv[])
Main-function.
Definition archimedean-spiral.cpp:114
ArchimedeanSpiral::f
FloatVarArray f
The numbers.
Definition archimedean-spiral.cpp:70
ArchimedeanSpiral::ArchimedeanSpiral
ArchimedeanSpiral(const Options &opt)
Actual model.
Definition archimedean-spiral.cpp:73
ArchimedeanSpiral::print
virtual void print(std::ostream &os) const
Print solution coordinates.
Definition archimedean-spiral.cpp:104
ArchimedeanSpiral::cost
virtual FloatVar cost(void) const
Cost function.
Definition archimedean-spiral.cpp:100
ArchimedeanSpiral::copy
virtual Space * copy(void)
Copy during cloning.
Definition archimedean-spiral.cpp:96
Gecode::Driver::ScriptBase< Driver::ExtractStepOption< FloatMaximizeSpace > >::run
static void run(const Options &opt, Script *s=NULL)
Gecode::FloatVal::pi
static FloatVal pi(void)
Return lower bound of .
Definition val.hpp:114
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::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::sin
void sin(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:52
Gecode::cos
void cos(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition trigonometric.cpp:66
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