Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
brancher-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: 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 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);
60  ValCommit(Space& home, bool shared, ValCommit<View,Val>& vs);
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,shared,vc) {
133  c.update(home,shared,vc.c);
134  }
135  template<class View>
137  ValCommitFunction<View>::commit(Space& home, unsigned int a, View x, int i,
138  Val n) {
139  typename View::VarType y(x.varimp());
141  c()(home,a,y,i,n);
142  return home.failed() ? ES_FAILED : ES_OK;
143  }
144  template<class View>
146  ValCommitFunction<View>::ngl(Space&, unsigned int, View, Val) const {
147  return NULL;
148  }
149  template<class View>
150  forceinline void
151  ValCommitFunction<View>::print(const Space&, unsigned int,
152  View, int i, const Val&,
153  std::ostream& o) const {
154  o << "var[" << i << "] is user-defined.";
155  }
156  template<class View>
157  forceinline bool
159  return true;
160  }
161  template<class View>
162  forceinline void
164  c.~SharedData<CommitFunction>();
165  }
166 
167 }
168 
169 // STATISTICS: kernel-branch
View::VarType Var
The corresponding variable type.
Post propagator for SetVar x
Definition: set.hh:784
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
#define forceinline
Definition: config.hpp:173
NGL * ngl(Space &home, unsigned int a, View x, Val n) const
Create no-good literal for alternative a.
Gecode::IntArgs i(4, 1, 2, 3, 4)
void update(Space &home, bool share, SharedHandle &sh)
Update during cloning.
BranchTraits< Var >::Commit CommitFunction
The corresponding commit function.
Base class for value commit.
Computation spaces.
Definition: core.hpp:1748
View::VarType Var
Corresponding variable type.
ValCommit(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
Traits for branching.
#define GECODE_VALID_FUNCTION(f)
Assert that a function is valid.
Definition: macros.hpp:98
_Val Val
Value type.
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
Gecode toplevel namespace
bool notice(void) const
Whether dispose must always be called (that is, notice is needed)
VarImp * varimp(void) const
Return variable implementation of variable.
Definition: var.hpp:108
struct Gecode::@579::NNF::@61::@63 a
For atomic nodes.
ModEvent commit(Space &home, unsigned int a, View x, int i, Val n)
Perform user-defined commit.
Value branching information.
Definition: branch-val.hpp:45
_View View
View type.
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.
int ModEvent
Type for modification events.
Definition: core.hpp:142
bool failed(void) const
Check whether space is failed.
Definition: core.hpp:4095
Exception: invalid function
Definition: exception.hpp:118
bool shared(const IntSet &, VX)
Definition: view-base.hpp:122
Gecode::FloatVal c(-8, 8)
No-good literal recorded during search.
Definition: core.hpp:1342
SharedData< CommitFunction > c
The user-defined commit function.
void dispose(Space &home)
Delete value commit.
Class for user-defined value commit.
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
ValCommitFunction(Space &home, const ValBranch< Var > &vb)
Constructor for initialization.
@ ES_FAILED
Execution has resulted in failure.
Definition: core.hpp:542
void dispose(Space &home)
Delete value commit.
@ ES_OK
Execution is okay.
Definition: core.hpp:544