Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 ValCommit {
49  public:
51  typedef _View View;
53  typedef typename View::VarType Var;
55  typedef _Val Val;
56  public:
58  ValCommit(Space& home, const ValBranch<Var>& vb);
62  bool notice(void) const;
64  void dispose(Space& home);
65  };
66 
68  template<class View>
69  class ValCommitFunction : public
70  ValCommit<View,
71  typename BranchTraits<typename View::VarType>::ValType> {
72  typedef typename ValCommit<View,
74  ::ValType>::Val Val;
75  public:
77  typedef typename View::VarType Var;
80  protected:
83  public:
85  ValCommitFunction(Space& home, const ValBranch<Var>& vb);
89  ModEvent commit(Space& home, unsigned int a, View x, int i, Val n);
91  NGL* ngl(Space& home, unsigned int a, View x, Val n) const;
93  void print(const Space& home, unsigned int a, View x, int i,
94  const Val& n, std::ostream& o) const;
96  bool notice(void) const;
98  void dispose(Space& home);
99  };
101 
102  // Baseclass for value commit
103  template<class View, class Val>
106  template<class View, class Val>
109  template<class View, class Val>
110  forceinline bool
112  return false;
113  }
114  template<class View, class Val>
115  forceinline void
117 
118 
119  // User-defined value selection
120  template<class View>
123  const ValBranch<Var>& vb)
124  : ValCommit<View,Val>(home,vb), c(vb.commit()) {
125  if (!c())
126  throw InvalidFunction("ValCommitFunction::ValCommitFunction");
127  }
128  template<class View>
132  : ValCommit<View,Val>(home,vc), c(vc.c) {
133  }
134  template<class View>
136  ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
137  Val n) {
138  typename View::VarType y(x.varimp());
140  c()(home,a,y,i,n);
141  return home.failed() ? ES_FAILED : ES_OK;
142  }
143  template<class View>
145  ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
146  return NULL;
147  }
148  template<class View>
149  forceinline void
150  ValCommitFunction<View>::print(const Space&, unsigned int,
151  View, int i, const Val&,
152  std::ostream& o) const {
153  o << "var[" << i << "] is user-defined.";
154  }
155  template<class View>
156  forceinline bool
158  return true;
159  }
160  template<class View>
161  forceinline void
164  }
165 
166 }
167 
168 // STATISTICS: kernel-branch
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-commit.hpp:111
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-commit.hpp:122
SharedData< CommitFunction > c
The user-defined commit function.
Definition: val-commit.hpp:82
int ModEvent
Type for modification events.
Definition: core.hpp:64
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
Definition: val-commit.hpp:136
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
Definition: val-commit.hpp:79
Base class for value commit.
Definition: val-commit.hpp:48
Gecode::FloatVal c(-8, 8)
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
Definition: val-commit.hpp:145
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
Execution has resulted in failure.
Definition: core.hpp:466
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:150
~SharedData(void)
Destructors.
void dispose(Space &home)
Delete value commit.
Definition: val-commit.hpp:116
_Val Val
Value type.
Definition: val-commit.hpp:55
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:3914
Exception: invalid function
Definition: exception.hpp:118
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
void print(std::basic_ostream< Char, Traits > &s, bool assigned, IL &lb, IU &ub, unsigned int cardMin, unsigned int cardMax)
Print set view.
Definition: print.hpp:67
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Definition: val-commit.hpp:157
void dispose(Space &home)
Delete value commit.
Definition: val-commit.hpp:162
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
Value branching information.
Definition: val.hpp:45
struct Gecode::@585::NNF::@62::@64 a
For atomic nodes.
View::VarType Var
Corresponding variable type.
Definition: val-commit.hpp:53
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Definition: val-commit.hpp:105
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
View::VarType Var
The corresponding variable type.
Definition: val-commit.hpp:77
Class for user-defined value commit.
Definition: val-commit.hpp:69
Gecode toplevel namespace
_View View
View type.
Definition: val-commit.hpp:51
Traits for branching.
Definition: traits.hpp:59
No-good literal recorded during search.
Definition: core.hpp:1266