Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <functional>
35
36namespace Gecode {
37
39 template<class Var>
40 using BranchFilter = std::function<bool(const Space& home,
41 Var x, int i)>;
42
44 template<class View>
46 public:
48 typedef typename View::VarType Var;
49 protected:
51 public:
57 operator bool(void) const;
59 bool operator ()(const Space& home, View x, int i) const;
61 bool notice(void) const;
63 void dispose(Space& home);
64 };
65
67 template<class View>
69 public:
71 typedef typename View::VarType Var;
72 public:
78 operator bool(void) const;
80 bool operator ()(const Space& home, View x, int i) const;
82 bool notice(void) const;
84 void dispose(Space& home);
85 };
86
87
88 template<class View>
91 if (!bf)
92 throw Gecode::InvalidFunction("BrancherFilter::BrancherFilter");
93 }
94
95 template<class View>
100
101 template<class View>
104 return true;
105 }
106
107 template<class View>
108 forceinline bool
109 BrancherFilter<View>::operator ()(const Space& home, View x, int i) const {
111 Var xv(x.varimp());
112 return f()(home,xv,i);
113 }
114
115 template<class View>
116 forceinline bool
118 return true;
119 }
120
121 template<class View>
122 forceinline void
126
127
128 template<class View>
131 assert(!bf);
132 (void) bf;
133 }
134
135 template<class View>
138
139 template<class View>
142 return false;
143 }
144
145 template<class View>
146 forceinline bool
148 return true;
149 }
150 template<class View>
151 forceinline bool
153 return false;
154 }
155
156 template<class View>
157 forceinline void
160
161}
162
163// STATISTICS: kernel-branch
Class storing a branch filter function.
Definition filter.hpp:45
View::VarType Var
The corresponding variable type.
Definition filter.hpp:48
SharedData< BranchFilter< Var > > f
Definition filter.hpp:50
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition filter.hpp:109
BrancherFilter(BranchFilter< Var > bf)
Initialize.
Definition filter.hpp:90
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition filter.hpp:117
void dispose(Space &home)
Delete object.
Definition filter.hpp:123
Class withot a branch filter function.
Definition filter.hpp:68
void dispose(Space &home)
Delete object.
Definition filter.hpp:158
bool operator()(const Space &home, View x, int i) const
Invoke filter function.
Definition filter.hpp:147
View::VarType Var
The corresponding variable type.
Definition filter.hpp:71
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition filter.hpp:152
BrancherNoFilter(BranchFilter< Var > bf)
Initialize.
Definition filter.hpp:130
Exception: invalid function
Class for sharing data between spaces.
Computation spaces.
Definition core.hpp:1742
VarImp * varimp(void) const
Return variable implementation of variable.
Definition var.hpp:96
Base class for variables.
Definition var.hpp:40
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:767
std::function< bool(const Space &home, Var x, int i)> BranchFilter
Function type for branch filter functions.
Definition filter.hpp:40
#define forceinline
Definition config.hpp:187
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition macros.hpp:94