Generated on for Gecode by doxygen 1.15.0
cutoff.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.dev>
5 *
6 * Contributing authors:
7 * Christian Schulte <schulte@gecode.dev>
8 *
9 * Copyright:
10 * Christian Schulte, 2013
11 * Guido Tack, 2013
12 *
13 * This file is part of Gecode, the generic constraint
14 * development environment:
15 * http://www.gecode.dev
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
24 *
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 *
36 */
37
38#include <algorithm>
39#include <gecode/search.hh>
40
41namespace Gecode { namespace Search {
42
43 unsigned long long int
45 return c;
46 }
47 unsigned long long int
49 return c;
50 }
51
52
53 unsigned long long int
55 return n;
56 }
57 unsigned long long int
59 n += scale;
60 return n;
61 }
62
63
64 unsigned long int
66 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,
67 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
68 };
69 unsigned long long int
71 return scale*luby(i);
72 }
73 unsigned long long int
75 return scale*luby(i++);
76 }
77
78
79 unsigned long long int
81 return static_cast<unsigned long long int>(scale * n);
82 }
83 unsigned long long int
85 n *= base;
86 return static_cast<unsigned long long int>(scale * n);
87 }
88
89
90 unsigned long long int
92 cur = min+step*rnd(n);
93 return cur;
94 }
95 unsigned long long int
97 return cur;
98 }
99
100
101 unsigned long long int
103 if (n > 0) {
104 return (*c1)();
105 } else {
106 return (*c2)();
107 }
108 }
109 unsigned long long int
111 if (n > 0) {
112 n--;
113 return ++(*c1);
114 } else {
115 return ++(*c2);
116 }
117 }
118
119
120 unsigned long long int
122 return (*c1)();
123 }
124 unsigned long long int
126 (void) ++(*c1);
127 std::swap(c1,c2);
128 return (*c1)();
129 }
130
131
132 unsigned long long int
134 return cutoff;
135 }
136 unsigned long long int
138 i++;
139 if (i == n) {
140 cutoff = (*c)();
141 i = 0;
142 }
143 return cutoff;
144 }
145
146
147 Cutoff*
148 Cutoff::constant(unsigned long long int scale) {
149 return new CutoffConstant(scale);
150 }
151 Cutoff*
152 Cutoff::linear(unsigned long long int scale) {
153 return new CutoffLinear(scale);
154 }
155 Cutoff*
156 Cutoff::luby(unsigned long long int scale) {
157 return new CutoffLuby(scale);
158 }
159 Cutoff*
160 Cutoff::geometric(unsigned long long int base, double scale) {
161 return new CutoffGeometric(base,scale);
162 }
163 Cutoff*
164 Cutoff::rnd(unsigned int seed,
165 unsigned long long int min,
166 unsigned long long int max,
167 unsigned long long int n) {
168 return new CutoffRandom(seed,min,max,n);
169 }
170 Cutoff*
171 Cutoff::append(Cutoff* c1, unsigned long long int n, Cutoff* c2) {
172 return new CutoffAppend(c1,n,c2);
173 }
174 Cutoff*
176 return new CutoffMerge(c1,c2);
177 }
178 Cutoff*
179 Cutoff::repeat(Cutoff* c, unsigned long long int n) {
180 return new CutoffRepeat(c,n);
181 }
182
183}}
184
185// STATISTICS: search-other
Cutoff generator appending two cutoff generators.
Definition search.hh:641
unsigned long long int n
How many number to take from the first.
Definition search.hh:648
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:110
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:102
Cutoff * c1
First cutoff generators.
Definition search.hh:644
Cutoff * c2
Second cutoff generators.
Definition search.hh:646
Cutoff generator for constant sequence.
Definition search.hh:530
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:48
unsigned long long int c
Constant.
Definition search.hh:533
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:44
Cutoff generator for the geometric sequence.
Definition search.hh:593
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:80
double n
Current cutoff value.
Definition search.hh:596
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:84
double scale
Scale factor.
Definition search.hh:598
Cutoff generator for linear sequence.
Definition search.hh:547
unsigned long long int n
Next number in sequence.
Definition search.hh:552
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:54
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:58
unsigned long long int scale
Scale factor.
Definition search.hh:550
Cutoff generator for the Luby sequence.
Definition search.hh:566
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:70
static const unsigned long long int n_start
Number of pre-computed luby values.
Definition search.hh:573
unsigned long long int i
Iteration number.
Definition search.hh:569
unsigned long long int scale
Scale factor.
Definition search.hh:571
static unsigned long long int luby(unsigned long long int i)
Compute Luby number for step i.
Definition cutoff.hpp:68
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:74
static unsigned long int start[n_start]
Precomputed luby-values.
Definition search.hh:575
Cutoff generator merging two cutoff generators.
Definition search.hh:664
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:125
Cutoff * c1
First cutoff generator.
Definition search.hh:667
Cutoff * c2
Second cutoff generator.
Definition search.hh:669
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:121
Cutoff generator for the random sequence.
Definition search.hh:614
unsigned long long int n
Random values.
Definition search.hh:621
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:91
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:96
unsigned long long int step
Step size.
Definition search.hh:623
unsigned long long int cur
Current value.
Definition search.hh:625
unsigned long long int min
Minimum cutoff value.
Definition search.hh:619
Support::RandomGenerator rnd
Random number generator.
Definition search.hh:617
Cutoff generator that repeats a cutoff from another cutoff generator.
Definition search.hh:685
virtual unsigned long long int operator()(void) const
Return the current cutoff value.
Definition cutoff.cpp:133
unsigned long long int n
Definition search.hh:694
unsigned long long int cutoff
Definition search.hh:690
virtual unsigned long long int operator++(void)
Increment and return the next cutoff value.
Definition cutoff.cpp:137
unsigned long long int i
Definition search.hh:692
Base class for cutoff generators for restart-based meta engine.
Definition search.hh:476
static Cutoff * luby(unsigned long long int scale=Config::slice)
Create generator for luby sequence with scale-factor scale.
Definition cutoff.cpp:156
static Cutoff * repeat(Cutoff *c, unsigned long long int n)
Create generator that repeats n times each cutoff value from c.
Definition cutoff.cpp:179
static Cutoff * merge(Cutoff *c1, Cutoff *c2)
Merge cutoff values from c1 with values from c2.
Definition cutoff.cpp:175
static Cutoff * constant(unsigned long long int scale=Config::slice)
Create generator for constant sequence with constant s.
Definition cutoff.cpp:148
static Cutoff * linear(unsigned long long int scale=Config::slice)
Create generator for linear sequence scaled by scale.
Definition cutoff.cpp:152
static Cutoff * rnd(unsigned int seed, unsigned long long int min, unsigned long long int max, unsigned long long int n)
Definition cutoff.cpp:164
Cutoff(void)
Default constructor.
Definition cutoff.hpp:41
static Cutoff * append(Cutoff *c1, unsigned long long int n, Cutoff *c2)
Append cutoff values from c2 after n values from c1.
Definition cutoff.cpp:171
static Cutoff * geometric(unsigned long long int scale=Config::slice, double base=Config::base)
Definition cutoff.cpp:160
Search engines
Gecode toplevel namespace
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .