Generated on Fri Jul 13 2018 06:08:29 for Gecode by doxygen 1.8.14
brancher-filter.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, 2017
8  *
9  * Last modified:
10  * $Date: 2017-04-01 20:27:10 +0200 (Sat, 01 Apr 2017) $ by $Author: schulte $
11  * $Revision: 15623 $
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 <functional>
39 
40 namespace Gecode {
41 
43  template<class Var>
44  using BranchFilter = std::function<bool(const Space& home,
45  Var x, int i)>;
46 
48  template<class View>
50  public:
52  typedef typename View::VarType Var;
53  protected:
55  public:
59  BrancherFilter(Space& home, bool shared, BrancherFilter& bf);
61  operator bool(void) const;
63  bool operator ()(const Space& home, View x, int i) const;
65  bool notice(void) const;
67  void dispose(Space& home);
68  };
69 
71  template<class View>
73  public:
75  typedef typename View::VarType Var;
76  public:
82  operator bool(void) const;
84  bool operator ()(const Space& home, View x, int i) const;
86  bool notice(void) const;
88  void dispose(Space& home);
89  };
90 
91 
92  template<class View>
95  if (!bf)
96  throw Gecode::InvalidFunction("BrancherFilter::BrancherFilter");
97  }
98 
99  template<class View>
102  BrancherFilter<View>& bf) {
103  f.update(home,shared,bf.f);
104  }
105 
106  template<class View>
109  return true;
110  }
111 
112  template<class View>
113  forceinline bool
114  BrancherFilter<View>::operator ()(const Space& home, View x, int i) const {
116  Var xv(x.varimp());
117  return f()(home,xv,i);
118  }
119 
120  template<class View>
121  forceinline bool
123  return true;
124  }
125 
126  template<class View>
127  forceinline void
129  f.~SharedData<BranchFilter<Var>>();
130  }
131 
132 
133  template<class View>
136  assert(!bf);
137  }
138 
139  template<class View>
143 
144  template<class View>
147  return false;
148  }
149 
150  template<class View>
151  forceinline bool
152  BrancherNoFilter<View>::operator ()(const Space&, View, int) const {
153  return true;
154  }
155  template<class View>
156  forceinline bool
158  return false;
159  }
160 
161  template<class View>
162  forceinline void
164  }
165 
166 }
167 
168 // STATISTICS: kernel-branch
VarImp * varimp(void) const
Return variable implementation of variable.
Definition: var.hpp:108
Class withot a branch filter function.
View::VarType Var
The corresponding variable type.
void dispose(Space &home)
Delete object.
Computation spaces.
Definition: core.hpp:1748
SharedData< BranchFilter< Var > > f
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
BrancherFilter(BranchFilter< Var > bf)
Initialize.
Gecode::IntArgs i(4, 1, 2, 3, 4)
Class storing a branch filter function.
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
View::VarType Var
The corresponding variable type.
BrancherNoFilter(BranchFilter< Var > bf)
Initialize.
Exception: invalid function
Definition: exception.hpp:118
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
Post propagator for f(x \diamond_{\mathit{op}} y) \sim_r z \f$ void rel(Home home
Base class for variables.
Definition: var.hpp:44
Class for sharing data between spaces.
Definition: shared-data.hpp:42
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
void dispose(Space &home)
Delete object.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
Gecode toplevel namespace
bool operator()(const Space &home, View x, int i) const
Invoke filter function.