Generated on Sat Feb 7 2015 02:01:15 for Gecode by doxygen 1.8.9.1
afc.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2013
8  *
9  * Last modified:
10  * $Date: 2014-05-27 14:57:59 +0200 (Tue, 27 May 2014) $ by $Author: schulte $
11  * $Revision: 14124 $
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 namespace Gecode {
39 
44  class AFC {
45  protected:
47  int n;
48  public:
50 
51 
58  AFC(void);
60  AFC(const AFC& a);
62  AFC& operator =(const AFC& a);
64  template<class Var>
65  AFC(Home home, const VarArgArray<Var>& x, double d);
67  template<class Var>
68  void init(Home home, const VarArgArray<Var>& x, double d);
70  bool initialized(void) const;
72  void set(Space& home, double a=1.0);
76 
78 
79  void update(Space& home, bool share, AFC& a);
82  ~AFC(void);
84 
86 
87  int size(void) const;
90 
92 
93  void decay(Space& home, double d);
96  double decay(const Space& home) const;
98  };
99 
104  template<class Char, class Traits>
105  std::basic_ostream<Char,Traits>&
106  operator <<(std::basic_ostream<Char,Traits>& os,
107  const AFC& a);
108 
109  /*
110  * AFC
111  *
112  */
113  forceinline int
114  AFC::size(void) const {
115  assert(n >= 0);
116  return n;
117  }
118 
120  AFC::AFC(void) : n(-1) {}
121 
122  forceinline bool
123  AFC::initialized(void) const {
124  return n >= 0;
125  }
126 
127  template<class Var>
129  AFC::AFC(Home home, const VarArgArray<Var>& x, double d)
130  : n(x.size()) {
131  if ((d < 0.0) || (d > 1.0))
132  throw IllegalDecay("AFC");
133  static_cast<Space&>(home).afc_decay(d);
134  }
135  template<class Var>
136  forceinline void
137  AFC::init(Home home, const VarArgArray<Var>& x, double d) {
138  n = x.size();
139  if ((d < 0.0) || (d > 1.0))
140  throw IllegalDecay("AFC");
141  static_cast<Space&>(home).afc_decay(d);
142  }
143 
144 
146  AFC::AFC(const AFC& a)
147  : n(a.n) {}
150  n=a.n;
151  return *this;
152  }
154  AFC::~AFC(void) {}
155 
156  forceinline void
157  AFC::update(Space&, bool, AFC& a) {
158  n=a.n;
159  }
160 
161  forceinline void
162  AFC::decay(Space& home, double d) {
163  if ((d < 0.0) || (d > 1.0))
164  throw IllegalDecay("AFC");
165  home.afc_decay(d);
166  }
167 
168  forceinline void
169  AFC::set(Space& home, double a) {
170  home.afc_set(a);
171  }
172 
173  forceinline double
174  AFC::decay(const Space& home) const {
175  return home.afc_decay();
176  }
177 
178 
179  template<class Char, class Traits>
180  std::basic_ostream<Char,Traits>&
181  operator <<(std::basic_ostream<Char,Traits>& os,
182  const AFC& a) {
183  (void)a;
184  return os << "AFC(no information available)";
185  }
186 
187 }
188 
189 // STATISTICS: kernel-branch
void afc_set(double a)
Reset AFC to a.
Definition: core.cpp:685
int size(void) const
Return size of array (number of elements)
bool initialized(void) const
Test whether already initialized.
Definition: afc.hpp:123
void init(Home home, const VarArgArray< Var > &x, double d)
Initialize for views x and decay factor d.
Definition: afc.hpp:137
void set(Space &home, double a=1.0)
Set AFC information to a.
Definition: afc.hpp:169
~AFC(void)
Destructor.
Definition: afc.hpp:154
void afc_decay(double d)
Set AFC decay factor to d
Definition: core.cpp:675
Computation spaces.
Definition: core.hpp:1362
Gecode::IntSet d(v, 7)
AFC(void)
Construct as not yet intialized.
Definition: afc.hpp:120
Class for AFC (accumulated failure count) management.
Definition: afc.hpp:44
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
unsigned int size(I &i)
Size of all ranges of range iterator i.
#define GECODE_KERNEL_EXPORT
Definition: kernel.hh:70
int size(void) const
Return number of AFC values.
Definition: afc.hpp:114
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
int n
Number of views.
Definition: afc.hpp:47
void decay(Space &home, double d)
Set decay factor to d.
Definition: afc.hpp:162
#define forceinline
Definition: config.hpp:132
static const AFC def
Default (empty) AFC information.
Definition: afc.hpp:74
Gecode toplevel namespace
Argument array for variables.
Definition: array.hpp:53
void update(Space &home, bool share, AFC &a)
Updating during cloning.
Definition: afc.hpp:157
AFC & operator=(const AFC &a)
Assignment operator.
Definition: afc.hpp:149
Exception: illegal decay factor
Definition: exception.hpp:90
Home class for posting propagators
Definition: core.hpp:717
struct Gecode::@518::NNF::@57::@59 a
For atomic nodes.