Generated on for Gecode by doxygen 1.17.0
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.dev>
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.dev
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
34namespace Gecode {
35
42
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 public:
70 typedef typename ValSel<View,
72 ::ValType>::Var Var;
74 typedef typename ValSel<View,
76 ::ValType>::Val Val;
79 protected:
82 public:
84 ValSelFunction(Space& home, const ValBranch<Var>& vb);
88 Val val(const Space& home, View x, int i);
90 bool notice(void) const;
92 void dispose(Space& home);
93 };
94
95
96
97 // Baseclass value selection
98 template<class View, class Val>
99 forceinline
101 template<class View, class Val>
102 forceinline
104 template<class View, class Val>
105 forceinline bool
107 return false;
108 }
109 template<class View, class Val>
110 forceinline void
112
113
114 // User-defined value selection
115 template<class View>
116 forceinline
118 (Space& home, const ValBranch<Var>& vb)
119 : ValSel<View,Val>(home,vb), v(vb.val()) {
120 if (!v())
121 throw InvalidFunction("ValSelFunction::ValSelFunction");
122 }
123 template<class View>
124 forceinline
128 template<class View>
129 forceinline typename ValSelFunction<View>::Val
130 ValSelFunction<View>::val(const Space& home, View x, int i) {
131 typename View::VarType y(x.varimp());
133 return v()(home,y,i);
134 }
135 template<class View>
136 forceinline bool
138 return true;
139 }
140 template<class View>
141 forceinline void
143 v.~SharedData<ValFunction>();
144 }
145
146}
147
148// STATISTICS: kernel-branch
Traits for branching.
Definition traits.hpp:55
Exception: invalid function
Class for sharing data between spaces.
Computation spaces.
Definition core.hpp:1775
Value branching information.
Definition val.hpp:41
ValSel< View, typenameBranchTraits< typenameView::VarType >::ValType >::Val Val
The corresponding value type.
Definition val-sel.hpp:76
BranchTraits< Var >::Val ValFunction
The corresponding value function.
Definition val-sel.hpp:78
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition val-sel.hpp:118
void dispose(Space &home)
Delete value selection.
Definition val-sel.hpp:142
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-sel.hpp:137
ValSel< View, typenameBranchTraits< typenameView::VarType >::ValType >::Var Var
The corresponding variable type.
Definition val-sel.hpp:72
SharedData< ValFunction > v
The user-defined value function.
Definition val-sel.hpp:81
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
Definition val-sel.hpp:130
bool notice(void) const
Whether dispose must always be called (that is, notice is needed).
Definition val-sel.hpp:106
ValSel(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition val-sel.hpp:100
void dispose(Space &home)
Delete value selection.
Definition val-sel.hpp:111
Val_ Val
Value type.
Definition val-sel.hpp:51
ValSel(Space &home, ValSel< View, Val > &vs)
Constructor for cloning.
Definition val-sel.hpp:103
View_ View
View type.
Definition val-sel.hpp:47
View::VarType Var
Corresponding variable type.
Definition val-sel.hpp:49
Gecode toplevel namespace
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition macros.hpp:94