Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
relax.hh
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, 2016
8  *
9  * Last modified:
10  * $Date: 2017-03-01 06:50:42 +0100 (Wed, 01 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15542 $
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 #ifndef __GECODE_SEARCH_RELAX_HH__
39 #define __GECODE_SEARCH_RELAX_HH__
40 
41 #include <gecode/kernel.hh>
42 #include <gecode/search.hh>
43 
44 namespace Gecode { namespace Search {
45 
47  template<class VarArgs, class Post>
48  forceinline void
49  relax(Home home, const VarArgs& x, const VarArgs& sx, Rnd r,
50  double p, Post& post);
51 
52 
53  template<class VarArgs, class Post>
54  forceinline void
55  relax(Home home, const VarArgs& x, const VarArgs& sx, Rnd r,
56  double p, Post& post) {
57  if (home.failed())
58  return;
59  Region reg(home);
60  // Which variables to assign
61  Support::BitSet<Region> ax(reg, static_cast<unsigned int>(x.size()));
62  // Select randomly with probability p to relax value
63  for (int i=x.size(); i--; )
64  if (r(UINT_MAX) >=
65  static_cast<unsigned int>(p * static_cast<double>(UINT_MAX)))
66  ax.set(static_cast<unsigned int>(i));
67  if (ax.all())
68  // Choose one variable uniformly and unset it
69  ax.clear(r(static_cast<unsigned int>(x.size())));
71  if (post(home, x[i.val()], sx[i.val()]) != ES_OK) {
72  home.failed();
73  return;
74  }
75  }
76 
77 }}
78 
79 #endif
80 
81 // STATISTICS: search-other
bool all(void) const
Test whether all bits are set.
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1669
void clear(unsigned int i)
Clear bit i.
Handle to region.
Definition: region.hpp:61
Value iterator for values in a bitset.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:4099
void set(unsigned int i)
Set bit i.
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
Execution is okay.
Definition: core.hpp:544
Gecode toplevel namespace
Random number generator.
Definition: rnd.hpp:46
Home class for posting propagators
Definition: core.hpp:922
void relax(Home home, const VarArgs &x, const VarArgs &sx, Rnd r, double p, Post &post)
Relax variables in x from solution sx with probability p.
Definition: relax.hh:55
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.