this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Guido Tack <tack@gecode.org>
5 *
6 * Contributing authors:
7 * Christian Schulte <schulte@gecode.org>
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.org
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
44 CutoffConstant::operator ()(void) const {
45 return c;
46 }
47 unsigned long long int
48 CutoffConstant::operator ++(void) {
49 return c;
50 }
51
52
53 unsigned long long int
54 CutoffLinear::operator ()(void) const {
55 return n;
56 }
57 unsigned long long int
58 CutoffLinear::operator ++(void) {
59 n += scale;
60 return n;
61 }
62
63
64 unsigned long int
65 CutoffLuby::start[CutoffLuby::n_start] = {
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
70 CutoffLuby::operator ()(void) const {
71 return scale*luby(i);
72 }
73 unsigned long long int
74 CutoffLuby::operator ++(void) {
75 return scale*luby(i++);
76 }
77
78
79 unsigned long long int
80 CutoffGeometric::operator ()(void) const {
81 return static_cast<unsigned long long int>(scale * n);
82 }
83 unsigned long long int
84 CutoffGeometric::operator ++(void) {
85 n *= base;
86 return static_cast<unsigned long long int>(scale * n);
87 }
88
89
90 unsigned long long int
91 CutoffRandom::operator ++(void) {
92 cur = min+step*rnd(n);
93 return cur;
94 }
95 unsigned long long int
96 CutoffRandom::operator ()(void) const {
97 return cur;
98 }
99
100
101 unsigned long long int
102 CutoffAppend::operator ()(void) const {
103 if (n > 0) {
104 return (*c1)();
105 } else {
106 return (*c2)();
107 }
108 }
109 unsigned long long int
110 CutoffAppend::operator ++(void) {
111 if (n > 0) {
112 n--;
113 return ++(*c1);
114 } else {
115 return ++(*c2);
116 }
117 }
118
119
120 unsigned long long int
121 CutoffMerge::operator ()(void) const {
122 return (*c1)();
123 }
124 unsigned long long int
125 CutoffMerge::operator ++(void) {
126 (void) ++(*c1);
127 std::swap(c1,c2);
128 return (*c1)();
129 }
130
131
132 unsigned long long int
133 CutoffRepeat::operator ()(void) const {
134 return cutoff;
135 }
136 unsigned long long int
137 CutoffRepeat::operator ++(void) {
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*
175 Cutoff::merge(Cutoff* c1, Cutoff* c2) {
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