Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
val-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>
44 class ValCommit {
45 public:
47 typedef _View View;
49 typedef typename View::VarType Var;
51 typedef _Val Val;
52 public:
54 ValCommit(Space& home, const ValBranch<Var>& vb);
58 bool notice(void) const;
60 void dispose(Space& home);
61 };
62
64 template<class View>
65 class ValCommitFunction : public
66 ValCommit<View,
67 typename BranchTraits<typename View::VarType>::ValType> {
68 typedef typename ValCommit<View,
70 ::ValType>::Val Val;
71 public:
73 typedef typename View::VarType Var;
76 protected:
79 public:
81 ValCommitFunction(Space& home, const ValBranch<Var>& vb);
85 ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
87 NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
89 void print(const Space& home, unsigned int a, View x, int i,
90 const Val& n, std::ostream& o) const;
92 bool notice(void) const;
94 void dispose(Space& home);
95 };
97
98 // Baseclass for value commit
99 template<class View, class Val>
102 template<class View, class Val>
105 template<class View, class Val>
106 forceinline bool
108 return false;
109 }
110 template<class View, class Val>
111 forceinline void
113
114
115 // User-defined value selection
116 template<class View>
119 const ValBranch<Var>& vb)
120 : ValCommit<View,Val>(home,vb), c(vb.commit()) {
121 if (!c())
122 throw InvalidFunction("ValCommitFunction::ValCommitFunction");
123 }
124 template<class View>
128 : ValCommit<View,Val>(home,vc), c(vc.c) {
129 }
130 template<class View>
132 ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
133 Val n) {
134 typename View::VarType y(x.varimp());
136 c()(home,a,y,i,n);
137 return home.failed() ? ES_FAILED : ES_OK;
138 }
139 template<class View>
141 ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
142 return NULL;
143 }
144 template<class View>
145 forceinline void
147 View, int i, const Val&,
148 std::ostream& o) const {
149 o << "var[" << i << "] is user-defined.";
150 }
151 template<class View>
152 forceinline bool
154 return true;
155 }
156 template<class View>
157 forceinline void
161
162}
163
164// STATISTICS: kernel-branch
int n
Number of negative literals for node type.
struct Gecode::@603::NNF::@65::@67 a
For atomic nodes.
Traits for branching.
Definition traits.hpp:55
Exception: invalid function
No-good literal recorded during search.
Definition core.hpp:1340
Class for sharing data between spaces.
Computation spaces.
Definition core.hpp:1742
Value branching information.
Definition val.hpp:41
Class for user-defined value commit.
SharedData< CommitFunction > c
The user-defined commit function.
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
void dispose(Space &home)
Delete value commit.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
View::VarType Var
The corresponding variable type.
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
void print(const Space &home, unsigned int a, View x, int i, const Val &n, std::ostream &o) const
Print on o the alternative with view x at position i and value n.
Base class for value commit.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
void dispose(Space &home)
Delete value commit.
_View View
View type.
_Val Val
Value type.
ValCommit(Space &home, ValCommit< View, Val > &vs)
Constructor for cloning.
View::VarType Var
Corresponding variable type.
VarImp * varimp(void) const
Return variable implementation of variable.
Definition var.hpp:96
bool failed(void) const
Check whether space is failed.
Definition core.hpp:4044
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:767
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:474
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
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition macros.hpp:94