Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
brancher-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  * Last modified:
10  * $Date: 2017-03-01 04:28:36 +0100 (Wed, 01 Mar 2017) $ by $Author: schulte $
11  * $Revision: 15541 $
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 namespace Gecode {
39 
46  template<class _View, class _Val>
48  class ValSel {
49  public:
51  typedef _View View;
53  typedef typename View::VarType Var;
55  typedef _Val Val;
56  public:
58  ValSel(Space& home, const ValBranch<Var>& vb);
60  ValSel(Space& home, bool shared, ValSel<View,Val>& vs);
62  bool notice(void) const;
64  void dispose(Space& home);
65  };
66 
68  template<class View>
70  public ValSel<View,
71  typename BranchTraits<typename View::VarType>::ValType> {
72  using typename ValSel<View,
74  public:
76  typedef typename ValSel<View,
78  ::ValType>::Val Val;
81  protected:
84  public:
86  ValSelFunction(Space& home, const ValBranch<Var>& vb);
90  Val val(const Space& home, View x, int i);
92  bool notice(void) const;
94  void dispose(Space& home);
95  };
97 
98 
99  // Baseclass value selection
100  template<class View, class Val>
103  template<class View, class Val>
106  template<class View, class Val>
107  forceinline bool
109  return false;
110  }
111  template<class View, class Val>
112  forceinline void
114 
115 
116  // User-defined value selection
117  template<class View>
120  : ValSel<View,Val>(home,vb), v(vb.val()) {
121  if (!v())
122  throw InvalidFunction("ValSelFunction::ValSelFunction");
123  }
124  template<class View>
128  : ValSel<View,Val>(home,shared,vs) {
129  v.update(home,shared,vs.v);
130  }
131  template<class View>
133  ValSelFunction<View>::val(const Space& home, View x, int i) {
134  typename View::VarType y(x.varimp());
136  return v()(home,y,i);
137  }
138  template<class View>
139  forceinline bool
141  return true;
142  }
143  template<class View>
144  forceinline void
147  }
148 
149 }
150 
151 // STATISTICS: kernel-branch
SharedData< ValFunction > v
The user-defined value function.
void update(Space &home, bool share, SharedHandle &sh)
Update during cloning.
View::VarType Var
Corresponding variable type.
User-defined value selection.
_View View
View type.
_Val Val
Value type.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Computation spaces.
Definition: core.hpp:1748
ValSel(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
void dispose(Space &home)
Delete value selection.
Gecode::IntArgs i(4, 1, 2, 3, 4)
~SharedData(void)
Destructors.
void dispose(Space &home)
Delete value selection.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Exception: invalid function
Definition: exception.hpp:118
const int v[7]
Definition: distinct.cpp:263
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
Value branching information.
Definition: branch-val.hpp:45
Integer variables.
Definition: int.hh:353
#define forceinline
Definition: config.hpp:173
Post propagator for SetVar x
Definition: set.hh:784
Val val(const Space &home, View x, int i)
Return user-defined value of view x at position i.
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:702
ValSelFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Gecode toplevel namespace
ValSel< View, typename BranchTraits< typename View::VarType >::ValType >::Val Val
The corresponding value type.
BranchTraits< Var >::Val ValFunction
The corresponding value function.
Traits for branching.
Base class for value selection.