Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
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 
34 namespace Gecode {
35 
42  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
146  ValCommitFunction<View>::print(const Space&, unsigned int,
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
159  c.~SharedData<CommitFunction>();
160  }
161 
162 }
163 
164 // STATISTICS: kernel-branch
View::VarType Var
The corresponding variable type.
Definition: val-commit.hpp:73
Post propagator for SetVar x
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
Definition: val-commit.hpp:141
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
Definition: val-commit.hpp:75
Base class for value commit.
Definition: val-commit.hpp:44
Computation spaces.
Definition: core.hpp:1742
View::VarType Var
Corresponding variable type.
Definition: val-commit.hpp:49
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-commit.hpp:101
Traits for branching.
Definition: traits.hpp:55
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:94
_Val Val
Value type.
Definition: val-commit.hpp:51
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-commit.hpp:153
Gecode toplevel namespace
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-commit.hpp:107
VarImp * varimp(void) const
Return variable implementation of variable.
Definition: var.hpp:96
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
Definition: val-commit.hpp:132
Value branching information.
Definition: val.hpp:41
_View View
View type.
Definition: val-commit.hpp:47
struct Gecode::@602::NNF::@65::@67 a
For atomic nodes.
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.
Definition: val-commit.hpp:146
int ModEvent
Type for modification events.
Definition: core.hpp:62
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:4044
Exception: invalid function
Definition: exception.hpp:114
#define forceinline
Definition: config.hpp:185
Gecode::FloatVal c(-8, 8)
No-good literal recorded during search.
Definition: core.hpp:1340
SharedData< CommitFunction > c
The user-defined commit function.
Definition: val-commit.hpp:78
void dispose(Space &home)
Delete value commit.
Definition: val-commit.hpp:158
Class for user-defined value commit.
Definition: val-commit.hpp:65
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-commit.hpp:118
@ ES_FAILED
Execution has resulted in failure.
Definition: core.hpp:474
Gecode::IntArgs i({1, 2, 3, 4})
void dispose(Space &home)
Delete value commit.
Definition: val-commit.hpp:112
@ ES_OK
Execution is okay.
Definition: core.hpp:476