Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
val-sel-commit.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
34namespace Gecode {
35
43 template<class _View, class _Val>
45 public:
47 typedef _View View;
49 typedef typename View::VarType Var;
51 typedef _Val Val;
52 public:
58 virtual Val val(const Space& home, View x, int i) = 0;
60 virtual ModEvent commit(Space& home, unsigned int a,
61 View x, int i, Val n) = 0;
63 virtual NGL* ngl(Space& home, unsigned int a,
64 View x, Val n) const = 0;
66 virtual void print(const Space& home, unsigned int a,
67 View x, int i, const Val& n,
68 std::ostream& o) const = 0;
72 virtual bool notice(void) const = 0;
74 virtual void dispose(Space& home) = 0;
76 virtual ~ValSelCommitBase(void);
78
79
80 static void* operator new(size_t s, Space& home);
82 static void operator delete(void* p, Space& home);
84 static void operator delete(void* p);
86 };
87
89 template<class ValSel, class ValCommit>
91 : public ValSelCommitBase<typename ValSel::View,typename ValSel::Val> {
92 protected:
93 typedef typename ValSelCommitBase<typename ValSel::View,
95 typedef typename ValSelCommitBase<typename ValSel::View,
97 typedef typename ValSelCommitBase<typename ValSel::View,
103 public:
105 ValSelCommit(Space& home, const ValBranch<Var>& vb);
109 virtual Val val(const Space& home, View x, int i);
111 virtual ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
113 virtual NGL* ngl(Space& home, unsigned int a,
114 View x, Val n) const;
116 virtual void print(const Space& home, unsigned int a,
117 View x, int i, const Val& n,
118 std::ostream& o) const;
122 virtual bool notice(void) const;
124 virtual void dispose(Space& home);
125 };
127
128
129 template<class View, class Val>
133 template<class View, class Val>
137 template<class View, class Val>
139
140 template<class View, class Val>
141 forceinline void
143 template<class View, class Val>
144 forceinline void
146 template<class View, class Val>
147 forceinline void*
149 return home.ralloc(s);
150 }
151
152
153
154
155 template<class ValSel, class ValCommit>
158 const ValBranch<Var>& vb)
159 : ValSelCommitBase<View,Val>(home,vb), s(home,vb), c(home,vb) {}
160
161 template<class ValSel, class ValCommit>
165 : ValSelCommitBase<View,Val>(home,vsc),
166 s(home,vsc.s), c(home,vsc.c) {}
167
168 template<class ValSel, class ValCommit>
171 return s.val(home,x,i);
172 }
173
174 template<class ValSel, class ValCommit>
177 View x, int i, Val n) {
178 return c.commit(home,a,x,i,n);
179 }
180
181 template<class ValSel, class ValCommit>
182 NGL*
184 View x, Val n) const {
185 return c.ngl(home, a, x, n);
186 }
187
188 template<class ValSel, class ValCommit>
189 void
191 View x, int i, const Val& n,
192 std::ostream& o) const {
193 c.print(home,a,x,i,n,o);
194 }
195
196 template<class ValSel, class ValCommit>
199 return new (home) ValSelCommit<ValSel,ValCommit>(home,*this);
200 }
201
202 template<class ValSel, class ValCommit>
203 bool
205 return s.notice() || c.notice();
206 }
207
208 template<class ValSel, class ValCommit>
209 void
211 s.dispose(home);
212 c.dispose(home);
213 }
214
215}
216
217// STATISTICS: kernel-branch
int p
Number of positive literals for node type.
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
No-good literal recorded during search.
Definition core.hpp:1340
Computation spaces.
Definition core.hpp:1742
Value branching information.
Definition val.hpp:41
Base class for value commit.
Base class for value selection and commit.
virtual ~ValSelCommitBase(void)
Unused destructor.
virtual ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)=0
Commit view x at position i to value n for alternative a.
View::VarType Var
Corresponding variable type.
virtual Val val(const Space &home, View x, int i)=0
Return value of view x at position i.
virtual ValSelCommitBase< View, Val > * copy(Space &home)=0
Perform cloning.
virtual void dispose(Space &home)=0
Delete value selection.
virtual void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const =0
Print on o branch for alternative a, view x at position i, and value n.
virtual bool notice(void) const =0
Whether dispose must always be called (that is, notice is needed)
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const =0
Create no-good literal for choice c and alternative a.
ValSelCommitBase(Space &home, ValSelCommitBase< View, Val > &vsc)
Constructor for cloning.
ValSelCommitBase(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Class for value selection and commit.
virtual ValSelCommit< ValSel, ValCommit > * copy(Space &home)
Perform cloning.
ValSelCommitBase< typenameValSel::View, typenameValSel::Val >::Var Var
ValCommit c
The commit object used.
ValSel s
The value selection object used.
ValSelCommitBase< typenameValSel::View, typenameValSel::Val >::View View
virtual void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const
Print on o branch for alternative a, view x at position i, and value n.
virtual Val val(const Space &home, View x, int i)
Return value of view x at position i.
virtual ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Commit view x at position i to value n for alternative a.
virtual bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
virtual NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for choice c and alternative a.
virtual void dispose(Space &home)
Delete value selection.
ValSelCommitBase< typenameValSel::View, typenameValSel::Val >::Val Val
ValSelCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Base class for value selection.
Definition val-sel.hpp:44
_Val Val
Value type.
Definition val-sel.hpp:51
_View View
View type.
Definition val-sel.hpp:47
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:767
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:187