Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
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 
42  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);
56  ValSel(Space& home, ValSel<View,Val>& vs);
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  : ValSel<View,Val>(home,vb), v(vb.val()) {
117  if (!v())
118  throw InvalidFunction("ValSelFunction::ValSelFunction");
119  }
120  template<class View>
123  : ValSel<View,Val>(home,vs), v(vs.v) {
124  }
125  template<class View>
127  ValSelFunction<View>::val(const Space& home, View x, int i) {
128  typename View::VarType y(x.varimp());
130  return v()(home,y,i);
131  }
132  template<class View>
133  forceinline bool
135  return true;
136  }
137  template<class View>
138  forceinline void
141  }
142 
143 }
144 
145 // STATISTICS: kernel-branch
SharedData< ValFunction > v
The user-defined value function.
Definition: val-sel.hpp:79
View::VarType Var
Corresponding variable type.
Definition: val-sel.hpp:49
User-defined value selection.
Definition: val-sel.hpp:65
_View View
View type.
Definition: val-sel.hpp:47
_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:134
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
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:139
Gecode::IntArgs i(4, 1, 2, 3, 4)
~SharedData(void)
Destructors.
void dispose(Space &home)
Delete value selection.
Definition: val-sel.hpp:109
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-sel.hpp:104
Exception: invalid function
Definition: exception.hpp:114
const int v[7]
Definition: distinct.cpp:259
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:94
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:765
Value branching information.
Definition: val.hpp:41
Integer variables.
Definition: int.hh:347
Post propagator for SetVar x
Definition: set.hh:765
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
Definition: val-sel.hpp:127
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-sel.hpp:115
Gecode toplevel namespace
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
Traits for branching.
Definition: traits.hpp:55
Base class for value selection.
Definition: val-sel.hpp:44