Generated on Tue Jan 26 2021 00:00:00 for Gecode by doxygen 1.9.1
val-sel.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main author:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2012
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 namespace Gecode {
35 
43  template<class _View, class _Val>
44  class ValSel {
45  public:
47  typedef _View View;
49  typedef typename View::VarType Var;
51  typedef _Val Val;
52  public:
54  ValSel(Space& home, const ValBranch<Var>& vb);
58  bool notice(void) const;
60  void dispose(Space& home);
61  };
62 
64  template<class View>
66  public ValSel<View,
67  typename BranchTraits<typename View::VarType>::ValType> {
68  using typename ValSel<View,
70  public:
72  typedef typename ValSel<View,
74  ::ValType>::Val Val;
77  protected:
80  public:
82  ValSelFunction(Space& home, const ValBranch<Var>& vb);
86  Val val(const Space& home, View x, int i);
88  bool notice(void) const;
90  void dispose(Space& home);
91  };
93 
94 
95  // Baseclass value selection
96  template<class View, class Val>
99  template<class View, class Val>
102  template<class View, class Val>
103  forceinline bool
105  return false;
106  }
107  template<class View, class Val>
108  forceinline void
110 
111 
112  // User-defined value selection
113  template<class View>
116  (Space& home, const ValBranch<ValSelFunction<View>::Var>& vb)
117  : ValSel<View,Val>(home,vb), v(vb.val()) {
118  if (!v())
119  throw InvalidFunction("ValSelFunction::ValSelFunction");
120  }
121  template<class View>
124  : ValSel<View,Val>(home,vs), v(vs.v) {
125  }
126  template<class View>
128  ValSelFunction<View>::val(const Space& home, View x, int i) {
129  typename View::VarType y(x.varimp());
131  return v()(home,y,i);
132  }
133  template<class View>
134  forceinline bool
136  return true;
137  }
138  template<class View>
139  forceinline void
141  v.~SharedData<ValFunction>();
142  }
143 
144 }
145 
146 // STATISTICS: kernel-branch
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
Traits for branching.
Definition: traits.hpp:55
Exception: invalid function
Definition: exception.hpp:114
Computation spaces.
Definition: core.hpp:1742
Value branching information.
Definition: val.hpp:41
User-defined value selection.
Definition: val-sel.hpp:67
ValSel< View, typename BranchTraits< typename View::VarType >::ValType >::Val Val
The corresponding value type.
Definition: val-sel.hpp:74
BranchTraits< Var >::Val ValFunction
The corresponding value function.
Definition: val-sel.hpp:76
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:140
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:135
SharedData< ValFunction > v
The user-defined value function.
Definition: val-sel.hpp:79
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
Definition: val-sel.hpp:128
Base class for value selection.
Definition: val-sel.hpp:44
_Val Val
Value type.
Definition: val-sel.hpp:51
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:104
_View View
View type.
Definition: val-sel.hpp:47
ValSel(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:98
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:109
ValSel(Space &home, ValSel< View, Val > &vs)
Constructor for cloning.
Definition: val-sel.hpp:101
View::VarType Var
Corresponding variable type.
Definition: val-sel.hpp:49
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
Gecode::IntArgs i({1, 2, 3, 4})
const int v[7]
Definition: distinct.cpp:259
#define forceinline
Definition: config.hpp:185
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:94