Generated on Thu Jan 14 2016 02:25:43 for Gecode by doxygen 1.8.5
cutoff.hpp
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.org>
5  *
6  * Contributing authors:
7  * Christian Schulte <schulte@gecode.org>
8  *
9  * Copyright:
10  * Christian Schulte, 2013
11  * Guido Tack, 2013
12  *
13  * Last modified:
14  * $Date: 2015-03-11 10:45:36 +0100 (Wed, 11 Mar 2015) $ by $Author: schulte $
15  * $Revision: 14434 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 namespace Gecode { namespace Search {
43 
45  Cutoff::Cutoff(void) {}
47  Cutoff::~Cutoff(void) {}
48  forceinline void*
49  Cutoff::operator new(size_t s) {
50  return heap.ralloc(s);
51  }
52  forceinline void
53  Cutoff::operator delete(void* p) {
54  heap.rfree(p);
55  }
56 
57 
59  CutoffConstant::CutoffConstant(unsigned long int c0)
60  : c(c0) {}
61 
62 
64  CutoffLinear::CutoffLinear(unsigned long int s)
65  : scale(s), n(0) {}
66 
67 
69  CutoffLuby::CutoffLuby(unsigned long int scale0)
70  : i(1U), scale(scale0) {}
71  forceinline unsigned long int
72  CutoffLuby::log(unsigned long int i) {
73  if (i == 1U)
74  return 0U;
75  unsigned long int exp = 0U;
76  while ( (i >> (++exp)) > 1U ) {}
77  return exp;
78  }
79  forceinline unsigned long int
80  CutoffLuby::luby(unsigned long int i) {
81  while (true) {
82  if (i <= n_start)
83  return start[i-1];
84  unsigned long int l = log(i);
85  if (i == (1U<<(l+1))-1)
86  return 1UL<<l;
87  i=i-(1U<<l)+1;
88  }
90  return 0;
91  }
92 
93 
95  CutoffGeometric::CutoffGeometric(unsigned long int scale0, double base0)
96  : n(1.0), scale(static_cast<double>(scale0)), base(base0) {}
97 
98 
100  CutoffRandom::CutoffRandom(unsigned int seed,
101  unsigned long int min0,
102  unsigned long int max0,
103  unsigned long int n0)
104  : rnd(seed), min(min0), n(n0 == 0 ? (max0-min+1U) : n0),
105  step(std::max(1UL,
106  static_cast<unsigned long int>((max0-min0+1U)/n))) {
107  cur = ++(*this);
108  }
109 
110 
112  CutoffAppend::CutoffAppend(Cutoff* d1, unsigned long int n0, Cutoff* d2)
113  : c1(d1), c2(d2), n(n0) {}
116  delete c1; delete c2;
117  }
118 
119 
122  : c1(d1), c2(d2) {}
125  delete c1; delete c2;
126  }
127 
128 
130  CutoffRepeat::CutoffRepeat(Cutoff* c1, unsigned long int n0)
131  : c(c1), i(0), n(n0) {
132  cutoff = (*c)();
133  }
136  delete c;
137  }
138 
139 }}
140 
141 // STATISTICS: search-other
const Gecode::FloatNum step
Definition: arithmetic.cpp:789
Cutoff(void)
Default constructor.
Definition: cutoff.hpp:45
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
static const unsigned long int n_start
Number of pre-computed luby values.
Definition: search.hh:271
virtual ~Cutoff(void)
Destructor.
Definition: cutoff.hpp:47
Cutoff * c1
First cutoff generator.
Definition: search.hh:365
void rfree(void *p)
Free memory block starting at p.
Definition: heap.hpp:355
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
static unsigned long int luby(unsigned long int i)
Compute Luby number for step i.
Definition: cutoff.hpp:80
virtual ~CutoffAppend(void)
Destructor.
Definition: cutoff.hpp:115
void * ralloc(size_t s)
Allocate s bytes from heap.
Definition: heap.hpp:341
Base class for cutoff generators for restart-based meta engine.
Definition: search.hh:168
CutoffLuby(unsigned long int scale)
Constructor.
Definition: cutoff.hpp:69
Heap heap
The single global heap.
Definition: heap.cpp:49
Gecode::IntSet d1(v1, 7)
Gecode::FloatVal c(-8, 8)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Gecode::IntSet d2(v2, 9)
virtual ~CutoffRepeat(void)
Destructor.
Definition: cutoff.hpp:135
static unsigned long int start[n_start]
Precomputed luby-values.
Definition: search.hh:273
unsigned long int cur
Current value.
Definition: search.hh:323
Cutoff * c2
Second cutoff generators.
Definition: search.hh:344
static unsigned long int log(unsigned long int i)
Compute binary logarithm of i.
Definition: cutoff.hpp:72
Cutoff * c1
First cutoff generators.
Definition: search.hh:342
virtual ~CutoffMerge(void)
Destructor.
Definition: cutoff.hpp:124
CutoffRandom(unsigned int seed, unsigned long int min, unsigned long int max, unsigned long int n)
Constructor.
Definition: cutoff.hpp:100
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
Cutoff * c
Actual cutoff generator.
Definition: search.hh:386
CutoffRepeat(Cutoff *c, unsigned long int n)
Constructor.
Definition: cutoff.hpp:130
CutoffMerge(Cutoff *c1, Cutoff *c2)
Constructor.
Definition: cutoff.hpp:121
CutoffGeometric(unsigned long int scale, double base)
Constructor.
Definition: cutoff.hpp:95
#define forceinline
Definition: config.hpp:132
CutoffConstant(unsigned long int c)
Constructor.
Definition: cutoff.hpp:59
void exp(Home home, FloatVar x0, FloatVar x1)
Post propagator for .
Definition: arithmetic.cpp:144
Cutoff * c2
Second cutoff generator.
Definition: search.hh:367
CutoffAppend(Cutoff *c1, unsigned long int n, Cutoff *c2)
Constructor.
Definition: cutoff.hpp:112
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
CutoffLinear(unsigned long int scale)
Constructor.
Definition: cutoff.hpp:64