Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
11  * $Revision$
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:
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  : f(bf.f) {
103  }
104 
105  template<class View>
108  return true;
109  }
110 
111  template<class View>
112  forceinline bool
113  BrancherFilter<View>::operator ()(const Space& home, View x, int i) const {
115  Var xv(x.varimp());
116  return f()(home,xv,i);
117  }
118 
119  template<class View>
120  forceinline bool
122  return true;
123  }
124 
125  template<class View>
126  forceinline void
129  }
130 
131 
132  template<class View>
135  assert(!bf);
136  (void) bf;
137  }
138 
139  template<class View>
142 
143  template<class View>
146  return false;
147  }
148 
149  template<class View>
150  forceinline bool
151  BrancherNoFilter<View>::operator ()(const Space&, View, int) const {
152  return true;
153  }
154  template<class View>
155  forceinline bool
157  return false;
158  }
159 
160  template<class View>
161  forceinline void
163  }
164 
165 }
166 
167 // STATISTICS: kernel-branch
Class withot a branch filter function.
Definition: filter.hpp:72
View::VarType Var
The corresponding variable type.
Definition: filter.hpp:52
void dispose(Space &home)
Delete object.
Definition: filter.hpp:127
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
SharedData< BranchFilter< Var > > f
Definition: filter.hpp:54
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: filter.hpp:156
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: filter.hpp:121
BrancherFilter(BranchFilter< Var > bf)
Initialize.
Definition: filter.hpp:94
Gecode::IntArgs i(4, 1, 2, 3, 4)
Class storing a branch filter function.
Definition: filter.hpp:49
~SharedData(void)
Destructors.
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
Definition: filter.hpp:45
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition: filter.hpp:151
View::VarType Var
The corresponding variable type.
Definition: filter.hpp:75
BrancherNoFilter(BranchFilter< Var > bf)
Initialize.
Definition: filter.hpp:134
Exception: invalid function
Definition: exception.hpp:118
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
Base class for variables.
Definition: var.hpp:44
Class for sharing data between spaces.
Definition: shared-data.hpp:42
Post propagator for SetVar x
Definition: set.hh:769
void dispose(Space &home)
Delete object.
Definition: filter.hpp:162
Gecode toplevel namespace
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition: filter.hpp:113