cutoff.cpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Guido Tack <tack@gecode.org>
*
* Contributing authors:
* Christian Schulte <schulte@gecode.org>
*
* Copyright:
* Christian Schulte, 2013
* Guido Tack, 2013
*
* 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 <algorithm>
#include <gecode/search.hh>
namespace Gecode { namespace Search {
unsigned long int
CutoffConstant::operator ()(void) const {
return c;
}
unsigned long int
CutoffConstant::operator ++(void) {
return c;
}
unsigned long int
CutoffLinear::operator ()(void) const {
return n;
}
unsigned long int
CutoffLinear::operator ++(void) {
n += scale;
return n;
}
unsigned long int
CutoffLuby::start[CutoffLuby::n_start] = {
1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,
1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,1,1,2,1,1,2,4,1,1,2,1,1,2,4,8,16,32
};
unsigned long int
CutoffLuby::operator ()(void) const {
return scale*luby(i);
}
unsigned long int
CutoffLuby::operator ++(void) {
return scale*luby(i++);
}
unsigned long int
CutoffGeometric::operator ()(void) const {
return static_cast<unsigned long int>(scale * n);
}
unsigned long int
CutoffGeometric::operator ++(void) {
n *= base;
return static_cast<unsigned long int>(scale * n);
}
unsigned long int
CutoffRandom::operator ++(void) {
cur = min+step*rnd(n);
return cur;
}
unsigned long int
CutoffRandom::operator ()(void) const {
return cur;
}
unsigned long int
CutoffAppend::operator ()(void) const {
if (n > 0) {
return (*c1)();
} else {
return (*c2)();
}
}
unsigned long int
CutoffAppend::operator ++(void) {
if (n > 0) {
n--;
return ++(*c1);
} else {
return ++(*c2);
}
}
unsigned long int
CutoffMerge::operator ()(void) const {
return (*c1)();
}
unsigned long int
CutoffMerge::operator ++(void) {
(void) ++(*c1);
std::swap(c1,c2);
return (*c1)();
}
unsigned long int
CutoffRepeat::operator ()(void) const {
return cutoff;
}
unsigned long int
CutoffRepeat::operator ++(void) {
i++;
if (i == n) {
cutoff = (*c)();
i = 0;
}
return cutoff;
}
Cutoff*
Cutoff::constant(unsigned long int scale) {
return new CutoffConstant(scale);
}
Cutoff*
Cutoff::linear(unsigned long int scale) {
return new CutoffLinear(scale);
}
Cutoff*
Cutoff::luby(unsigned long int scale) {
return new CutoffLuby(scale);
}
Cutoff*
Cutoff::geometric(unsigned long int base, double scale) {
return new CutoffGeometric(base,scale);
}
Cutoff*
Cutoff::rnd(unsigned int seed,
unsigned long int min,
unsigned long int max,
unsigned long int n) {
return new CutoffRandom(seed,min,max,n);
}
Cutoff*
Cutoff::append(Cutoff* c1, unsigned long int n, Cutoff* c2) {
return new CutoffAppend(c1,n,c2);
}
Cutoff*
Cutoff::merge(Cutoff* c1, Cutoff* c2) {
return new CutoffMerge(c1,c2);
}
Cutoff*
Cutoff::repeat(Cutoff* c, unsigned long int n) {
return new CutoffRepeat(c,n);
}
}}
// STATISTICS: search-other
Gecode::Search::CutoffAppend
Cutoff generator appending two cutoff generators.
Definition search.hh:636
Gecode::Search::CutoffAppend::n
unsigned long int n
How many number to take from the first.
Definition search.hh:643
Gecode::Search::CutoffAppend::c1
Cutoff * c1
First cutoff generators.
Definition search.hh:639
Gecode::Search::CutoffAppend::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:110
Gecode::Search::CutoffAppend::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:102
Gecode::Search::CutoffAppend::c2
Cutoff * c2
Second cutoff generators.
Definition search.hh:641
Gecode::Search::CutoffConstant
Cutoff generator for constant sequence.
Definition search.hh:525
Gecode::Search::CutoffConstant::c
unsigned long int c
Constant.
Definition search.hh:528
Gecode::Search::CutoffConstant::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:44
Gecode::Search::CutoffConstant::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:48
Gecode::Search::CutoffGeometric
Cutoff generator for the geometric sequence.
Definition search.hh:588
Gecode::Search::CutoffGeometric::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:84
Gecode::Search::CutoffGeometric::n
double n
Current cutoff value.
Definition search.hh:591
Gecode::Search::CutoffGeometric::base
double base
Base.
Definition search.hh:595
Gecode::Search::CutoffGeometric::scale
double scale
Scale factor.
Definition search.hh:593
Gecode::Search::CutoffGeometric::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:80
Gecode::Search::CutoffLinear
Cutoff generator for linear sequence.
Definition search.hh:542
Gecode::Search::CutoffLinear::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:58
Gecode::Search::CutoffLinear::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:54
Gecode::Search::CutoffLinear::n
unsigned long int n
Next number in sequence.
Definition search.hh:547
Gecode::Search::CutoffLinear::scale
unsigned long int scale
Scale factor.
Definition search.hh:545
Gecode::Search::CutoffLuby
Cutoff generator for the Luby sequence.
Definition search.hh:561
Gecode::Search::CutoffLuby::luby
static unsigned long int luby(unsigned long int i)
Compute Luby number for step i.
Definition cutoff.hpp:68
Gecode::Search::CutoffLuby::n_start
static const unsigned long int n_start
Number of pre-computed luby values.
Definition search.hh:568
Gecode::Search::CutoffLuby::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:70
Gecode::Search::CutoffLuby::scale
unsigned long int scale
Scale factor.
Definition search.hh:566
Gecode::Search::CutoffLuby::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:74
Gecode::Search::CutoffLuby::i
unsigned long int i
Iteration number.
Definition search.hh:564
Gecode::Search::CutoffLuby::start
static unsigned long int start[n_start]
Precomputed luby-values.
Definition search.hh:570
Gecode::Search::CutoffMerge
Cutoff generator merging two cutoff generators.
Definition search.hh:659
Gecode::Search::CutoffMerge::c1
Cutoff * c1
First cutoff generator.
Definition search.hh:662
Gecode::Search::CutoffMerge::c2
Cutoff * c2
Second cutoff generator.
Definition search.hh:664
Gecode::Search::CutoffMerge::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:125
Gecode::Search::CutoffMerge::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:121
Gecode::Search::CutoffRandom
Cutoff generator for the random sequence.
Definition search.hh:609
Gecode::Search::CutoffRandom::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:91
Gecode::Search::CutoffRandom::step
unsigned long int step
Step size.
Definition search.hh:618
Gecode::Search::CutoffRandom::cur
unsigned long int cur
Current value.
Definition search.hh:620
Gecode::Search::CutoffRandom::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:96
Gecode::Search::CutoffRandom::n
unsigned long int n
Random values.
Definition search.hh:616
Gecode::Search::CutoffRandom::rnd
Support::RandomGenerator rnd
Random number generator.
Definition search.hh:612
Gecode::Search::CutoffRandom::min
unsigned long int min
Minimum cutoff value.
Definition search.hh:614
Gecode::Search::CutoffRepeat
Cutoff generator that repeats a cutoff from another cutoff generator.
Definition search.hh:680
Gecode::Search::CutoffRepeat::n
unsigned long int n
Definition search.hh:689
Gecode::Search::CutoffRepeat::cutoff
unsigned int cutoff
Definition search.hh:685
Gecode::Search::CutoffRepeat::operator++
virtual unsigned long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:137
Gecode::Search::CutoffRepeat::operator()
virtual unsigned long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:133
Gecode::Search::CutoffRepeat::i
unsigned long int i
Definition search.hh:687
Gecode::Search::Cutoff
Base class for cutoff generators for restart-based meta engine.
Definition search.hh:472
Gecode::Search::Cutoff::rnd
static Cutoff * rnd(unsigned int seed, unsigned long int min, unsigned long int max, unsigned long int n)
Definition cutoff.cpp:164
Gecode::Search::Cutoff::merge
static Cutoff * merge(Cutoff *c1, Cutoff *c2)
Merge cutoff values from c1 with values from c2.
Definition cutoff.cpp:175
Gecode::Search::Cutoff::linear
static Cutoff * linear(unsigned long int scale=Config::slice)
Create generator for linear sequence scaled by scale.
Definition cutoff.cpp:152
Gecode::Search::Cutoff::geometric
static Cutoff * geometric(unsigned long int scale=Config::slice, double base=Config::base)
Definition cutoff.cpp:160
Gecode::Search::Cutoff::constant
static Cutoff * constant(unsigned long int scale=Config::slice)
Create generator for constant sequence with constant s.
Definition cutoff.cpp:148
Gecode::Search::Cutoff::Cutoff
Cutoff(void)
Default constructor.
Definition cutoff.hpp:41
Gecode::Search::Cutoff::luby
static Cutoff * luby(unsigned long int scale=Config::slice)
Create generator for luby sequence with scale-factor scale.
Definition cutoff.cpp:156
Gecode::Search::Cutoff::append
static Cutoff * append(Cutoff *c1, unsigned long int n, Cutoff *c2)
Append cutoff values from c2 after n values from c1.
Definition cutoff.cpp:171
Gecode::Search::Cutoff::repeat
static Cutoff * repeat(Cutoff *c, unsigned long int n)
Create generator that repeats n times each cutoff value from c.
Definition cutoff.cpp:179
Gecode::Search
Search engines
Gecode
Gecode toplevel namespace
Gecode::min
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:67
Gecode::max
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition arithmetic.cpp:49
search.hh